When using an instance http.createServer
, a function is available for the server instance address()
. This indicates whether the server is really listening and available.
Until it is called listen()
on the server instance address()
, it is returned null
because the instance itself does not yet have the address that it is listening on.
Once listen()
called, address()
will return the object.
Example
var http = require('http');
var server = http.createServer();
console.log(server.address());
server.listen(3000, 'localhost', function() {
console.log('listening');
});
console.log(server.address());
Summary
If server.address()
- null
, your instance is not running.
If the server.address()
object returns, your instance is working.
peteb source
share