Node.js Server

A Node server turns runtime skills into a real service. Start with the core HTTP module before adding a framework.

HTTP module

import http from "node:http";

const server = http.createServer((req, res) => {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end("Hello from Node");
});

Routes

Keep routing explicit. A small route table is easier to debug than implicit control flow.

Response design

  • Set status codes intentionally.
  • Return a clear content type.
  • Keep error messages useful but safe.

Practice

  1. Create one server that answers two paths.
  2. Return a different status code for unknown paths.
  3. Record one reason to avoid business logic inside the request handler.