Skip to main content

Core NodeJS

HTTP Module

The HTTP core module is a key module in Node used for networking.

import http from 'http'

You can also use frameworks build on top of it like express and fastify. These frameworks are built on top of Node's core HTTP module.


The HTTP module provides 5 classes:

  • http.Agent: A global instance of the http.Agent class is created to
    1. Efficiently manage a connection's persistance
    2. Reuse a single socket connection for HTTP clients
    3. Maintain a pool of sockets
    4. Ensure every request to the server is queued
  • http.ClientRequest: Node creates this object when we make a request using methods like http.request() or http.get(). The http.ClientRequest object creates a http.IncomingMessage object when listening to the response event.
  • http.Server
  • http.ServerResponse
  • http.IncomingMessage