Tiny Node library for persisting small runtime objects on filesystem
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
lib
.gitignore
LICENSE
README.md
package.json

README.md

fs-persistent-object

Tiny Node library for persisting small runtime objects on filesystem

Install

$ npm install fs-persistent-object

Usage

var persistentObject = require('../lib/fs-persistent-object');
var path = require('path');


// register exit handlers so that process.on('exit') works
var exitFunc = function(){
    console.log('\nShutting down');
    process.exit(0);
}

process.on('SIGINT', exitFunc);
process.on('SIGTERM', exitFunc);

// load persistent object or initialize it with some defaults
var pObject = persistentObject.load(path.resolve(path.dirname(__filename), './runtime', 'example1.pObject'), {
    filename: __filename,
    datetime: new Date(),
    iterator: 0
});

console.log(pObject);

pObject.iterator += 1;

console.log('Now start me again and see that pObject.iterator is changing while pObject.datetime isn\'t.');

process.exit(0);