JDB is a lightweight, file-append-only, in-memory, non-blocking I/O database inspired by NeDB. It allows users to manipulate data directly using standard JavaScript code, eliminating the need for a separate query language. The current stable version is 0.5.5, indicating a relatively mature but perhaps slower-paced development cycle without explicit release cadence information. Key differentiators include its lightweight core (approx. 200 lines), direct JavaScript data manipulation, promise support, and both standalone server and in-application library modes. It operates by appending JavaScript commands to a file, which are then re-executed on startup to reconstruct the database's in-memory state. Periodically, the database file can be compacted into a single JSON object to optimize storage and startup time.
npm install jdbVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates initializing a JDB instance, saving complex JavaScript objects using both callback and promise-based `exec` methods, accessing the saved data directly from the in-memory document, and finally simulating a restart to confirm data persistence by re-initializing from the saved file. It also includes cleanup of the temporary database file.
Only use JDB with database files from trusted sources and ensure strict file system permissions for database files. Avoid using JDB in multi-tenant environments where users can submit arbitrary JavaScript code for data manipulation without stringent validation.
Pass any necessary external data into the `exec` call via the `data` option, and access it within the command function through the `data` argument: `jdb.exec({ data: myExternalData, command: (jdb, receivedData) => { jdb.doc.myKey = receivedData; jdb.save(); } });`Regularly use `jdb.compactDBFile()` (or enable `compactDBFile: true` in `init` options) to reduce the number of commands that need to be replayed. Consider alternative database solutions if extremely fast startup for very large, highly mutable datasets is a critical requirement.
Pass the required data via the `data` property of the `exec` options object and access it as the second argument to your command function: `jdb.exec({ data: myValue, command: (db, receivedValue) => { db.doc.someKey = receivedValue; db.save(); } });`Ensure you invoke the required module by adding `()` after the `require` call: `const jdb = require('jdb')();`No dependency data recorded yet.