Registry / database / mysql-promise

mysql-promise

JSON →
library5.0.0jsnpmunverified

mysql-promise is a small wrapper version 5.0.0 for the mysql and mysql2 Node.js drivers that returns promises instead of callbacks. It provides a simple API with query, configure, and support for multiple database connections. Unlike alternatives like mysql2/promise, it wraps the legacy mysql package and allows using any promise implementation. Release cadence is low; last release was 2019.

npm install mysql-promise
INSTALL
IMPORT
SIG · MYSQL-PROMISE
M
mysql-promise
databasejavascriptv5.0.0
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
const db = require('mysql-promise')();
The module exports a factory function, not a constructor or singleton. Must call it as a function.
default
import db from 'mysql-promise'; const instance = db();
import db from 'mysql-promise';
ESM import works but note that db is a factory function, not a connection instance.
default
const db = require('mysql-promise')(); db.query(...)
const db = require('mysql-promise'); db.query(...)
CommonJS must invoke the factory: require('mysql-promise')()

Shows how to create a connection, run a query with promise, and handle results.

const db = require('mysql-promise')(); db.configure({ host: 'localhost', user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'test' }); db.query('SELECT 1 + 1 AS solution') .then(([rows]) => console.log(rows[0].solution)) .catch(err => console.error(err));
Debug
Known issues
breakingDeprecated: use mysql2/promise or other modern libraries instead
fix
Consider migrating to mysql2/promise which has native promise support.
affects: >=5.0.0
deprecatedThe .spread() method used in examples is not standard Promise; it's from Bluebird.
fix
If not using Bluebird, use .then() with destructuring or handle rows differently.
affects: >=3.0.0
gotchaThe module uses Bluebird promises internally; .spread() and .bind() are not native.
fix
Either use Bluebird globally or replace .spread() with .then(([rows]) => ...).
affects: >=4.0.0
gotchaMissing dependency: mysql or mysql2 must be installed separately.
fix
Run: npm install mysql or npm install mysql2
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: db.query is not a function
Calling require('mysql-promise') without invoking the factory.
fix
Correct: const db = require('mysql-promise')();
Error: Cannot find module 'mysql'
Peer dependency mysql is not installed.
fix
Run: npm install mysql
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
mysqloptionalPeer dependency for MySQL driver
mysql2optionalAlternative peer dependency
Agent activity
4 hits · last 30 days
node
4
Resources
mysql-promise — npm install mysql-promise · libregistry