Node 'writefile' Add Instead of Replace - node.js

Is there any way for me to write to a file and have it simply add any new data instead of replacing the previous data?
Currently I'm using CasperJS to extract a list of items on a page and I'm using fs.write on Node to save it.
I'd like to make one large list and add to it everytime I run the script instead of having separate entries every time.
Alternatively, is there any way to combine multiple HTML files in Node?

You can use fs.appendFile instead of fs.write. From the docs:
Asynchronously append data to a file, creating the file if it does not yet exist.

Related

Is it possible to add filters to a saved search when using N/Task module to run saved search

I have a script (2.0) successfully running saved searches and writing the results to CSV files in the File Cabinet via the N/task.searchTask.
The issue is that the full system requires multiple saved searches that vary only by date range, and multiple script deployments configured with the same script parameterized by Saved Search Id and File Id (for the results). It would be better/simpler to have one Saved Search and have parameters for the data range instead of having multiple Saved Searches.
Is there a path using the N/task.searchTask that allows for the adding of Filters on the Saved Search?
You can use the N/search module to load Saved Searches and modify them however you see fit before executing them. You could certainly load a Search then manipulate its filters property before running the search.

Application.LoadfromText...load from string instead?

I was wondering if it is possible to use the code saved in the .txt file using the application.savetotext and save the code in a table, then use the application.loadfromtext to to build the object from a string rather that a .txt file
Does that make any sense? Basically I'm wanting to store all the object codes in a table on separate rows and allow users to select the relevant row and build the object without having to import the .txt file
Yes and no. You would have to write the field content to a (temp) file, then use LoadFromText to read in the object.
But it doesn't make much sense, and I think you are on a wrong track. You could just as well have the objects ready-made in application.

How to parse single file for different outputs

Does somebody know how to parse single line from a file and parse it for different outputs? For example: input is a log file, outputs are elasticsearch indices with different templates. I need to parse every line and save it into the first index and some of lines which has a promo code (like ?promo=wteaewfsthser) I need to put to another index as well. I think it's possible to use two logstash instances (correct me if I'm wrong please). But I want to know is it possible to use single instance of logstash and one configuration file?
Thanks,
Igor
Sounds like you're looking for clone. Note that only the filters that are present after the clone{} will be run on the cloned event.

Is it possible to app.post once for multiple jade file in the same directory using node.js?

I am trying to use node.js to create a program that stores a task, each task is dynamic: such as adding two random number, so I store the task as a jade file, since the second time you called, the random number might be different
The problem I am having right now is that I can write the app.post for each task, but I don't want to do that as there might be ten jade files in that directory, and I have to write app.post for each task ten times, which is not scalable, so I was wondering if there is a way to run all the jade file using one app.post?
Any hint would be appreciated
Use app.get('/:task', do) for routing and req.params.task to get the value passed from client.
See http://expressjs.com/api.html#req.params for more information.

GridFS: Clean out all unreferenced files

I have just moved towards storing things in my GridFS in MongoDB. During testing, I noticed many files are being created but not deleted properly. I have a collection users, which has a field avatar. It contains the ObjectId of the file.
Now I'd like to have some command I could use to remove all the files and chunks that are not referenced there. Is it possible to do that with one query? Maybe 'map-reduce'?
Also I am not sure how to properly delete GridFS-Files in node-mongodb-native properly.
? Now I'd like to have some command I could use to remove all the files and chunks that are not referenced there.
Key terms here is "referenced". MongoDB does not have any joins and therefore, it does not have concept of "references".
Maybe 'map-reduce'?
Map / Reduce is a query tool, not a data modification tool. The same is true of the newer "Aggregration Framework".
What you will have to do is loop through your files and check the references for each one individually. You will then be able to delete those files.
Take a look at some documented examples on how to issue those deletions.

Resources