Registry / database / promise-mysql2

promise-mysql2

JSON →
library1.0.0jsnpmunverified

A promise wrapper for mysqljs/mysql, providing a simple way to interact with MySQL databases using Promises and async/await syntax. Version 1.0.0 is the latest stable release, with no active development indicated. It supports standard connection and pool creation, but not poolCluster. It is a lightweight alternative to more feature-rich ORMs like Sequelize or TypeORM, focusing on minimal abstraction over the underlying mysql driver.

npm install promise-mysql2
INSTALL
IMPORT
SIG · PROMISE-MYSQL2
P
promise-mysql2
databasejavascriptv1.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.

mysql
const mysql = require('promise-mysql2');
import mysql from 'promise-mysql2'; // Only supports CommonJS
This package is CJS-only; does not support ES modules or named imports.
createConnection
const conn = await mysql.createConnection(options);
const conn = await createConnection(options); // Not exported as named
createConnection is a method on the default export, not a named export.
createPool
const pool = mysql.createPool(options);
const pool = new mysql.Pool(options); // Pool constructor not exposed
Only available via createPool factory function.

Demonstrates connecting to MySQL, running a query, and closing the connection using async/await.

const mysql = require('promise-mysql2'); async function main() { const conn = await mysql.createConnection({ host: 'localhost', user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'test' }); const [rows, fields] = await conn.query('SELECT 1 + 1 AS solution'); console.log('The solution is:', rows[0].solution); conn.end(); } main().catch(console.error);
Debug
Known issues
breakingRequires node >= 8.0 (ES2017+ for async/await). Not compatible with older Node versions.
fix
Upgrade Node.js to version 8 or later.
affects: >=1.0.0
deprecatedThe underlying mysqljs/mysql library is in maintenance mode and may receive only critical security updates.
fix
Consider migrating to mysql2 or another actively maintained MySQL driver.
affects: >=1.0.0
gotchaMust call connection.end() to release the connection, otherwise the Node event loop will not exit.
fix
Always call conn.end() after queries, especially in scripts.
affects: >=1.0.0
gotchaPool.query() returns a promise that resolves to [rows, fields] directly, not a connection. Do not try to release it.
fix
Use pool.query() for one-off queries; use pool.getConnection() if you need a connection handle.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'promise-mysql2'
Package not installed or typo in package name.
fix
Run 'npm install promise-mysql2' and ensure the require path matches.
TypeError: mysql.createConnection is not a function
Incorrect import - using ES import syntax or destructuring.
fix
Use 'const mysql = require('promise-mysql2');' (CommonJS).
Error: Connection lost: The server closed the connection.
Connection timed out or was closed unexpectedly.
fix
Implement reconnection logic or increase wait_timeout on the MySQL server.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
mysqlrequiredPeer dependency - wraps mysqljs/mysql functions with promises
Agent activity
9 hits · last 30 days
node
6
Resources
promise-mysql2 — npm install promise-mysql2 · libregistry