Our HTTP server in detail

Let's break down our HTTP server code to see what's really going on. First, we require the http package so we can access the HTTP module's methods:

const http = require('http');

Next, we use the createServer method to create a server instance that listens to incoming requests. Inside it, we pass in a request handler function that takes a req and res parameters.

Most developers use req and res as shorthands for "request" and "response" parameter names, but you can use any variable names you like.

The req parameter is an object containing information about the request, such as its origin IP, URL, protocol, body payload (if any), and so on. The res object provides methods that help you prepare the response message to ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.