Skip to content

quangld/json-persistent-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Javascript object that is based on a json file and writes back if any changes made to it

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published