node package manager


jSync - Module for sync local object variable with *.js or *.coffee file



$ npm install jsync

Simple usage

var jsync = require('jsync');
var obj = jsync('data.json'); // also you can load *.js, *.cson and *.coffee files 
// now object will keep in sync with json-file 

Set interval

var obj = jsync('data.js', 100); // file check every 100ms 

Set context for eval

// data.js 
    someVariable: this.prop

Context can only be the Object

context = { prop: 'value' };
var obj = jsync('data.js', context);
console.log(obj); // { someVariable: 'value' } 

Set handler

// data.js 
function handler (err, arr) {
var obj = jsync('data.js', handler);
console.log(obj); // [1,2] 

All-in-one call

var obj = jsync(file, interval, context, handler); // all arguments are optional except `file` 

Cancel sync and remove watcher


Simple read without sync

var obj ='data.js', context);

Manual sync with or without new context

jsync.trigger(obj, newContext);

Save synced object to file

var obj = jsync('data.js');*, fileName, callback */); // if fileName not set it will use 'data.js' 

function will execute asynchronously if callback is set

Run some tests

$ cd /path/to/jsync/
$ npm test