json-tu-file
v1.4.2
Published
A simple way to read/write JSON from files
Downloads
84
Readme
json-tu-file
A simple way to read/write JSON from files.
##Usage
var JSONFile = require('json-tu-file');
var obj = {
"n":8,
"msg":"Hello World 7bc59b8e-8a3f-2d04-62eb-8c9f5c39606f",
"tmx":1388775322979
};
// writeFile(obj, 'file, [options], callback(err))
JSONFile.writeFile(obj, 'write.json', {encoding: 'ascii'}, function (err) {
if (err) throw err;
console.log('ok');
});
// options: Object
// encoding String | Null default = 'utf8'
// mode Number default = 438 (aka 0666 in Octal)
// flag String default = 'w'
// writeFileSync(obj, file, [options])
JSONFile.writeFileSync(obj, 'write_sync.json', {encoding: 'ascii'});
// readFile(file, callback(err, data))
JSONFile.readFile('write.json', function (err, data) {
if (err) throw err;
console.log(data);
});
//readFileSync(file)
var data = JSONFile.readFileSync('write.json');
Development
this projet has been set up with a precommit that forces you to follow a code style, no jshint issues and 100% of code coverage before commit
to run test
npm test
to run jshint
npm run jshint
to run code style
npm run code-style
to check code coverage
npm run check-coverage
to open the code coverage report
npm run open-coverage