0.0.1 • Published 8 years ago

async-mw v0.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

async-mw

Use async syntax (or Promises) to build express middlewares.

npm install --save async-mw

Sample

import express from 'express';
import asyncMW from 'async-mw';

const app = express();
app.get('/resource/:id', asyncMW(async req => {
    const list = await myDatabase.load(req.params.id);
    return list;
}));

What else?

  • asyncMW takes your async function(req, res)
  • asyncMW returns express middleware function(req, res, next)
  • your async function could return:
    • undefined: in this case asyncMW calls method next
    • null: asyncMW does nothing
    • any other value: asyncMW sends that value like json
  • that's it