npm.io
1.0.0 • Published 7 years ago

async-wrapper-express

Licence
LGPL-3.0
Version
1.0.0
Deps
0
Size
1 kB
Vulns
0
Weekly
0

Async wrapper middleware

A simple Express middleware to wrap async functions.

Usage

const express = require('express');
const asyncWrapper = require('async-wrapper-express');

const router = express.Router();

router.get('/', asyncWrapper(async function (req, res, next) {
    let objs = await getFromDb();

    res.send(objs);
}));

Notes

The middleware will do Promise.resolve on the async function and then catch any error thrown, that will be then passed onto the next function in Express chain.