TwinDB is a lightweight, local, file-based database designed for Node.js applications, currently at version 1.1.2. It stores data in JSON files, making it suitable for small-scale applications, configuration management, or local development environments where a full-fledged database system is overkill. Its key differentiator lies in its straightforward API for manipulating JSON structures directly through object paths, offering methods like `set`, `get`, `delete`, `sum`, `sub`, `concat`, `push`, and `pull`. While it doesn't offer advanced features like transactions or complex querying found in relational or NoSQL databases, it excels in providing a simple, persistent data store. The project appears to have an ad-hoc release cadence, with recent updates indicating active maintenance, focusing on utility and ease of use. It specifically requires an ES module environment.
npm install twin-dbVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a TwinDB database, set and retrieve values using object paths, perform atomic updates like sum and push, and delete entries. It also includes cleanup for a runnable example.
Add `"type": "module"` to your `package.json` file. If your project uses CommonJS, consider transpiling or switching to an ESM-compatible setup.
Always ensure that the data you are attempting to `set` or `push` into TwinDB is serializable to JSON (strings, numbers, booleans, arrays, objects, `null`).
Upgrade to `twin-db >=1.1.0` to benefit from the improved behavior where `sum`, `sub`, and `push` will automatically initialize non-existent paths. If using older versions, ensure paths are initialized before calling these methods.
Change `const TwinDB = require('twin-db');` to `import TwinDB from 'twin-db';`. Also, ensure your `package.json` file includes `"type": "module"`.TwinDB converts non-JSON values to `null`. Review the value you are passing to the `set` method and ensure it is a valid JSON type (string, number, boolean, array, object, or `null`).
Ensure the target path for `sum` or `sub` operations holds a numeric value. If the path might be missing, consider upgrading to `twin-db >=1.1.0` for automatic initialization or manually `set` an initial numeric value (e.g., `0`) first.
No dependency data recorded yet.