Skip to content

yash3492/rest-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rest-server


Usage

  • 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();

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published