async-handler-express
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

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.

License

MIT

Package Sidebar

Install

npm i async-handler-express

Weekly Downloads

4

Version

0.2.4

License

MIT

Unpacked Size

29.3 kB

Total Files

14

Last publish

Collaborators

  • rana_usman
  • usmanhaider140
  • roman_azeem
  • maroof_akram