Node.js HTTP Module
THE WORLD'S LARGEST WEB DEVELOPER SITE

Node.js HTTP Module

❮ Built-in Modules


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 module provides a way of making Node.js transfer data over HTTP (Hyper Text Transfer Protocol).


Syntax

The syntax for including the HTTP module in your application:

var http = require('http');

HTTP Properties and Methods

Method Description
createClient() Deprecated. Creates a HTTP client
createServer() Creates an HTTP server
get() Sets the method to GET, and returns an object containing the user's request
globalAgent Returns the HTTP Agent
request() Returns an object containing the user's request

❮ Built-in Modules