How can you persist user data for command line tools?

I'm a front-end dev just venturing into the Node.js, particularly in using it to create small command line tools.

My question: how do you persist data with command line tools? For example, if I want to keep track of the size of certain files over time, I'd need to keep a running record of changes (additions and deletions) to those files, and relevant date/time information.

On the web, you store that sort of data in a database on a server, and then query the database when you need it again. But how do you do it when you're creating a Node module that's meant to be used as a command line tool?

Some generic direction is all I'm after. I don't even know what to Google at this point.

It really depends on what you're doing, but a simple approach is to just save the data that you want to persist to a file and, since we're talking node, store it in JSON format.

Let's say you have some data like:

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

(it actually doesn't matter what it is, as long as it can be JSON.stringifiy()d)

You can just save it with:

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

And load it again with:

fs.readFile(filename, {encoding: 'utf8'}, function(err, contents) {
    data = JSON.parse(contents);
});

You'll probably want to give the user the ability to specify the name of the file you're going to persist the data to via an argument like:

node myscript.js <data_file>

You can get that passed in parameter with process.argv:

var filename = process.argv[2]; // Be sure to check process.argv.length and have a default

Using something like minimist can be really helpful if you want to get more complex like:

node myscript.js --output <data_file>