HTTP Server in Node.js
From the Node.js Core Modules cheat sheet ยท HTTP & HTTPS ยท verified Jul 2026
HTTP Server
Create HTTP servers to handle web requests
javascript
const http = require('http');
// Create server
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World');
});
server.listen(3000, () => {
console.log('Server running on port 3000');
});๐ข Essential - Foundation of web servers in Node.js
๐ก Use Express.js for production applications
๐ Server emits events: request, connection, close
โก Use cluster module for multi-core utilization
โ ๏ธ Handle server errors to prevent crashes
๐ Related: https module for SSL/TLS