Skip to content

KArjmand/simple-http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple HTTP Server

A simple HTTP server implementation using TypeScript.

Features

  • Routing for GET and POST requests
  • Middleware support
  • Error handling
  • Promise-based body parsing

Usage

  1. Install dependencies:
npm install 
  1. Run the server:
npm run start 

The server will start listening on http://localhost:3000.

  1. Use the server:
import App from './App';

const app = new App();

app.get('/', (req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, World!');
});

app.post('/users', (req, res) => {
  // Handle POST request to /users
  res.statusCode = 201;
  res.setHeader('Content-Type', 'application/json');
  res.end(JSON.stringify({ id: 1, name: 'John Doe' }));
});

app.listen(3000);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published