kuaisu-router

1.0.2 • Public • Published

kuaisu-router

kuaisu-router is a lightweight Node.js HTTP/HTTPS router like express. It allows you to define routes and bind them to HTTP methods, and provides middleware functionality for additional processing of incoming requests.

Usage

Here's an example of how to use kuaisu-router:

const Router = require('kuaisu-router');

const router = new Router();

router.get('/', (req, res) => {
  res.end('Hello, world!');
});

router.post('/users', (req, res) => {
  res.end('Created new user.');
});

router.use((req, res) => {
  res.statusCode = 404;
  res.end('Not found.');
});

router.listen(3000, () => {
  console.log('Server is running on port 3000.');
});

API

const router = new Router();

Creates a new Router instance. Accepts an optional options object with the following properties:

  • ssl: An object containing SSL certificate options. If this property is present, the router will create an HTTPS server instead of an HTTP server.

  • staticDirs: An array of directories to serve static files from.

router.get(path, handler)

Defines a route that responds to GET requests with the specified handler function.

router.post(path, handler)

Defines a route that responds to POST requests with the specified handler function.

router.put(path, handler)

Defines a route that responds to PUT requests with the specified handler function.

router.delete(path, handler)

Defines a route that responds to DELETE requests with the specified handler function.

router.use(middleware)

Registers a middleware function to be executed for every incoming request.

router.useStatic(dir)

Registers a directory to serve static files from. (Not Working)

router.listen(port[, hostname][, backlog][, callback])

Starts the server and begins listening for incoming requests on the specified port and hostname. Accepts an optional backlog argument and a callback function to be called when the server starts listening.

DISCLAIMER

You could test this however you like, but this is NOT as fast as express. This is just for you guys to give feedback to improve this on the reddit community: https://www.reddit.com/r/kuaisu/. This is only the testing phase of the project. Please post feedback on the reddit site.

Links

My YT Channel (Valorant Content) - https://www.youtube.com/channel/UCENdaNH9n58AOUho732i_6g

Readme

Keywords

none

Package Sidebar

Install

npm i kuaisu-router

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

72.3 kB

Total Files

16

Last publish

Collaborators

  • flixhype