Simple, lightweight database alternative using JSON files
Stop over-engineering your projects! jsonl-db gives you a database-like experience using simple JSON files. Perfect for prototypes, small projects, or when you just need to get things done quickly without the complexity of traditional databases.
- π Get started in seconds - No setup, no configuration, no complex schemas
- π Uses familiar JSON files - Your data stays in human-readable format
- β‘ Zero dependencies - Lightweight and fast
- π Full CRUD operations - Add, read, update, delete with simple methods
- π Powerful querying - Search and filter your data easily
- π‘ Perfect for - Prototypes, small apps, data processing, testing, learning
JSONL (JSON Lines) is a simple format where each line contains a valid JSON object. Think of it as a database table where each row is a JSON object on its own line.
Example:
{"id": 1, "name": "Alice", "age": 25}
{"id": 2, "name": "Bob", "age": 30}
{"id": 3, "name": "Charlie", "age": 28}Benefits:
- β Easy to read and debug
- β Simple to append new records
- β No complex parsing needed
- β Works with standard text tools
- β Human-editable
npm install jsonl-dbimport { jsonlDir } from "jsonl-db";
// Create a database directory
const db = jsonlDir("./data");
// Create a users collection
const users = db.file("users");
// Add a user
await users.add({ name: "John", age: 27, email: "[email protected]" });
// Find a user
const john = await users.findOne(user => user.name === "John");
// Update a user
const updatedUsers = await users.update(
user => user.name === "John",
user => ({ ...user, age: 28 })
);
// Delete a user
const remainingUsers = await users.delete(user => user.name === "John");- β Add - Single records or batches
- π Read - Find first match or all matches
- π Update - By condition with custom logic
- β Delete - Specific records with conditions
- π Find - First match or all matches
- π Count - Total records in collection
- β‘ Fast Access - Efficient batch processing
- π― Flexible - Custom conditions and filters
- π Auto-create - Files created automatically
- ποΈ Organized - Directory-based structure
- πΎ Persistent - Data survives restarts
const db = jsonlDir("./data");
const users = db.file("users");
// Add multiple users
await users.add([
{ id: 1, name: "Alice", role: "admin" },
{ id: 2, name: "Bob", role: "user" },
{ id: 3, name: "Charlie", role: "user" }
]);
// Find all admins
const admins = await users.find(user => user.role === "admin");
// Count total users
const userCount = await users.count();const db = jsonlDir("./logs");
const appLogs = db.file("app");
// Add log entry
await appLogs.add({
timestamp: new Date().toISOString(),
level: "info",
message: "User logged in",
userId: 123
});
// Get recent logs
const recentLogs = await appLogs.find(log =>
new Date(log.timestamp) > new Date(Date.now() - 24 * 60 * 60 * 1000)
);const db = jsonlDir("./config");
const settings = db.file("app-settings");
// Store settings
await settings.add({ key: "theme", value: "dark" });
await settings.add({ key: "language", value: "en" });
// Get setting
const theme = await settings.findOne(setting => setting.key === "theme");const db = jsonlDir("./app-data");
// Different collections for different entities
const users = db.file("users");
const products = db.file("products");
const orders = db.file("orders");
// Work with users
await users.add({ name: "John", email: "[email protected]" });
// Work with products
await products.add({ name: "Laptop", price: 999.99 });
// Work with orders
await orders.add({ userId: 1, productId: 1, quantity: 2 });Perfect for:
- π Prototypes - Get your idea working fast
- π± Small apps - Personal projects, simple tools
- π§ͺ Testing - Mock data, test scenarios
- π Data processing - ETL jobs, data analysis
- π Learning - Understand database concepts
- π§ Configuration - App settings, user preferences
Consider alternatives when:
- π Large datasets - Millions of records
- π₯ Multiple users - Concurrent access needed
- π Complex security - Advanced permissions required
- π High performance - Sub-millisecond queries needed
- Node.js v22 or higher
Multiple formats available for different environments:
- ESM (
.js) - Modern ES modules - CommonJS (
.cjs) - Traditional Node.js - TypeScript (
.d.ts) - Full type support
import { jsonlDir } from "jsonl-db";
// Create a database in a directory
const db = jsonlDir("./data");
// Create collections (files) for different entities
const users = db.file("users");
const products = db.file("products");// Single record
await users.add({ name: "John", age: 27 });
// Multiple records
await users.add([
{ name: "John", age: 27 },
{ name: "Jane", age: 31 }
]);// Find first match
const user = await users.findOne(user => user.name === "John");
// Find all matches
const adults = await users.find(user => user.age >= 18);
// Count total records
const total = await users.count();// Update with custom logic
const updatedUsers = await users.update(
user => user.age > 30,
user => ({ ...user, isSenior: true })
);// Delete with condition
const remainingUsers = await users.delete(user => user.age > 100);We love contributions! Here's how to help:
- Fork the repository
- Create a feature branch:
git checkout -b my-feature - Make your changes and add tests
- Test everything:
npm test - Commit with clear messages
- Push and submit a pull request
MIT License - feel free to use in any project!
Ready to simplify your data storage? Start with jsonl-db and focus on building features, not database complexity! π