Skip to content

greatm3/HTTP-from-scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP-from-scratch

A barebones HTTP/1.1 server built only with raw TCP sockets (net module), implemented my own routing system No frameworks used.

usage

$ git clone https://github.com/greatm3/HTTP-from-scratch

$ cd HTTP-from-scratch

# Install dependencies
npm install

# compiles the typescript to js, creates a dist/ directory
npm run build

Usage

import HTTPServer from "./dist/HttpServer.js";

const server = new HTTPServer() 

server.makeServer((req, res) => {
    res.setHeader("Content-Type", "text/html")
    res.write("<h1>Hello</h1>")
})
 

server.listen(3971, () => {
    console.log("Started at 127.0.0.1:3971")
})
  • open your browser and go to http://127.0.0.1:3971
// HTTP server class inherits from EventEmitter class, so on recieving data, the instance emits a request message

server.on("request", (req, res) => {
    // knock yourself out.
})

TODOs

  • Basic HTTP request parsing
  • GET method routing
  • Response object with status/headers
  • POST method with body parsing
  • Query parsing

DISCLAIMER

  • This project is for learning purposes. Not intended for production use, see LICENSE.

About

A barebones HTTP/1.1 server built only with raw TCP sockets Node.js net module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •