@rajsinghudr/restserver

1.0.1 • Public • Published

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: console
  • ingestException, 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.

Readme

Keywords

Package Sidebar

Install

npm i @rajsinghudr/restserver

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

7.61 kB

Total Files

6

Last publish

Collaborators

  • rajsinghudr