Snowbase is a simple, fast, and persistent file-based database for Node.js.
It creates and manages a local JSON file to store your data safely, making it perfect for lightweight applications, prototypes, scripts, and small tools.
No servers. No complex setup. Just storage.
- ⚡ Lightweight and easy to use
- 📦 File-based persistence with no external database required
- 🔐 Optional encryption for stored data
- 🧾 Optional logging for operations
- 💾 Automatic backups with versioned files
- ⚙️ Supports both sync and async APIs
- 🧩 Works well for prototypes, local apps, and small projects
npm install snowbaseconst Snowbase = require("snowbase");
const db = new Snowbase();
db.on("ready", () => {
console.log("Database is ready");
});import Snowbase from "snowbase";
const db = new Snowbase();
db.on("ready", () => {
console.log("Database is ready");
});
//Multiples database
const db1 = new Snowbase({ baseDir: "storage" });
const db2 = new Snowbase({ baseDir: "database" }); // creates an isolated new Snowbase storage
// You need to specify the baseDir if use the CLI// Set a value
db.set("user/name", "Pedro");
// Get a value
console.log(db.get("user/name")); // Pedro
// Remove a value
db.remove("user/name");
// Clear the whole database
db.clear();You can configure Snowbase during initialization:
const db = new Snowbase({
baseDir: "./my-database",
encryption: true,
secret: "my-secret",
logging: true,
backup: true,
});- baseDir: directory where the database file will be stored
- encryption: enables encrypted persistence
- secret: secret key used when encryption is enabled
- logging: enables operation logging
- backup: enables automatic backups
db.set("patients", {
john: {
age: 20,
name: "John",
city: "New York",
},
albert: {
age: 31,
name: "Albert",
city: "Chicago",
},
});console.log(db.get("patients/john/city")); // New York
console.log(db.has("patients/albert")); // true
console.log(db.count("patients")); // 2const result = db.find("patients", ({ key }) => key.includes("a"));
console.log(result);
db.remove("patients/albert"); // true
db.remove("patients/susy"); // falseSnowbase can emit events for lifecycle and database operations. You can listen to them with the standard EventEmitter API.
const db = new Snowbase();
db.on("ready", () => {
console.log("Database is ready");
});
db.on("error", (err) => {
console.error(err.message);
});
db.on("get", (details, timestamp) => {
console.log("Get event", details, timestamp);
});- ready: emitted when the database instance is initialized
- error: emitted when an error occurs; receives an Error object
- get: emitted after a read operation; payload includes the path and the resolved value
- set: emitted after a write operation; payload includes the path, key, and value
- remove: emitted after a remove operation; payload includes the path, removed value, and whether it was removed
- clear: emitted after clearing the database; payload includes the previous data
- _write: emitted after data is written to disk
- create backup: emitted when a backup file is created
For non-blocking operations, use the async version:
import Snowbase from "snowbase/async";
const db = new Snowbase({
encryption: true,
secret: "my-secret",
backup: true,
});
await db.set("user/name", "Pedro");
console.log(await db.get("user/name"));Snowbase also includes a CLI for common tasks:
snowbase init
snowbase inspect
snowbase backup
snowbase restore
snowbase get user/name
snowbase set user/name Pedro
snowbase remove user/name
snowbase clear
snowbase hasMIT @ Pedro Henrique Brandão (p3droob)
