Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tuckerconnelly/minimal-router
Minimal Node.js router
https://github.com/tuckerconnelly/minimal-router
Last synced: 23 days ago
JSON representation
Minimal Node.js router
- Host: GitHub
- URL: https://github.com/tuckerconnelly/minimal-router
- Owner: tuckerconnelly
- License: mit
- Created: 2019-08-10T18:11:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T06:50:18.000Z (almost 2 years ago)
- Last Synced: 2024-11-14T01:09:52.748Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 776 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
***Early Version***
# minimal-router
Minimal Node.js router.
## Usage
```
npm i @tuckerconnelly/minimal-router
```Then where you define your HTTP server:
```js
const http = require('http');const minimalRouter = require('@tuckerconnelly/minimal-router');
http.createServer(
minimalRouter(`${__dirname}/routes`)((req, res) => {
res.statusCode = 404;
res.end('Not Found');
})
).listen(3000);
```Then in `routes/test-endpoint.js` add:
```js
// Optional, defaults to ['post']
exports.methods = ['get']
// Required
exports.default = (req, res) => res.end('OK');
```Then you can make calls to that route function:
```
> curl localhost:3000/test-endpointOK
```Any file in the passed folder with those exports will get picked up and routed to.
---
> Whatever you do, work at it with all your heart, as working for the Lord, not for human masters, since you know that you will receive an inheritance from the Lord as a reward.
*Colossians 3:23*