json-event-emitter

0.0.1 • Public • Published

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);
})

Package Sidebar

Install

npm i json-event-emitter

Weekly Downloads

1

Version

0.0.1

License

ISC

Last publish

Collaborators

  • gabryk