json-tu-file

1.4.2 • Public • Published

json-tu-file

A simple way to read/write JSON from files.

Build StatusCode Coverage 100%ISC Licensenpm - v1.4.1

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

Package Sidebar

Install

npm i json-tu-file

Weekly Downloads

4

Version

1.4.2

License

ISC

Last publish

Collaborators

  • quim