fs-ndjson
read and write NDJSON files (Newline Delimited JSON)
FYI
While NDJSON is often used for efficient streaming of JSON, it is also a good format for persisting and retreiving object data collections to and from disk. For example, NeDB uses the format.
See Also:
API
The following fs-ndjson
methods mirror the fs
core module method APIs, however, the methods have been universalified so that you can use promises or callbacks for async.
- readFile
- readFileSync
- writeFile
- writeFileSync
BONUS: writeFile
and writeFileSync
will create the parent directory, if it does not already exist.
Installation
$ npm install --save fs-ndjson
Usage
Given /Users/tyler/project-mayhem/enemies.db
contains
{"name":"Equifax","location":"Atlanta, GA"}
{"name":"Visa","location":"Foster City, CA"}
const fsNdjson = ; // can return a promisefsNdjson; // can use a callbackfsNdjson; // can be used synchronouslylet enemies = fsNdjson; // ******** BUT WAIT, THERE'S MORE! ******** //// Not only does it read, but it writes too! // // fsNdjson.writeFile // use callback or promise// fsNdjson.writeFileSync // does what you think it does
License
ISC © Buster Collings