1. Import createServer
createServer comes from the built-in node:http module; no package install is needed.
import { createServer } from "node:http"Typorithm · easy
Step 1 of 8 · intro card
HTTP & Events
createServer from node:http builds an HTTP server from a handler. The handler gets a request (req) and a response (res); you set headers with res.writeHead and send the body with res.end, then server.listen binds a port.
node:http is built in: createServer returns a server whose handler runs once per request, receiving the incoming req and the outgoing res.
req carries the method, url, and headers of the request; res is how you reply — writeHead sets the status and headers, and end sends the body.
Nothing reaches the client until you call res.end; server.listen(3000) then binds the port so the server starts accepting connections.
createServer takes a (req, res) handler.
res.writeHead sets status code and headers.
res.end sends the body and closes the response.
import { createServer } from "node:http"
const server = createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" })
res.end("Hello")
})
server.listen(3000)Connect each part of the code to the concept before you type.
createServer comes from the built-in node:http module; no package install is needed.
import { createServer } from "node:http"createServer takes a handler that runs on every incoming request, receiving the request and response objects.
const server = createServer((req, res) => {writeHead sends the status code and response headers before any body is written.
res.writeHead(200, { "Content-Type": "text/plain" })res.end writes the final body chunk and closes the response so the client receives it.
res.end("Hello")listen binds the server to port 3000 and starts accepting connections.
server.listen(3000)Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.