Registry / database / nodejs-mysql

nodejs-mysql

JSON →
library0.1.3jsnpmunverified

A Promise-based wrapper around the mysql driver for Node.js. Version 0.1.3, last published in 2017. Provides a simple API for MySQL operations including querying, inserts, updates, deletes, and transactions. Unlike raw mysql package, it returns Promises and manages connection pooling. Development is sporadic with no recent releases.

npm install nodejs-mysql
INSTALL
IMPORT
SIG · NODEJS-MYSQL
N
nodejs-mysql
databasejavascriptv0.1.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
import mysql from 'nodejs-mysql'
const mysql = require('nodejs-mysql')
CommonJS users must use require('nodejs-mysql').default
default
const mysql = require('nodejs-mysql').default
const mysql = require('nodejs-mysql')
In CommonJS, default export is under .default
mysql.getInstance
const db = mysql.getInstance(config)
mysql.getInstance(config)
getInstance is the main entry to create a database instance

Shows how to create a database instance and execute a simple SELECT query with promises.

import mysql from 'nodejs-mysql'; const config = { host: 'localhost', port: 3306, user: 'root', password: 'password', database: 'test' }; const db = mysql.getInstance(config); db.exec('SELECT 1 + 1 AS solution') .then(rows => { console.log('The solution is:', rows[0].solution); }) .catch(err => { console.error('Error executing query:', err); });
Debug
Known issues
breakingImporting with `require('nodejs-mysql')` returns an object with a `default` property. You must use `require('nodejs-mysql').default`.
fix
Use `const mysql = require('nodejs-mysql').default;`
affects: >=0.1.0
deprecatedPackage has not been updated since 2017 and uses an outdated version of the mysql driver. Consider using mysql2 with direct promises.
fix
Migrate to mysql2 and use its built-in promise support: `import mysql from 'mysql2/promise';`
affects: >=0.0.0
gotchaConfig must be an object for single connection or an array of objects for connection pool. Passing an empty array will cause errors.
fix
Ensure config is either a single object or a non-empty array of objects.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: mysql.getInstance is not a function
Importing the module incorrectly via require without .default.
fix
Use `const mysql = require('nodejs-mysql').default;`
Error: Cannot find module 'mysql'
Missing the required peer dependency 'mysql'.
fix
Run `npm install mysql` to install the mysql driver.
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies
mysqlrequiredCore MySQL driver that nodejs-mysql wraps
Agent activity
5 hits · last 30 days
node
4
Resources
nodejs-mysql — npm install nodejs-mysql · libregistry