Registry / database / express-mysql-pool

express-mysql-pool

JSON →
library1.0.3jsnpmunverified

Express middleware that provides MySQL connection pooling, automatically attaching a connection to each request and releasing it on response end. Version 1.0.3 (latest, no recent updates). Simple wrapper around mysql module's pool; focuses on request-scoped connections. Alternatives: express-mysql-connection (individual connections), mysql2/promise pool (modern).

npm install express-mysql-pool
INSTALL
IMPORT
SIG · EXPRESS-MYSQL-POOL
E
express-mysql-pool
databasejavascriptv1.0.3
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 (function)
import myConn from 'express-mysql-pool'
const myConn = require('express-mysql-pool')
Package is CommonJS; use require or default import with ESM interop.
default (require)
const myConn = require('express-mysql-pool')
const myConn = require('express-mysql-pool').default
In CommonJS, require returns the function directly, not an object with default property.
request.getConnection
req.getConnection(function(err, conn) { ... })
req.getConnection().then(conn => ...)
getConnection is callback-based, not Promise-based. No promise version available.

Sets up Express middleware to attach MySQL pool connection to each request, queries a table, returns JSON.

var mysql = require('mysql'); var myConn = require('express-mysql-pool'); var express = require('express'); var app = express(); var dbOptions = { host: 'localhost', user: process.env.DB_USER || 'root', password: process.env.DB_PASS || '', database: 'test' }; app.use(myConn(mysql, dbOptions)); app.get('/api/foods', function(req, res, next) { req.getConnection(function(err, conn) { if(err) return next(err); conn.query('SELECT * FROM food', function(err, results) { if(err) return next(err); res.json(results); }); }); }); app.listen(3000);
Debug
Known issues
breakingUses old callback style. No Promise or async/await support.
fix
Wrap req.getConnection and conn.query in util.promisify or use mysql2/promise.
affects: >=0.0.0
gotchaRequires mysql module as first argument; passing wrong module (e.g., mysql2) may not work correctly.
fix
Ensure you use the 'mysql' package (not mysql2) unless compatibility is confirmed.
affects: >=0.0.0
deprecatedThe 'mysql' package itself is in maintenance mode; consider migrating to mysql2.
fix
Switch to mysql2 for modern features and security updates.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: req.getConnection is not a function
Middleware not applied correctly or not applied to the route path.
fix
Ensure app.use(myConn(mysql, dbOptions)) is called before routes that use req.getConnection.
Error: Cannot enqueue Query after executing a query
Trying to use the same connection for multiple parallel queries without releasing.
fix
Use separate connections for parallel queries or chain them with callbacks.
Error: Pool is closed
MySQL server went down or pool was manually ended.
fix
Restart MySQL server or reinitialize middleware.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
mysqlrequiredpeer dependency; the module requires mysql to create pool and queries
Agent activity
9 hits · last 30 days
node
8
Resources
express-mysql-pool — npm install express-mysql-pool · libregistry