Package Exports
- async-handler-express
- async-handler-express/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (async-handler-express) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Async Handler
This Package is to handle the async API response.
Installation
Use the package manager npm to install async-handler-express.
npm install async-handler-express
Add Middleware in root file
const { errorHandler }=require('async-handler-express');
#use this middleware after including routes in the app root/server file.
app.use(errorHandler);
Usage
const { catchAsync }=require('async-handler-express');
app.get('/',catchAsync(async()=>{
await Promise.resolve();
}));
Example
#Fetch users data from jsonplaceholder fake apis
const { catchAsync }=require('async-handler-express');
router.get('/users',catchAsync(async()=>{
const users = await fetch("https://jsonplaceholder.typicode.com/users");
return users;
}));
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.