Easy support async/await
to express.
Supports ESM modules 👍
$ npm i express-asyncify
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);
If you're having trouble importing a module into TypeScript, try adding settings to tsconfig.json
:
{
"compilerOptions": {
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}
To run the test suite, first install the dependencies, then run npm test
:
$ npm ci
$ npm test