{"id":16665,"library":"pro.db","title":"Pro.db","description":"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.","status":"active","version":"3.0.8","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","db","database","json","sql","sqlite","m7md"],"install":[{"cmd":"npm install pro.db","lang":"bash","label":"npm"},{"cmd":"yarn add pro.db","lang":"bash","label":"yarn"},{"cmd":"pnpm add pro.db","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import db from 'pro.db';","symbol":"db","correct":"const db = require('pro.db');"},{"note":"While the main export is an object with methods, destructuring is possible for convenience, though less common than importing the whole object.","wrong":"const db = require('pro.db').db;","symbol":"db (individual functions)","correct":"const { set, get } = require('pro.db');"},{"note":"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';`.","wrong":"import * as db from 'pro.db';","symbol":"Pro.db in TypeScript","correct":"import db from 'pro.db';"}],"quickstart":{"code":"const db = require('pro.db');\nconst path = require('path');\nconst fs = require('fs');\n\nconst dbFilePath = path.join(__dirname, 'database.json');\n// Ensure the database file exists or is created before operations\nif (!fs.existsSync(dbFilePath)) {\n  fs.writeFileSync(dbFilePath, '{}', 'utf8');\n}\n\n// Set a value\ndb.set('user:123:name', 'Alice');\ndb.set('user:123:age', 30);\ndb.set('products', [{ id: 1, name: 'Laptop' }, { id: 2, name: 'Mouse' }]);\n\nconsole.log('User name:', db.get('user:123:name'));\nconsole.log('Products:', db.get('products'));\n\n// Add to a numeric key\ndb.add('user:123:age', 5);\nconsole.log('New age:', db.get('user:123:age'));\n\n// Push to an array key\ndb.push('products', { id: 3, name: 'Keyboard' });\nconsole.log('Updated products:', db.get('products'));\n\n// Check if a key exists\nconsole.log('Has user:123:name?', db.has('user:123:name'));\n\n// Delete a key\ndb.delete('user:123:name');\nconsole.log('User name after delete:', db.get('user:123:name'));\n\n// Fetch all data\nconsole.log('All data:', db.fetchAll());\n\n// Example of backup (create a dummy backup file)\ndb.backup('my_backup_file');\nconsole.log('Backup initiated (check your file system for my_backup_file.json)');\n\n// Caution: db.reset() will delete all data.\n// Uncomment to clear the database:\n// db.reset();\n// console.log('Database reset. All data removed.');","lang":"javascript","description":"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."},"warnings":[{"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.","message":"pro.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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Implement robust confirmation logic in your application code before invoking `db.reset()`. Ensure backups are performed regularly using `db.backup()`.","message":"The `db.reset()` function permanently deletes all data from the database. There is no confirmation prompt or undo mechanism built into the function itself.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Wrap `pro.db` operations in `try...catch` blocks to handle potential file system errors gracefully. For example, catching `EACCES` for permission denied errors.","message":"Error 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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 */ });`.","cause":"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.","error":"ReferenceError: require is not defined in ES module scope"},{"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.","cause":"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.","error":"TypeError: db.set is not a function"},{"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).","cause":"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).","error":"EACCES: permission denied, open 'database.json'"}],"ecosystem":"npm"}