Skip to content

A minimal HTTP server built from scratch in TypeScript using raw TCP sockets. Demonstrates HTTP parsing, response serialization, simple routing, and connection management without frameworks.

Notifications You must be signed in to change notification settings

codetheworld-io/simple-web-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple HTTP Server in TypeScript (From Scratch)

A minimal HTTP server built directly on top of TCP using Node.js and TypeScript.
This project is designed to demonstrate how HTTP works under the hood — without using http, Express, or any web framework.

Features

  • Raw TCP server using Node.js net module
  • Manual HTTP request parsing
  • Manual HTTP response serialization
  • Simple built-in router
  • Keep-alive support via a custom ConnectionManager
  • Clean, readable, educational code

Why This Project?

Most web developers use frameworks that hide the complexity of HTTP.
This project exists to demystify HTTP by showing:

  • What an HTTP request really looks like
  • How responses are constructed
  • How connections are managed
  • How servers handle multiple requests per connection

It’s intended for learning, experimentation, and deeper understanding — not production use.

Project Structure

simple-http-server/
├── src/
│ └── server.ts # Full TCP-based HTTP server implementation
├── package.json
├── tsconfig.json
└── README.md

Getting Started

Prerequisites

  • Node.js 18+
  • npm

Install dependencies

npm install

Run the server (development)

npm run dev

The server will start on:

tcp://localhost:3000

Testing the Server

You can test the server using curl:

# Root route
curl http://localhost:3000/

# Health check
curl http://localhost:3000/health

# Echo endpoint
curl -X POST http://localhost:3000/echo -d "Hello server"

Key Concepts Covered

  • TCP sockets and network I/O
  • HTTP request / response structure
  • Buffers vs strings
  • Event-driven architecture in Node.js
  • Connection keep-alive logic
  • Simple routing without frameworks

Possible Extensions

  • Proper Content-Length body parsing
  • Query string parsing
  • Respect Connection: close header
  • Request timeout handling
  • HTTP/1.1 edge cases
  • Logging and metrics

Related Article

This repository accompanies a Medium article explaining the concepts step by step:

Demystifying HTTP: Building a Simple Web Server in TypeScript From Scratch

Disclaimer

This project is for educational purposes only. It is not production-ready and should not be exposed to the public internet.

License

MIT License

About

A minimal HTTP server built from scratch in TypeScript using raw TCP sockets. Demonstrates HTTP parsing, response serialization, simple routing, and connection management without frameworks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors