Skip to content

Use async syntax (or Promises) to build express middlewares

Notifications You must be signed in to change notification settings

smbwain/async-mw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Use async syntax (or Promises) to build express middlewares

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published