node.js - How can you persist user data for command line tools? -


I am a front-end god who is node. Running in JS, especially for using small command line tools.

My question: How do you keep data with the command line tool? For example, if I want to keep track of the size of certain files over time, I will need to keep records of changes (extra and extinction) in those files and relevant date / time information.

On the Web, you store that type of data in a database on a server, and then the database needs it again. But how do you do this when you create a node module which is meant as a command line tool?

Some normal direction is after all I am. I do not even know at this point

It really depends on you that you But there is a simple way to save data, you want to continue any file because we are speaking node, store it in JSON format.

Assume that you have some data:

  var data = [{File: 'foo.bar', size: 1234, Date: '2014-07- 31 00: 00: 00.000 '}, ...]  

(This is actually' unless it is JSON.stringifiy () d)

Maybe, you can save it with:

  Fs.writeFile (filename, JSON.stringify (data), {encoding: 'utf8'}, function (mistake } {...});  

and reload it:

  fs.readFile (filename, {encoding: 'utf8'}, function (error, content) { Data = JSON.parse (content);});  

You probably want to give the user the ability to specify the name of the file that you are going to continue with the data through any argument:

 < Code> node myscript.js & lt; Data_file & gt;  

You can have pass in the parameter with process.argv :

  var filename = process.argv [2] ; / /  

Using any kind can be really useful if you want to like more complex:

 

code> Node myscript.js - output & lt; Data_file & gt;

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -