http Module (Node.js)
http is Node.js's built-in module for creating web servers and making HTTP requests, with no dependencies. http.createServer() starts a server that handles incoming requests with (req, res) callbacks.
Node.js
The http module is the low-level foundation of web serving in Node. http.createServer((req, res) => {...}) creates a server; the callback runs for each request, receiving an IncomingMessage (req) for the request and a ServerResponse (res) you write the reply to, then you call server.listen(port).
You handle responses manually here: set the status with res.statusCode, headers with res.setHeader(), and body with res.write()/res.end(). The req object is a readable stream, so reading a request body means collecting its 'data' chunks — which is why higher-level frameworks exist.
Most real apps use Express or another framework rather than http directly, because routing, body parsing, and middleware are tedious to build by hand. But Express is built on top of http, so understanding this module clarifies what frameworks do for you. http also provides http.request/http.get for making outbound requests.
Syntax
http.createServer((req, res) => {...}).listen(3000)Examples
JavaScript
const http = require("http");
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello from Node");
});
server.listen(3000, () => console.log("on :3000"));