async-express-decorator

1.1.0 • Public • Published

Wrapper for express routers or app for transparent work with async controllers and error handling.

Usage:

const express = require("express")
const toAsyncRouter = require("async-express-decorator")
 
const router = toAsyncRouter(express.Router())
 
router.get('/some-route', someAsyncController)

and so on.

Thrown errors can be catched with standard express middleware.

By default decorator works for methods: get, post, put, delete. If you want extend or shrink this list, use toAsyncRouter.setMethods() before toAsyncRouter() call:

const express = require("express")
const toAsyncRouter = require("async-express-decorator")
 
toAsyncRouter.setMethods(['get', 'post', 'all'])
 
const router = toAsyncRouter(express.Router())
 
router.all('/some-route', someAsyncController)

It is also possible to get a list of methods that will be decorated:

console.log(toAsyncRouter.getMethods())

Package Sidebar

Install

npm i async-express-decorator

Weekly Downloads

141

Version

1.1.0

License

MIT

Unpacked Size

2.22 kB

Total Files

3

Last publish

Collaborators

  • m.dezhurko