Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wallneradam/node-express-async
Automatically handles unhandled async middleware errors by sending them to next() function.
https://github.com/wallneradam/node-express-async
async-await es6 expressjs javascript node-module nodejs promise
Last synced: about 1 month ago
JSON representation
Automatically handles unhandled async middleware errors by sending them to next() function.
- Host: GitHub
- URL: https://github.com/wallneradam/node-express-async
- Owner: wallneradam
- License: bsd-3-clause
- Created: 2017-09-05T11:01:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-22T13:31:56.000Z (over 6 years ago)
- Last Synced: 2024-10-02T23:45:14.736Z (3 months ago)
- Topics: async-await, es6, expressjs, javascript, node-module, nodejs, promise
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-express-async
Automatically handles unhandled async middleware errors by sending them to next() function.
This way you don't need and you won't forget to try-catch all middlewares for default
error handling.## Usage
You need to *require* the module (only) once by application for example in app.js:
```javascript
require("node-express-async");
```After this you can use async middlewares normally, like this:
```javascript
const router = express.Router();
router.get('/', async (req, res, /* next */) => {
// You don't need the try-catch
// try {
... your code
// } catch(err) {
// next(err);
// }
})
```## How it works
It modifies Route object of Express, to every middleware which has async prefix
will be wrapped by asyncMiddleware function. The wrapper creates a Promise, which if
rejected calls the next function.More details here:
https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016