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);
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.
fixRun '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.
fixStart 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.
fixUse 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.
fixSet DEV_DB_USERNAME and DEV_DB_PASSWORD in .env file correctly. For root with no password, set DEV_DB_PASSWORD= (empty).
Audit
Dependencies
mysqlrequiredRequired to establish MySQL connections and execute queries.