https://github.com/txchen/awrap
async function wrapper for expressjs
https://github.com/txchen/awrap
Last synced: 5 months ago
JSON representation
async function wrapper for expressjs
- Host: GitHub
- URL: https://github.com/txchen/awrap
- Owner: txchen
- License: mit
- Created: 2015-09-30T05:30:46.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-04T16:59:46.000Z (over 10 years ago)
- Last Synced: 2025-09-18T23:00:18.105Z (9 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/awrap
- Size: 148 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# awrap - async function wrapper for express.js
express.js can take async function as middleware or handler function, however, it cannot handle the error correctly. When error happens, the request will never complete.
awrap turns async function into a normal function that express.js can accept.
## Installation
```
$ npm install awrap
```
## Usage
Just wrap the async function with awrap and pass into express:
```javascript
app.get('/', awrap(async (req, res) => {
console.log('processing /')
await sleep(200)
res.send('Hello async/await!')
}))
```
## Example
[This](./example/app.es6) is an example server implementation.
To run it:
```
$ npm install
$ npm run example
```
## Changelog
**2015-10-04** `0.0.1`
First version.