Welcome to the most ✨extra✨ HTTP/1.1 server you never knew you needed: coded in TypeScript, powered by raw TCP sockets. No http module, no frameworks, just bare metal Node.js and vibes.
Built for modern browsers. RFC 9110 compliant (fr, no clickbait). Handles streaming, downloads, compression, and caching like a champ.
- RFC 9110 Compliant (followed for most things though liberal in some functionalities)
- Backpressure Producer-Consumer: Promise-based I/O naturally enforces backpressure, much like blocking I/O in other languages but without actually blocking, as Node.js doesn’t support true blocking I/O. So the callback based async read, write functions of the net module are converted to promise based read/write: clean af!
- Static file server: HTML, CSS, JS, videos, images all MIME-typed up
- Range request support: Yup, even multipart downloads
- Gzip compression: Only when it makes sense
- Streaming support: Custom generators, live responses
- Proper error handling: No more mystery 500s for the most part :)
- Built with security in mind
- Caching & ETag support: Because bandwidth ain't free
TCPConn: A neat async wrapper aroundnet.SocketTCPListener: Connection acceptor built onnet.createServer
- Custom
DynBuffor smooth byte stream slicing and dicing
Taking a page from C’s manual memory management playbook, the resources, namely open file descriptors, are gracefully handled to prevent memory leaks. Garbage collector ain't gonna close open file sockets :(
- Clear ownership: Sockets and files have well-defined lifetimes and a single owner at a time.
- Ownership transfer: Once an fd is passed to a handler, it’s their problem now (no double frees, no leaks).
- Graceful failure: Even in bad requests or client drop-offs, the cleanup logic kicks in like a bro.
- Parses request line, headers, body with strict validation.
- Handles chunked encoding & malformed input like a pro.
/:home.html/echo: echoes back whatever you throw at it/files/:filename: secure static file serving/sheep: async streaming viacountSheep(), just for fun 🐑
- Builds full HTTP responses with proper headers
- Supports chunked transfer and streaming content
- Applies Gzip if
Accept-Encodingallows and the content is worth it
- Safe path handling
- Full Range request support (single + multi)
- ETag generation & validation
If-None-Match,If-Rangesupport
✅ Chrome
✅ Firefox
✅ Safari
✅ cURL
✅ Netcat
✅ AI generated test code
Just clone the repo and the run the following command inside the directory:
npx tsc
node dst/index.js
You can use your browser to test it at: localhost/8080 or use netcat or curl(super useful)
The server is deployed on Raspberry Pi 4B, have a look: Deployed Server
Made with 🧠, patience, and way too much caffine. And obviously with the help of these kind souls:
https://dev.to/osmanmrtacar/simple-http-server-using-nodejs-net-module-5aoa
Build Your Own Web Server From Scratch In Node.JS by James Smith - for all the theory and design considerations