cache-database
raw JSON → 1.3.3 verified Fri May 01 auth: no javascript
A lightweight, promise-based in-memory database with MongoDB-like query syntax (e.g., $in, $gte, $lte) for Node.js. Version 1.3.3 (last release appears infrequent, no clear cadence) provides basic CRUD operations, sorting, skipping, and field projection. Unlike full databases, it stores data in memory without persistence, making it suitable for caching or prototyping. No external dependencies.
Common errors
error TypeError: cache.create is not a function ↓
cause Importing the package incorrectly (using named import instead of default).
fix
Use const cache = require('cache-database');
error TypeError: Cannot read property 'data' of undefined ↓
cause Forgetting to return or await the promise from find().
fix
Ensure you await the promise: const result = await collection.find(...);
Warnings
gotcha find() returns an object with data, search, skip, sort, records — not just an array. ↓
fix Access result.data for the documents array.
gotcha The sort parameter in find() is the third argument, not a separate options object. ↓
fix Pass sort as the third argument, e.g., find(query, projection, sort, skip, limit) – but the README shows sort as third or fourth; check documentation.
gotcha All operations are async and return Promises; synchronous usage will cause issues. ↓
fix Use .then() or await inside async functions.
Install
npm install cache-database yarn add cache-database pnpm add cache-database Imports
- default wrong
import cache from 'cache-database';correctconst cache = require('cache-database'); - create wrong
cache.Collection('collection')correctcache.create('collection'); - collection.find wrong
collection.find({a: 1}, {b: 0}, 30, 10)correctcollection.find({a: 1}, {b: 0}).then(data => {})
Quickstart
const cache = require('cache-database');
const collection = cache.create('users');
collection.create({name: 'Alice', age: 30})
.then(() => collection.find({age: {$gte: 25}}))
.then(result => console.log(result.data))
.catch(err => console.error(err));