1.0.7 • Published 7 years ago

save-on-change v1.0.7

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

save-on-change

This module allows you to read and write JSON files. It overwrites the JSON file as soon as you change the object in your Node.js application. When you are restarting your Node.js app, the object will automatically be loaded from the JSON file.

Example

const autoSave = require('save-on-change')

// load a JSON file
const a = autoSave('config.json')

// change anything
a.hello = true
a.foo = 'baz'

The file config.json should now contain:

{"hello": true, "foo": "baz"}

Installation

npm i save-on-change --save

Function: autoSave(filename, onSave)

  • filename \<String> filename of the JSON file
  • onSave \<Function> function that gets called every time the object gets saved

returns object representing the parsed contents of the file (Parser: JSON.parse())

If the JSON file does not exist, an empty object is returned. Once you modify the object, the file will be created or overwritten.

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago