Easy JSON Database (easy-json-database) is a lightweight, file-system based database solution for Node.js environments. Currently stable at version 1.5.1, it has seen no new releases in approximately three years, suggesting a maintenance-only status without active feature development. This package differentiates itself through its extreme simplicity, storing all data directly within a single JSON file. It offers basic CRUD operations (set, get, delete, has), numerical manipulations (add, subtract), and array operations (push), along with a `clear` and `all` method. Key features include an optional snapshot mechanism for backups. Unlike robust NoSQL databases (e.g., MongoDB, CouchDB) or relational databases with JSON capabilities (e.g., PostgreSQL), easy-json-database operates by loading and saving the entire JSON file to disk for every write operation, making it suitable only for small datasets and low-concurrency scenarios. It is primarily used in projects requiring minimal setup and direct file storage, such as the 'Scratch For Discord' bot.
npm install easy-json-databaseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic CRUD operations, numerical increments, array pushes, existence checks, and data clearing using `easy-json-database` in a TypeScript environment. It also shows how to configure snapshots and includes file system cleanup for a reproducible example.
For larger datasets, higher throughput, or concurrent access, consider using dedicated databases like `lowdb` (with an appropriate adapter), SQLite, or NoSQL solutions such as MongoDB or CouchDB. Avoid frequent, small write operations.
Implement robust backup strategies (like the built-in snapshots feature), ensure graceful application shutdowns, and consider external file-system level atomicity solutions if absolute data integrity is critical. For mission-critical data, avoid flat-file databases entirely.
Ensure that only one instance of the application accesses the database file at a time, or implement external locking mechanisms (e.g., file locks) if multiple processes need to interact with the same database file. Design your application to avoid concurrent writes to the same key or file.
Evaluate if the current feature set and stability meet your long-term project needs. For projects requiring active development, community support, or modern features, consider more actively maintained alternatives like `lowdb` or `node-json-db`.
Either convert your project to ES Modules by adding `"type": "module"` to your `package.json` file or rename your file to `.mjs`, or use the CommonJS `require()` syntax: `const { Database } = require('easy-json-database');`For direct JSON file imports in TypeScript with ESM, ensure `"resolveJsonModule": true` and `"esModuleInterop": true` are set in `tsconfig.json`. Also, remember that direct JSON imports usually expose the entire JSON as a default export, or require specific import attributes (e.g., `import data from './data.json' with { type: 'json' }`) in native ESM environments.Ensure the directory path provided to the `Database` constructor exists and that your application has read/write permissions for that directory. You might need to create the directory programmatically using `fs.mkdirSync(path, { recursive: true })` before initializing the database.Inspect the `.json` file for syntax errors using a JSON linter or validator. Common fixes include adding/removing commas, ensuring all keys and string values use double quotes, escaping special characters within strings, and balancing all brackets. If the file is corrupted, restore from a backup.
No dependency data recorded yet.