http Module

noun

say it: “AYCH-tee-tee-PEE MOJ-ool” /ˌeɪtʃˌtiˌtiˈpi ˈmɑdʒul/

Node's built-in module for making web servers and sending web requests, with no package to install.

What is the http module in Node?

The http module comes with Node and makes web servers. http.createServer takes a function that runs for every request and writes the answer; listen picks the port the server waits on.

import http from "node:http";

const server = http.createServer((req, res) => {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end("Today's special: tomato soup, $6");
});
server.listen(3000); // open http://localhost:3000

In a sentence

  • “The http module hands every request to one function, so that function has to check the URL itself.”
  • “Before reaching for Express, Ana built a tiny menu server with Node's http module.”

Level: Apprentice · More Node.js terms at this level

Updated