# express-async-wrap

> Allows the use of ES2016 async functions as Express route handlers

Latest version **1.0.0** (published 2015-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-async-wrap
pnpm add express-async-wrap
yarn add express-async-wrap
bun add express-async-wrap
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-09-04 |
| First published | 2015-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/express-async-wrap) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chris Shepherd |
| Maintainers | tesco |
| Keywords | express, async-await, routes |

## Links

- npm: https://www.npmjs.com/package/express-async-wrap
- Repository: https://github.com/Greenfields/express-async-wrap
- Homepage: https://github.com/Greenfields/express-async-wrap#readme
- Issues: https://github.com/Greenfields/express-async-wrap/issues
- npm.io page: https://npm.io/package/express-async-wrap

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2015-09-04

## README

# express-async-wrap
Allows the use of ES2016 async functions as Express route handlers.

## Install

```javascript
npm i express-async-wrap
```

## Usage

To use in place of a normal route handler:

```javascript
import wrap from 'express-async-wrap';

function makeResult(result) {
  return new Promise((resolve) => {
    setTimeout(() => resolve(result), 10);
  });
}

app.get('/', wrap(async function(req, res) {
  const results = [];

  for(let i = 0; i < 5; i++) {
    results.push(makeResult(`test${i}`));
  }

  res.send((await* results).join());
}));
```

To use as an error handler:

```javascript
import wrap from 'express-async-wrap';

app.get('/', wrap(async function(req, res, next) {
  next(new Error('error'));
}));
app.use(wrap(async function(err, req, res, next) {
  res.status(500).send('error');
}));
```

---
_Source: https://npm.io/package/express-async-wrap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
