Learn/Glossary/Web Server
Infrastructure

Web Server

A web server is a program that listens on a network port, processes incoming HTTP request packets, and returns response bytes.

Diagram

  Client (Browser)                  Web Server (api.myapp.com)
  ─────────────────                 ─────────────────────────
  │ GET /index.html│ ─────────────▶  │ Listening on Port 443   │
  │                 │ ◀─────────────  │ Reads file from disk    │
  └─────────────────    200 OK HTML   └─────────────────────────

In Depth

A web server is an application process running on a host machine that opens a specific network port (like 80 for HTTP or 443 for HTTPS) and listens for incoming TCP client connections to process and return data.

Code Example

Barebones HTTP server in Node.js

import http from 'http';

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello from Web Server!');
});

server.listen(3000, () => {
  console.log('Server listening on port 3000');
});

Related Terms