@rajsinghudr/restserver
v1.0.1
Published
Rest server based on express
Downloads
2
Readme
rest-server
Usage
- Install package
npm install @rajsinghudr/restserver
- Create an
.env
file with configs. (list below) - Require
const {loadConfig, RestServer} = require('@rajsinghudr/restserver');
- 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();
Supported config variables
BODY_SIZE_LIMIT
, Default: '100kb'DEFAULT_ERROR_MESSAGE
, Default: 'Internal Server Error'logger
, Default: consoleingestException
,Default: () => {}
PORT
, Default: 4000
Silent features
- 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.