
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
jsonfile-storage
Advanced tools
Package with a simple API for storing json files to a local directory.
Package with a simple API for storing json files to a local directory.
npm i jsonfile-storage
var JSONFileStorage = require('jsonfile-storage');
// directory must exist before creating storage instance
var storage = new JSONFileStorage('./data');
// put stuff into the storage
storage.put({ "key" : "stuff" }).then(result => {
console.log(result);
// outputs: { key: 'stuff', id: '137280bc-8afe-4ba2-9625-8c1d20b13c58' }
// the id is generated automatically if it does not exist
// remove item from the storage
storage.remove(result.id).then(() => {
// file was removed from storage
console.log(storage.getFiles());
// outputs: []
})
})
Kind: global class
Promise.<any>Promise.<Array.<any>>Promise.<any>Promise.<Array.<any>>Promise.<void>Array.<string>Creates a new instance of JSONFileStorage
Throws:
| Param | Type | Description |
|---|---|---|
| directoryPath | string | The path of the folder where the data will be saved/retrieved |
Promise.<any>Get a single item from the directory with the id
Kind: instance method of JSONFileStorage
Returns: Promise.<any> - a promise that resolves into the file that matches the id.
The promise is rejected if the file is not found with the id. Or if there is an error parsing the JSON.
| Param | Type | Description |
|---|---|---|
| id | string | id of the item to get |
Promise.<Array.<any>>Gets all the items from the directory and their content
Kind: instance method of JSONFileStorage
Promise.<any>Puts a single item in the directory
Kind: instance method of JSONFileStorage
Returns: Promise.<any> - promise that resolves into the file that was put
| Param | Type | Default | Description |
|---|---|---|---|
| item | any | item to be put in to the directory | |
| [updateListing] | boolean | true | should the files property be updated. Default is true |
Promise.<Array.<any>>Puts items in the directory in bulk
Kind: instance method of JSONFileStorage
Returns: Promise.<Array.<any>> - items putted to the directory
Throws:
| Param | Type | Description |
|---|---|---|
| items | Array.<any> | items to be put to the directory |
removes the specified file from the directory
Kind: instance method of JSONFileStorage
| Param | Type | Default | Description |
|---|---|---|---|
| id | string | id of the file | |
| [updateListing] | boolean | true | should the file listing be updated. Default is true |
Promise.<void>Deletes files in bulk
Kind: instance method of JSONFileStorage
| Param | Type | Description |
|---|---|---|
| ids | Array.<string> | Array of ids for the files to be deleted |
Array.<string>Get the json files inside the directory
Kind: instance method of JSONFileStorage
Returns: Array.<string> - files in the directory
Changes the directory used within this class
Kind: instance method of JSONFileStorage
| Param | Type | Description |
|---|---|---|
| directoryPath | string | path where to change to |
FAQs
Package with a simple API for storing json files to a local directory.
We found that jsonfile-storage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.