1.0.0 • Published 4 months ago
neffs-js v1.0.0
NefFS-JS
A standalone file system–based JSON database for Node.js.
Installation
Install the module via npm:
npm install NefFS-JS --save
Usage
Below is an example of how to use NefFS-JS in your project:
// Import the JSON database module.
const jsonDb = require('NefFS-JS');
// Initialize the database by specifying a directory (e.g., 'db') where JSON files will be stored.
const db = jsonDb('db');
// Use collections like "money", "seen", "posts", etc.
// Collections are automatically created if they don't exist.
db.money.set('max', 10);
db.money.set('some_user', db.money.get('phil') + 10);
db.seen.set('some_user', Date.now());
db.posts.set('posts', [
{ title: 'nef fs is awesome!', body: '...', likes: 10 },
{ title: 'flexbility', body: '...', likes: 3 },
{ title: 'something someting something', body: '...', likes: 8 }
]);
After running your application, the specified directory (e.g., db
) will contain JSON files corresponding to each collection.
API
Each collection provides the following methods:
- get(key) – Returns the value associated with the given key.
- set(key, value) – Sets the value for the given key and persists the change to disk.
- put(key, updater) – Updates the value based on the current value using an updater function.
- remove(key) – Deletes the key and its associated value from the collection.
- keys() – Returns an array of all keys in the collection.
If you access a collection that does not exist, it is automatically created.
Examples
// Setting and getting values
db.money.set('ash', 500);
console.log(db.money.get('ash')); // Output: 500
// Updating values using put()
db.money.put('ash', (val) => val + 100);
console.log(db.money.get('ash')); // Output: 600
// Listing keys
console.log(db.money.keys()); // Output: ['ash']
// Removing a key
db.money.remove('ash');
console.log(db.money.get('ash')); // Output: undefined
Credits
Developed By Clark Jones (impulse.pokemonshowdown@gmail.com).
Licensed under the MIT License.
1.0.0
4 months ago