Node.js Course
Node.js
/
Intermediate

HTTP Module

Definition

The foundational core module that allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP). It enables Node to act as either an HTTP Server (listening for requests) or an HTTP Client (making requests).

Explain Like I'm New

This is the beating heart of Node web servers. It is the raw machinery that listens to port 3000, receives incoming network requests from browsers, and sends HTML or JSON back. However, it is very low-level and bare-bones, which is why almost everyone uses the `Express.js` framework to wrap it and make it easier to use.

Real World Example

Creating a lightning-fast microservice with zero external dependencies to just return a JSON response.

Common Use Cases

  • •Building web servers from scratch
  • •Creating reverse proxies
  • •Low-level network interception

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What method is used to create a new server?

intermediate

  • What two objects are passed into the `createServer` callback function?

advanced

  • Why do people use Express instead of the built-in HTTP module?

Flash Cards

Question

What two objects are passed?

Click to reveal answer
Answer

`request` (req) and `response` (res). The Request contains info about the incoming user (URL, headers, body data). The Response is the object you use to send data back to the user.

Question

Why use Express instead?

Click to reveal answer
Answer

The raw HTTP module doesn't understand Routing (`/users` vs `/posts`), doesn't easily parse JSON bodies, and has no Middleware. Express adds all these features on top of the HTTP module automatically.