THE WORLD'S LARGEST WEB DEVELOPER SITE

Node.js HTTP Server Object

❮ http.createServer()


Example

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!');
  res.end();
}).listen(8080);
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()