Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 1.08 KB

README.md

File metadata and controls

39 lines (27 loc) · 1.08 KB

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