Slayer.DB
raw JSON → 1.5.11 verified Sat May 09 auth: no javascript
Slayer.DB is a lightweight, easy-to-use database module for Node.js offering two backends: JSON-file-based (slayersDBJSON) and MongoDB (slayersDBMongo). Version 1.5.11 supports CRUD operations, nested key access, array manipulation, and table partitioning. It is designed for small-to-medium projects where simplicity is prioritized over scalability, with automatic save cooldowns to prevent corruption. Unlike heavier ORMs, it provides a minimal API with no complex schemas.
Common errors
error Cannot find module 'slayer.db' ↓
cause Package not installed
fix
Run: npm install slayer.db
error slayersDBMongo is not a constructor ↓
cause Incorrect import (default instead of named)
fix
Use import { slayersDBMongo } from 'slayer.db'
error TypeError: db.save is not a function ↓
cause Using slayersDBMongo which has no save method (automatic)
fix
Use slayersDBJSON if you need manual save().
Warnings
gotcha Saving too frequently can corrupt JSON data. Built-in save cooldown may not prevent all corruption. ↓
fix Avoid calling save() in rapid loops; rely on internal cooldown or batch updates.
gotcha The slayersDBMongo class requires a running MongoDB instance. No built-in connection pooling or retry logic. ↓
fix Ensure MongoDB is available and provide correct connection options.
gotcha findOneAndUpdate default upsert: true may create documents unintentionally. ↓
fix Set option { upsert: false } if you do not want automatic document creation.
Install
npm install slayer.db yarn add slayer.db pnpm add slayer.db Imports
- slayersDBMongo wrong
const slayersDBMongo = require('slayer.db').slayersDBMongocorrectimport { slayersDBMongo } from 'slayer.db' - slayersDBJSON wrong
import SlayersDBJSON from 'slayer.db'correctimport { slayersDBJSON } from 'slayer.db' - default import (entire module) wrong
import slayer from 'slayer.db'correctimport * as slayer from 'slayer.db'
Quickstart
import { slayersDBJSON } from 'slayer.db';
const db = new slayersDBJSON({ name: 'test' });
db.set('user.name', 'Alice');
db.set('user.age', 30);
console.log(db.get('user.name')); // 'Alice'
console.log(db.has('user.age')); // true
db.delete('user.age');
console.log(db.has('user.age')); // false
db.save();
db.clear();