0.1.5 • Published 3 years ago

express-asyncable v0.1.5

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

express-asyncable

Wraps async/await Express middlewares. Catches error and passes it to next.
Avoid wrinting try/catch in your middlewares.

Build Status npm version

Why?

DRY when catching errors from asyn/await Express middlewares.

This module exposes a wrapper for param middleware as well, which is using a different signature (req, res, next, value).

API

.middleware(function)

Where function returns a promise and accepts req, res, next arguments.

.paramMiddleware(function)

Where function returns a promise and accepts req, res, next and value arguments.

Usage example

import { middleware, paramMiddleware } from "asyncable"
// const { middleware, paramMiddleware } = require('asyncable')
// ...

router.param('userId', paramMiddleware(model.findObject.bind(model)))

router.route('/')
  .get(
    // ACL middleware or whatever before for instance...
    middleware(userController.list.bind(userController))
  )
  .post(
    // ACL middleware or whatever before for instance...
    middleware(userController.add.bind(userController))
  )
0.1.4

3 years ago

0.1.5

3 years ago

0.1.3

4 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

6 years ago