@aaronburt/bunhost

2.0.0 • Public • Published

Router

This is a simple router for creating dynamic and static routes in a TypeScript Node.js application using NodeNext

Features Create dynamic routes for HTTP methods: GET, POST, PUT, DELETE Create static routes for serving files Uses mime library to set the correct Content-Type header for static files Usage Setting up the router Create an instance of the Router class:

import Router from './router';
const router = new Router();

Creating dynamic routes

Use the get, post, put, and delete methods to create dynamic routes:

router.get('/users', (request: Request) => {
  // handle GET request to '/users' route
  return new Response('Success');
});

router.post('/users', (request: Request) => {
  // handle POST request to '/users' route
  return new Response('Success');
});

Creating static routes

Use the addStatic method to create a static route for serving a file:

router.addStatic('/images/fileName', './images/fileName');

This will create a route that serves the file located at ./images/fileName when a request is made to /images/:fileName.

Use the listen method to start the server:

router.listen(3000);

This will start the server on port 3000.

Readme

Keywords

Package Sidebar

Install

npm i @aaronburt/bunhost

Weekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

6.09 kB

Total Files

6

Last publish

Collaborators

  • aaronburt