A modern, simple, and async JSON database for Node.js with zero dependencies and a data-safe queue.
npm install nope.db





> A modern, simple, and asynchronous JSON database for Node.js. Zero dependencies, dual-module (ESM/CJS) support, and a robust queueing system to prevent data corruption.
- Asynchronous: All methods are Promise-based (async/await).
- Data Safe: Uses an atomic write queue to prevent data corruption from concurrent writes.
- Dual Module: Supports both ES Modules (import) and CommonJS (require).
- Zero Dependencies: Lightweight and clean.
- Nested Data: Access and manage nested objects with ease using a separator (e.g., user.settings.theme).
``console`
$ npm install nope.db
All database operations are asynchronous and return a Promise.
`javascript
import { NopeDB } from 'nope.db';
// All settings are optional
const db = new NopeDB({
path: './mydb.json', // defaults to './db.json'
spaces: 2, // defaults to 2 (for JSON formatting)
separator: '.' // defaults to '.'
});
async function main() {
try {
await db.set('user.1', { name: 'nopeion', role: 'admin' });
// This will be stored in 'mydb.json' as:
// {
// "user": {
// "1": { "name": "nopeion", "role": "admin" }
// }
// }
const user = await db.get('user.1');
console.log(user); // { name: 'nopeion', role: 'admin' }
// Access nested properties using the separator
const role = await db.get('user.1.role');
console.log(role); // 'admin'
} catch (error) {
console.error("Database operation failed:", error);
}
}
main();
`
`javascript
const { NopeDB } = require('nope.db');
const db = new NopeDB(); // Using all default settings
(async () => {
try {
await db.set('counter', 10);
await db.add('counter', 5);
const count = await db.get('counter');
console.log(count); // 15
} catch (error) {
console.error("Database operation failed:", error);
}
})();
`
All methods are asynchronous and return a Promise.
Creates a new database instance.
- settings (optional): An object with the following properties:
- path (string): Path to the database file.
- Default: './db.json'spaces
- (number): Number of spaces for JSON formatting.2
- Default: separator
- (string): Character to use for nested object access.'.'
- Default:
---
- The value that was set.---
$3
Gets an element from the database.
- Returns: Promise - The requested data, or null if not found.---
$3
Adds a number to an element. If the element doesn't exist, it will be created.
- Returns: Promise - The total result.
- Throws: DatabaseError if the existing data or the value is not a number.---
$3
Subtracts a number from an element.
- Returns: Promise - The remaining result.
- Throws: DatabaseError if the existing data or the value is not a number.---
$3
Checks if data exists in the database.
- Returns: Promise - true or false.---
$3
Pushes an element into an array. If the array doesn't exist, it will be created.
- Returns: Promise - The updated array.
- Throws: DatabaseError if the existing data is not an array.---
$3
Deletes an element from the database.
- Returns: Promise - true if deletion was successful, false if not found.---
$3
Returns all data in the database.
- Returns: Promise