Registry / database / pro.db

pro.db

JSON →
library3.0.8jsnpmunverified

pro.db is a lightweight, easy-to-use database package designed for simple data storage, primarily in Node.js environments. It operates by storing data as JSON objects within local files, functioning as a file-based key-value store. The current stable version is 3.0.8. Its primary differentiator lies in its simplicity and direct API for common database operations like setting, getting, deleting, and manipulating numeric values or arrays within the stored JSON structure. The package appears to follow an as-needed release cadence, focusing on stability for its core features, and is particularly suited for small-scale applications or Discord bot development where a full-fledged relational database might be overkill. It does not require external database server setup, relying solely on local file system operations.

npm install pro.db
INSTALL
IMPORT
SIG · PRO.DB
P
pro.db
databasejavascriptv3.0.8
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

db
✓ const db = require('pro.db');
✗ import db from 'pro.db';
The package is primarily designed for CommonJS. Direct ESM import might lead to 'require is not defined' errors if not transpiled or used with specific module loaders.
db (individual functions)
✓ const { set, get } = require('pro.db');
✗ const db = require('pro.db').db;
While the main export is an object with methods, destructuring is possible for convenience, though less common than importing the whole object.
Pro.db in TypeScript
✓ import db from 'pro.db';
✗ import * as db from 'pro.db';
If using TypeScript, you might need a custom `d.ts` declaration for CommonJS modules (e.g., `declare module 'pro.db' { const db: any; export = db; }`) or enable `esModuleInterop` and `allowSyntheticDefaultImports` in `tsconfig.json` to use `import db from 'pro.db';`.

This example demonstrates common CRUD operations (set, get, add, push, delete) with pro.db, including checking key existence, fetching all data, and creating a backup file, highlighting its synchronous nature and file-based storage.

const db = require('pro.db'); const path = require('path'); const fs = require('fs'); const dbFilePath = path.join(__dirname, 'database.json'); // Ensure the database file exists or is created before operations if (!fs.existsSync(dbFilePath)) { fs.writeFileSync(dbFilePath, '{}', 'utf8'); } // Set a value db.set('user:123:name', 'Alice'); db.set('user:123:age', 30); db.set('products', [{ id: 1, name: 'Laptop' }, { id: 2, name: 'Mouse' }]); console.log('User name:', db.get('user:123:name')); console.log('Products:', db.get('products')); // Add to a numeric key db.add('user:123:age', 5); console.log('New age:', db.get('user:123:age')); // Push to an array key db.push('products', { id: 3, name: 'Keyboard' }); console.log('Updated products:', db.get('products')); // Check if a key exists console.log('Has user:123:name?', db.has('user:123:name')); // Delete a key db.delete('user:123:name'); console.log('User name after delete:', db.get('user:123:name')); // Fetch all data console.log('All data:', db.fetchAll()); // Example of backup (create a dummy backup file) db.backup('my_backup_file'); console.log('Backup initiated (check your file system for my_backup_file.json)'); // Caution: db.reset() will delete all data. // Uncomment to clear the database: // db.reset(); // console.log('Database reset. All data removed.');
Debug
Known issues
gotchapro.db performs file I/O operations synchronously. In long-running or high-traffic Node.js applications, extensive synchronous disk access can block the event loop, leading to performance degradation or unresponsiveness.
fix
For performance-critical applications, consider a database solution with asynchronous I/O or use pro.db for minimal, infrequent writes. Wrap calls in a worker thread if blocking I/O is unavoidable for heavy usage patterns.
affects: >=1.0.0
breakingThe `db.reset()` function permanently deletes all data from the database. There is no confirmation prompt or undo mechanism built into the function itself.
fix
Implement robust confirmation logic in your application code before invoking `db.reset()`. Ensure backups are performed regularly using `db.backup()`.
affects: >=1.0.0
gotchaThe package is primarily built for CommonJS (CJS) environments. Directly using ESM `import` statements without proper transpilation or Node.js module resolution configuration (`"type": "module"` with `"exports"` field) can lead to runtime errors.
fix
For Node.js projects, use `const db = require('pro.db');`. If you must use ESM, ensure your project is configured with `"type": "module"` in `package.json` and investigate specific interoperability solutions or use a bundler.
affects: >=1.0.0
gotchaError handling for file system operations (e.g., permission issues, disk full) is not explicitly demonstrated in the quickstart and may require manual `try...catch` blocks around `pro.db` calls if you need to gracefully handle such failures.
fix
Wrap `pro.db` operations in `try...catch` blocks to handle potential file system errors gracefully. For example, catching `EACCES` for permission denied errors.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use `require()` in an ECMAScript Module (ESM) context (e.g., in a file where `type: module` is set in `package.json` or imported via `import`). pro.db is primarily a CommonJS package.
fix
Change your project or file to use CommonJS (`const db = require('pro.db');`) or transpile your ESM code to CJS before running. Alternatively, if your Node.js version supports it, you might be able to use dynamic import `import('pro.db').then(db => { /* use db */ });`.
TypeError: db.set is not a function
This usually indicates that `db` did not correctly resolve to the `pro.db` module's exported object. This can happen if you tried `import db from 'pro.db'` in a CJS-only context without proper TypeScript/Babel setup, or if the module itself was malformed.
fix
Ensure you are using `const db = require('pro.db');` for Node.js CommonJS environments. If using TypeScript, check your `tsconfig.json` for `esModuleInterop` and `allowSyntheticDefaultImports` or provide a custom module declaration.
EACCES: permission denied, open 'database.json'
The Node.js process does not have sufficient read/write permissions for the directory where `pro.db` attempts to create or access its database file (typically `database.json` in the current working directory).
fix
Ensure the user running the Node.js application has read and write permissions to the directory where the database file is stored. You may need to change directory permissions (e.g., `chmod 777 your-data-directory`) or run the application with elevated privileges (use with caution).
Upgrade
Version history
3.0.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources