Tutorials References Exercises Videos Menu
Free Website Get Certified Upgrade

Node.js server.listen() Method

❮ HTTP Server


Create a server that listens on port 8080 of your computer.

When port 8080 get accessed, write "Hello World!" back as a response:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Hello World!');
Run example »

Definition and Usage

The server.listen() method creates a listener on the specified port or path.


server.listen(port, hostname, backlog, callback);

Parameter Values

Parameter Description
port Optional. Specifies the port we want to listen to
hostname Optional. Specifies the IP address we want to listen to
backlog Optional. Specifies the max length of the queue of pending connections. Default 511
callback Optional. Specifies a function to be executed when the listener has been added

Technical Details

Return Value: None
Node.js Version: 0.1.90

❮ HTTP Server