async-express
TypeScript icon, indicating that this package has built-in type declarations

0.1.6 • Public • Published

async-express

Simple middleware wrapper to make Express handlers async compatible.

Usage

npm install --save async-express

In a route

const express = require('express');
const asyncExpress = require('async-express');
 
const app = express();
 
// As a route
app.get('/', asyncExpress(async (req, res, next) => {
  // Wait 5 seconds
  await new Promise(r => setTimeout(r, 5000));
  // Send a response
  res.send('Waited 5 seconds successfully');
}));

The sample above can be refactored as the following

const express = require('express');
const asyncExpress = require('async-express');
 
const app = express();
 
const waitForABit = asyncExpress(async (req, res, next) => {
  // Wait 5 seconds
  await new Promise(r => setTimeout(r, 5000));
  // Send a response
  res.send('Waited 5 seconds successfully');
});
 
app.get('/', waitForABit);

Package Sidebar

Install

npm i async-express

Weekly Downloads

2

Version

0.1.6

License

MIT

Unpacked Size

2 kB

Total Files

4

Last publish

Collaborators

  • jchancehud