Loading Depth Study
Preparing your workspace
Node.js provides the http module for creating servers that receive requests and send responses.
An HTTP server listens on a port and handles incoming requests. The request contains information such as the method, URL, headers, and sometimes a request body. The response contains a status code, headers, and response content. Understanding this low-level server model makes frameworks such as Express easier to understand because they build convenient abstractions around the same HTTP concepts.
A simple Node.js server can return a health check response that tells monitoring systems whether the application is running.
import { createServer } from 'node:http';
const server = createServer((request, response) => {
response.writeHead(200, { 'Content-Type': 'application/json' });
response.end(JSON.stringify({ message: 'API is running' }));
});
server.listen(3000, () => {
console.log('Server running on port 3000');
});A server starts on port 3000 and returns a JSON message for incoming requests.