Tutorials References Exercises Videos Menu
Website Get Certified Pro NEW

Node.js HTTP Server Object

❮ http.createServer()


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 HTTP Server object makes your computer behave as an HTTP server.

HTTP Server Methods and Properties

close() Closes the server connection
listen() Makes the server listen to ports on the computer
listening Returns true if the server is listening for connection, otherwise false
maxHeadersCount Limits the number of incoming headers
setTimeout() Sets the server's timeout value. Default is 2 minutes
timeout Sets, or gets, the server's timeout value

❮ http.createServer()