0.1.6 • Published 5 years ago

async-express v0.1.6

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

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);
0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

8 years ago