try-net-connect
I use this in my startup scripts executed in Docker containers so that I can wait for another container's server to be ready before starting the dependent server.
Install
npm install try-net-connect
Usage
const tryConnect =
tryConnect(options)
See node's net.connect parameters for connection options.
options: object
retry: number, 1000
ms to wait before retrying connectionretries: number, null (infinite)
number of retries
- returns:
eventEmitter
.on('connected', client => {})
.on('retry', reason => {})
.on('timeout', mainReason => {})
stop: function
stop retrying