EJDB - Embedded JSON Database
raw JSON →EJDB (Embedded JSON Database) is a lightweight, embedded NoSQL database engine for Node.js, providing a MongoDB-like query language for local JSON document storage. The `ejdb` npm package specifically provides the Node.js bindings for the first generation EJDB engine. This version, `1.2.12-44`, is stable but officially discontinued and has not been updated in over seven years. The project has entirely transitioned to its successor, `ejdb2_node`, which is a complete rewrite. Users should migrate to `ejdb2_node` for active development, maintenance, and new features, including security updates. EJDB v1.x was designed for Node.js versions >=4.0.0 and focused on providing fast, self-contained, file-based JSON document storage with indexing, without requiring a separate server process. Its release cadence was sporadic, with its last publish seven years ago. Its key differentiator was being a high-performance embedded JSON store suitable for small to medium-scale applications where a full-fledged database server was considered overkill.
Common errors
error Error: `node-gyp` failed to rebuild... ↓
node-gyp prerequisites (e.g., npm install -g node-gyp, then follow its setup instructions for your OS). For long-term stability, migrate to ejdb2_node. error TypeError: require is not a function ↓
.js file without type: "module") or refactor your project to use ejdb2_node which may offer better ESM compatibility. error Error: Cannot find module 'ejdb' ↓
npm install ejdb again. Check the console output for node-gyp errors. If errors persist, ensure build tools are configured or consider migrating to ejdb2_node. Warnings
breaking The `ejdb` package is officially discontinued and deprecated. All new development, maintenance, and support efforts have shifted to its successor, `ejdb2_node`. Users should plan to migrate to `ejdb2_node` as soon as possible for continued functionality and security. ↓
gotcha As a native Node.js add-on, `ejdb` requires `node-gyp` to compile C++ source code during installation. This process can frequently fail on modern Node.js versions or certain operating systems due to missing build tools (e.g., C++ compilers, Python) or ABI incompatibilities. The package has not been updated in seven years. ↓
gotcha This package receives no active maintenance, bug fixes, or security updates. Using it in production environments may expose applications to unpatched vulnerabilities or unexpected behavior with newer Node.js versions. ↓
Install
npm install ejdb yarn add ejdb pnpm add ejdb Imports
- EJDB wrong
import EJDB from 'ejdb'correctconst EJDB = require('ejdb') - EJDB.QL wrong
import { QL } from 'ejdb'correctconst QL = EJDB.QL - EJDB.DEFAULT_OPEN_MODE wrong
import { DEFAULT_OPEN_MODE } from 'ejdb'correctconst { DEFAULT_OPEN_MODE } = EJDB
Quickstart
const EJDB = require('ejdb');
const db = new EJDB();
async function run() {
try {
// Open/create a database file named 'my_database.ejdb'
// EJDB.DEFAULT_OPEN_MODE includes read/write, create if not exists, and truncate on open if specified.
await db.open('my_database.ejdb', EJDB.DEFAULT_OPEN_MODE);
console.log('Database opened successfully.');
// Insert a document into the 'users' collection
const userDoc = {
name: 'John Doe',
age: 42,
city: 'Sampleville',
interests: ['coding', 'reading', 'hiking']
};
const oid = await db.insert('users', userDoc);
console.log(`Document inserted with OID: ${oid}`);
// Find documents in the 'users' collection where age is greater than 30
// EJDB.QL is used to construct MongoDB-like queries.
const query = EJDB.QL('{"age": {"$gt": 30}}');
const cursor = await db.find('users', query);
const results = await cursor.toArray();
console.log('Found documents:', results);
// Close the database connection
await db.close();
console.log('Database closed.');
} catch (err) {
console.error('An error occurred:', err);
}
}
run();