object-fsify

0.2.0 • Public • Published

object-fsify

file system persisted variables as simple as it ever will be with the help of ES6 Proxies magic.

// myAwesomeNodejsScript.js
const a = objectFsify([], 'myArray.json')
 
a.push(10)
// myArray.json is now '[10]')
a.push(20)
// myArray.json is now '[10, 20]')
a.push(33)
// myArray.json is now '[10,20,33]')
 
// of course it works the same with objects
const a = objectFsify({} 'myObject.json')
 
a.b = 10
// myObject.json is now '{b: 10}')

When you run the script myAwesomeNodejsScript.js again, all the numbers will be there twice in the array as you would expect-file is loaded up when you initialise the a variable.

options

{
  async: true,  // default false, true makes fs operation async
  indent: 2 // default is none, 2 makes JSON file indents 2 spaces
}

Readme

Keywords

none

Package Sidebar

Install

npm i object-fsify

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

3.95 kB

Total Files

6

Last publish

Collaborators

  • capaj