GithubHelp home page GithubHelp logo

pacifiquem / node-async-handler Goto Github PK

View Code? Open in Web Editor NEW
26.0 1.0 1.0 213 KB

Async Error Handling Middleware for ExpressJS with ESM/TypeScript support.

License: MIT License

TypeScript 93.52% Shell 6.48%
async error error-handling express handling node nodejs try-catch

node-async-handler's Introduction

node-async-handler

Async Error Handling Middleware for Express with ESM Support

This middleware helps you eliminate the need for try-catch blocks throughout your Express application, streamlining error handling and improving code readability.

Note : This is made specifically for ExpressJS projects.

Usage

To use node-async-handler, simply wrap your async functions in the asyncHandler middleware:

// For ESM
import pkg from 'node-async-handler';
const { asyncHandler } = pkg;

// For CommonJS
const { asyncHandler } = require('node-async-handler');

express.get('/', asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
  const result = await someAsyncFunction();
  res.json(result);
}));

In case of an error, the middleware automatically calls next(error), allowing centralized error handling in your Express app.

Importing

Note : To import node-async-handler in ESM:

import pkg from 'node-async-handler';
const { asyncHandler } = pkg;

Note : To import node-async-handler in CommonJS:

const { asyncHandler } = require('node-async-handler');

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author: MURANGWA Pacifique

node-async-handler's People

Contributors

pacifiquem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

theopensourcer1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.