Very fast queue for JSON write queries.
npm install jsafe
const { write, read } = require("jsafe")
- write(jsonPath, jsonData) ⇒
promise
Add JSON object to write or to stack.
- read(jsonPath, defaultJsonData) ⇒
object
Read the JSON file if it exists.
Add JSON object to write or to stack.
Kind: global function
Returns: promise
- - But catch error is optional.
Param | Type | Description |
---|---|---|
jsonPath | string |
The path of json file. |
jsonData | object |
JSON stringable data. |
write("./file.json", json)
// Check if a writing is in progress.
// If so, overwrites the waiting stack
// with the new version of the file.
Read the JSON file if it exists.
Kind: global function
Returns: object
- - JSON exploitable data.
Param | Type | Description |
---|---|---|
jsonPath | string |
The path of json file. |
defaultJsonData | object |
JSON stringable data. |
const json = read("./file.json", "Hello World")
// Require json and delete require.cache.
// To do only once in the same script.
// Returns defaultJsonData if the file is non-existent.