lighteral
v1.0.2
Published
This is a library which you can use to define your routes as template literals. It uses express underneath.
Downloads
1
Readme
lighteral
This is a library which you can use to define your routes as template literals. It uses express underneath.
Install
npm i lighteral
Use
const { Server, Router } = require('lighteral');
const router = new Router();
const sendHello = (req, res) => {
res.end('hello');
};
router.get`
/
${sendHello}
`;
const server = new Server({ routers: [router] });
server.listen(3000, () => {
console.log(`http://127.0.0.1:3000`);
});
You can also define a prefix for the routes per router:
const { Server, Router } = require('lighteral');
const router = new Router('/api');
...
Currently the following methods are supported: use, get, post, put, patch, delete, options, all.
Note: express middleware should work, e.g. cors:
const { Server, Router } = require('lighteral');
const cors = require('cors');
const router = new Router('/api');
router.post`
/contacts
${cors()}
${(req, res, next) => res.end('hello')}
`
...