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

More Node.js tasks

Back to the full Node.js Core Modules cheat sheet