2.1.3 • Published 1 month ago

express-asyncify v2.1.3

Weekly downloads
3,334
License
MIT
Repository
github
Last release
1 month ago

express-asyncify npm.io

Easy support async/await to express.

Supports ESM modules 👍

Installation

$ npm i express-asyncify

Usage

Asyncify express application:

import express from 'express';
import asyncify from 'express-asyncify';
// For CommonJS
// const asyncify = require('express-asyncify').default;

const app = asyncify(express());

// ...

app.get('/', async (req, res) => {
    const posts = await Post.findAll();
    res.render('index', { posts });
});

Asyncify express router:

import express from 'express';
import asyncify from 'express-asyncify';

const app = express();
const router = asyncify(express.Router());

// ...

router.get('/', async (req, res) => {
    const posts = await Post.findAll();
    res.render('index', { posts });
});

app.use('/blog', router);

TypeScript

If you're having trouble importing a module into TypeScript, try adding settings to tsconfig.json:

{
    "compilerOptions": {
      "esModuleInterop": true,
      "allowSyntheticDefaultImports": true
    }
  }

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm ci
$ npm test

License

MIT

2.1.3

1 month ago

2.1.2

8 months ago

2.0.3

11 months ago

2.1.1

11 months ago

2.0.2

11 months ago

2.1.0

11 months ago

2.0.1

11 months ago

2.0.0

11 months ago

1.1.0

1 year ago

1.1.0-1

1 year ago

1.1.0-0

1 year ago

1.0.1

4 years ago

1.0.0

7 years ago