- Install package
npm install @yash3492/rest-server
- Create an
.env
file with configs. (list below) - Require
const {loadConfig, RestServer} = require('@yash3492/rest-server');
- Creating instance
// Load configs or create custom object
const config = loadConfig();
// Create a server instance
const server = new RestServer(config);
// Load all middle-wares required for rest API development
server.pre();
// router group
let router = server.router();
// bind some routes
router.get('/two', (req, res) => {
res.send({
now: (Date.now()),
two: true
})
});
// binding any router
// or middleware
server.use(router);
// bind 404, exception handling, terminating middle-ware and start listening.
server.post().terminating().listen();
BODY_SIZE_LIMIT
, Default: '100kb'DEFAULT_ERROR_MESSAGE
, Default: 'Internal Server Error'logger
, Default: consoleingestException
,Default: () => {}
PORT
, Default: 4000
- Correlation id logging on exception.
- Helmet initialized by default.
- Compression & JSON Body parsing.
- CORS enabled.
- Support for overriding logger.
- Support for injecting Custom Exception handler.