Registry / database / mysql-wait

mysql-wait

JSON →
library1.1.2jsnpmunverified

A promise-based utility to wait for a MySQL database to become available (version 1.1.2). It connects to the specified MySQL host and port, accepting user and password, and resolves once the connection succeeds, or rejects after a configurable timeout. Ideal for scripts that need to ensure the database is up before proceeding. Uses standard `mysql` package underneath. Minimal API: one function with an options object.

npm install mysql-wait
INSTALL
IMPORT
SIG · MYSQL-WAIT
M
mysql-wait
databasejavascriptv1.1.2
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 wait from 'mysql-wait'
const { wait } = require('mysql-wait')
Package uses CommonJS default export; named destructure does not work.
wait (as CommonJS require)
const wait = require('mysql-wait')
const { wait } = require('mysql-wait')
The module.exports is a function, not an object with a 'wait' property.
wait function call
wait({ host: 'localhost', port: 3306, user: 'root', password: 'secret', timeout: 30000 })
wait(['localhost', 3306, 'root', 'secret'])
Takes a single options object, not positional arguments.

Connects to a MySQL database and resolves when the database becomes available, or rejects after timeout.

import wait from 'mysql-wait'; const options = { host: process.env.MYSQL_HOST ?? 'localhost', port: parseInt(process.env.MYSQL_PORT ?? '3306'), user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', timeout: 60000 }; wait(options) .then(() => console.log('Database is up')) .catch(err => console.error('Database not available:', err));
Debug
Known issues
gotchaThe promise only rejects after the timeout; it does not immediately fail on connection refused.
fix
Set a reasonable timeout (default 60s) shorter if immediate feedback is needed.
affects: >=0.0.0
gotchaBad credentials cause rejection only after the timeout, not instantly.
fix
Ensure credentials are valid before using this tool; error message may not be specific.
affects: >=0.0.0
gotchaUses deprecated `mysql` package which is not recommended for production (use mysql2 instead).
fix
Consider migrating to a more modern MySQL wait utility built on mysql2.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: wait is not a function
Using named import ({ wait }) instead of default import or require.
fix
Correct: import wait from 'mysql-wait' or const wait = require('mysql-wait')
Error: ER_ACCESS_DENIED_ERROR: Access denied for user '...'@'...' (using password: NO)
Password not provided or empty string when MySQL requires one.
fix
Provide a valid password in options.password.
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running on the specified host/port.
fix
Start MySQL service or check host/port configuration.
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies
mysqlrequiredUnderlying MySQL driver used to test connection; runtime dependency.
Agent activity
4 hits · last 30 days
node
4
Resources
mysql-wait — npm install mysql-wait · libregistry