Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including filejson with all npm packages installed. Try it out:

var filejson = require("filejson")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

filejson v1.0.15

Seamlessly syncs a JavaScript value to a JSON file in the background whenever that value changes.



Seamlessly sync a JavaScript value to a JSON encoded file automatically in the background whenever that value changes. A value can be a Javascript: string, number, boolean, null, object, or an array. The value can be structured in an array or an object to allow for more complex data stores. These structures can also be nested. As a result, you can use this module as a simple document store for storing semi structured data.


ECMAScript 6 Reflect and Proxy objects support, which is found natively in Node.js >= 6. If you are using a version of Node.js < 6, use a polyfill, such as harmony-reflect. Proxy support is key for this module working so eloquently. Other non-Proxy based modules require function calls each time you wish to save an object. Unlike those, filejson is as easy as file.contents = "my new value" or file.contents = {"msg": "Hello World"} and the changes are automatically saved to disk.


npm install filejson --save

If you are using Node.js 5 or earlier, some additional installation and usage steps are needed. Click here.

Example usage

var Filejson = require("filejson");
var file1 = new Filejson();

file1.load("file1.json", proceed); // file1.json contains {"abc": "123"}

function proceed(error, file) {
    if(error) {

    console.log(file.contents); // outputs {"abc": "123"}

    file.contents.msg = "Hello World"; // saves {"abc": "123", "msg": "Hello World"} to file1.json.

    console.log(file.contents); // outputs {"abc": "123", "msg": "Hello World"}


Additional installation and usage steps for those using Node.js 5 or earlier

npm install harmony-reflect --save
  • In addition to requiring filejson, you will need to require harmony-reflect at the top of your app, like this:
var Reflect = require('harmony-reflect');
  • Lastly, every time you run your app you will need to use the node --harmony_proxies flag, like this:
node --harmony_proxies index.js
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free