# qjson-db

> Lightweight local JSON-based database for Node.js projects.

Latest version **1.2.3** (published 2025-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install qjson-db
pnpm add qjson-db
yarn add qjson-db
bun add qjson-db
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2025-07-26 |
| First published | 2025-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Greitan.co |
| Maintainers | alphamsq |
| Keywords | json, database, lightweight, storage, file, fs, local-db, embedded-db |

## Links

- npm: https://www.npmjs.com/package/qjson-db
- Repository: https://github.com/AlphaMSq/qjson-db
- Homepage: https://github.com/AlphaMSq/qjson-db#readme
- Issues: https://github.com/AlphaMSq/qjson-db/issues
- npm.io page: https://npm.io/package/qjson-db

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.2.3 (latest) — 2025-07-26
- 1.2.2 — 2025-07-26
- 1.2.1 — 2025-07-26
- 1.2.0 — 2025-07-26
- 1.1.0 — 2025-07-19

## README

# qjson-db

Lightweight local JSON-based database for Node.js projects.

## Installation

`npm install qjson-db`

## Usage

```js
const JSONdb = require("qjson-db").default; /* CommonJS */
const db = new JSONdb("./data.json");

db.set("username", "Qpla");
console.log(db.get("username")); // "Qpla"
```

## Options

- `asyncWrite` — Enables asynchronous write to disk (default: false)
- `syncOnWrite` — Writes changes to disk immediately after modification (default: true)
- `jsonSpaces` — Number of spaces to use for JSON formatting (default: 4)

## API

### new JSONdb(filePath[, options])

Creates a new database instance.

- `filePath` (string) — Path to the JSON file (extension .json will be added if missing)
- `options` (object, optional):
  - `asyncWrite` (boolean)
  - `syncOnWrite` (boolean)
  - `jsonSpaces` (number)
  - `stringify` (function)
  - `parse` (function)

### Methods

- `init(key, value)` — Initializes a key with a value if it doesn't exist.
- `set(key, value)` — Sets or updates a key with a value.
- `get(key)` — Retrieves the value by key.
- `has(key)` — Checks if a key exists.
- `delete(key)` — Deletes a key. Returns true if deleted, undefined if not found.
- `deleteAll()` — Deletes all keys.
- `sync()` — Writes current storage to disk.
- `JSON([storage])` — Gets a clone of the storage or replaces storage if an object is passed.

## License

MIT

---

Made with ❤️

---
_Source: https://npm.io/package/qjson-db · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
