1.0.6 • Published 8 years ago

json-persistent-object v1.0.6

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

json-persistent-object

An object that is based on a json file and is written back if any changes made to it. Its value stays consist even if the app is reloaded.

var JSONPO = require('json-persistent-object')

//create an object with data from config.json file
var config = new JSONPO('config.json');

//From now any update to "config" will be written back to the "config.json" immediately 

//add name if it doesn't exist
if (!config.name) config.name = 'testing';

//every time the app is restarted, this config.count will be increased by 1
config.count = config.count? config.count+1 : 0;

if (!config.controller) {
  //initialize default configuration
  config.controller = { timeout: 1, pinMaps: [10, 13] };
}
//...
//later in your code, these changes below will be immediately written back to config.json file
config.controller.pinMaps[1]=12;
config.controller.pinMaps.push(13);

//the content of config.json should be the same as printed by console.log
console.log(config); 

Installation

$ npm install json-persistent-object
1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago