Registry / database / nodedb-helper

nodedb-helper

JSON →
library1.4.1jsnpmunverified

A lightweight MySQL query builder and connection manager for Node.js, current version 1.4.1. It optimizes MySQL connections for re-use and supports multiple databases in a single application. Reads environment variables to switch between development and production databases. Provides chainable methods like .select(), .insert(), .update(), .delete(). No ORM overhead; designed for simple SQL operations with parameterized queries. Limited documentation and community adoption. Not recommended for new projects due to lack of maintenance (last release 4+ years ago). Consider using mysql2 with promise wrapper or knex.js instead.

npm install nodedb-helper
INSTALL
IMPORT
SIG · NODEDB-HELPER
N
nodedb-helper
databasejavascriptv1.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default (initialized with options)
const db = require('nodedb-helper')({ user: 'my_db', product: 'my_other_db' });
const nodedb = require('nodedb-helper'); nodedb({ user: 'my_db' });
The module exports a factory function that must be called with a database names object. Does not support ES module imports (no ESM).
db.user() / db.product()
const db = require('nodedb-helper')({ user: 'my_db' }); const result = await db.user().select({ table: 'users', where: 'id=?', params: [1] });
db.user.select({ table: 'users' });
Each database name becomes a method that returns a chained query builder instance. Must be called as a function (db.user()) to get the builder.
builder.select() / builder.insert() / builder.update() / builder.delete()
await db.user().select({ table: 'users', where: 'id=?', params: [1], order: 'name ASC', limit: 10 });
db.user().select({ table: 'users', where: 'id=1' });
Parameters must be passed in an object with specific keys (table, where, params, fields, order, limit). For where clause, use ? placeholders and provide params array - never concatenate user input.
builder.query()
await db.user().query('SELECT * FROM users WHERE id = ?', [1]);
await db.user().query('SELECT * FROM users WHERE id=' + 1);
Direct query method for raw SQL; still requires parameterized queries to prevent SQL injection.

Initialize nodedb-helper with multiple databases and perform a parameterized SELECT query.

// .env NODE_ENV=development DEV_DB_URL=localhost DEV_DB_USERNAME=root DEV_DB_PASSWORD= PROD_DB_URL=prod.example.com PROD_DB_USERNAME=admin PROD_DB_PASSWORD=secret // database.js const db = require('nodedb-helper')({ user: 'my_user_db', product: 'my_product_db' }); module.exports = db; // product.js const db = require('./database.js'); async function getProduct(id) { const result = await db.product().select({ table: 'product_details', where: 'product_id=?', params: [id] }); return result; } getProduct(123).then(console.log).catch(console.error);
Debug
Known issues
brokenPackage is no longer maintained. Last release 4+ years ago. Known issues with newer Node versions and mysql2 driver.
fix
Migrate to active alternatives like knex.js or mysql2 with promise wrapper.
affects: >=1.4.1
broken.env variable names are case-sensitive and must exactly match documented names (DEV_DB_URL, DEV_DB_USERNAME, DEV_DB_PASSWORD, PROD_DB_URL, etc.). Missing variables cause silent connection failures.
fix
Ensure all required environment variables are set. Use dotenv and validate before calling the module.
affects: >=1.0.0
brokenThe module uses the deprecated 'mysql' package, which does not support modern authentication (caching_sha2_password) by default. New MySQL 8+ installations may fail to connect.
fix
Upgrade to mysql2 by modifying the package source, or use a different library. Alternatively, set MySQL to use mysql_native_password for the user.
affects: >=1.0.0
brokenNo TypeScript typings. The package exports a factory function that returns an object with method names matching database keys, which cannot be statically typed.
fix
Create custom type declarations or use @types/nodedb-helper if available (currently none).
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'nodedb-helper'
Package not installed or not installed locally (e.g., global install). Also check package.json for exact name with hyphens.
fix
Run 'npm install nodedb-helper' in your project directory.
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running on localhost:3306, or environment variable DEV_DB_URL overrides but connection details are wrong.
fix
Start MySQL service or set correct URL in .env. Default is localhost:3306.
TypeError: db.user is not a function
Calling the returned object's method without parentheses, treating it as a property instead of a method.
fix
Use parentheses: db.user().select(...) instead of db.user.select(...).
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Invalid username/password or no password but expecting one. The module reads DEV_DB_USERNAME and DEV_DB_PASSWORD from .env.
fix
Set DEV_DB_USERNAME and DEV_DB_PASSWORD in .env file correctly. For root with no password, set DEV_DB_PASSWORD= (empty).
Upgrade
Version history
1.4.1latest on npm
Audit
Dependencies
mysqlrequiredRequired to establish MySQL connections and execute queries.
Agent activity
5 hits · last 30 days
node
4
Resources
nodedb-helper — npm install nodedb-helper · libregistry