THE WORLD'S LARGEST WEB DEVELOPER SITE

Node.js server.listening Property

❮ HTTP Server


Example

Check if the server is listening for connections or not:

var http = require('http');
var srvr = http.createServer(function (req, res) {
  res.write('Hello World!');
  res.end();
});
srvr.listen(8080);
console.log(srvr.listening);
srvr.close();
console.log(srvr.listening);
Run example »

Definition and Usage

The server.listening property returns true if the server is currently listening for connections, otherwise false.


Syntax

server.listening;

Technical Details

Return Value: Bolean value indicating if the server is listening for connections or not
Node.js Version: 5.7.0

❮ HTTP Server