server-ready
Know when a server is ready to receive requests. Used in hotel.
See server-ready-cli for the command-line tool.
Install
npm install server-ready --save
Example
var serverReady = require('server-ready')
var port = 3000
// A server process is spawned here or somewhere else...
serverReady(port, function (err) {
if (err) return console.error('timeout, can\'t connect to port')
console.log('port is open or has just opened')
})
How it works?
server-ready
will try to connect every 250ms
to the specified port
until a connection has been made or timeout has been reached (20s
by default).
API
serverReady.timeout
Default timeout.
serverReady(port[, host][, timeout], cb)
Tries to connect to port
.
License
MIT - Typicode