A simple way to read/write JSON from files


A simple way to read/write JSON from files.


var JSONFile = require('json-tu-file');

var obj = {
    "msg":"Hello World 7bc59b8e-8a3f-2d04-62eb-8c9f5c39606f",

// writeFile(obj, 'file, [options], callback(err))

JSONFile.writeFile(obj, 'write.json', {encoding: 'ascii'}, function (err) {
    if (err) throw err;

// 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;


var data = JSONFile.readFileSync('write.json');

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