Skip to Content

Installation of @atosjs/database

Terminal
npm install @atosjs/database
Simple, lightweight, JSON-based database utility:

@atosjs/database is a local storage system based on .json files, ideal for small to medium-sized projects, bots, or CLIs.

index.js
const { Database } = require("@atosjs/database"); const db = new Database("db.json"); (async () => { await db.set("user.123", { name: "Alice", coins: 50 }); console.log(await db.get("user.123")); // { name: 'Alice', coins: 50 } await db.update("user.123.coins", (value) => value + 10); console.log(await db.get("user.123.coins")); // 60 await db.delete("user.123.name"); console.log(await db.get("user.123")); // { coins: 60 } await db.push("user.123.inventory", "sword"); console.log(await db.get("user.123.inventory")); // ["sword"] })();

Expected output:
Terminal
{ name: 'Alice', coins: 50 } 60 { coins: 60 } ["sword"]

set(path, value)

set-example.js
await db.set("config.prefix", "!"); await db.set("user.1", { name: "João", vip: true });

Creates or replaces a value at a specific path.

  • Supports nested structures (object.object.key)

get(path)

get-example.js
const prefix = await db.get("config.prefix"); console.log(prefix); // "!"

Retrieves the value stored at the given path.

  • Returns undefined if it doesn’t exist.

update(path, callback)

update-example.js
await db.set("coins", 100); await db.update("coins", (val) => val + 50);

Updates a value by applying a transformation function.

  • Ideal for sums, subtractions, or dynamic modifications.

delete(path)

delete-example.js
await db.delete("user.1.vip");

Removes the specified key from the database.

  • Can delete nested values.

push(path, value)

push-example.js
await db.push("logins", "2025-04-29");

Adds a value to the end of an array.

  • Creates the array if it doesn’t exist.

has(path)

has-example.js
if (await db.has("user.1")) { console.log("User exists."); }

Returns true if the path exists, false otherwise.


🧩 Methods Table

Overview of new Database(path);

MethodTypeExampleDescription
set(path, val)Promisedb.set("x.y", 1)Creates or overwrites a value.
get(path)Promisedb.get("x.y")Returns the value at the specified path.
update(path, cb)Promisedb.update("x", (v) => v + 1)Updates an existing value based on a function.
delete(path)Promisedb.delete("x.y")Removes a specific key or value.
Last updated on: