0.0.1 • Published 7 years ago

json-event-emitter v0.0.1

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

json-event-emitter

A watcher for JSON files handler by EventEmitter

Tech

This module is base in others modules (fs, events)

Installation

$ npm install -s json-event-emitter

Creating instance from file path

Our test.json file

{
    "hello": "This is a test",
    "deepHello": {
        "hello": "Hello from deep"
    }
}

Create instance

const path = require('path');
const JsonEventEmitter = require('json-event-emitter');

var someJson = new JsonEventEmitter({
	path: path.resolve(__dirname, 'test.json')
});
//  Get the data as JS Object
console.log(someJson.getValue())

Updating changes

Modify a specific property change on the JSON file.

someJSON.update({
	deepHello:{
		hello: 'This is unfair'
	}
});

Listening events change

Register a function that is executed when a change is made.

someJson.on('change', (changes, value)=>{
	console.log("This changes where apply", changes);
})