Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-async-errors

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-async-errors

Async/await error handling support for expressjs

  • 3.1.1
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is express-async-errors?

The express-async-errors package is a utility for handling errors in asynchronous Express routes and middleware. It allows you to write asynchronous route handlers and middleware without needing to manually catch errors and pass them to the next() function.

What are express-async-errors's main functionalities?

Automatic Error Handling in Async Routes

This feature allows you to write asynchronous route handlers without needing to wrap them in try-catch blocks. Any errors thrown in the async function will be automatically passed to the error-handling middleware.

const express = require('express');
require('express-async-errors');

const app = express();

app.get('/async-route', async (req, res) => {
  // Simulate an async error
  throw new Error('Something went wrong!');
});

app.use((err, req, res, next) => {
  res.status(500).send('Internal Server Error');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Automatic Error Handling in Async Middleware

This feature allows you to write asynchronous middleware without needing to wrap them in try-catch blocks. Any errors thrown in the async middleware will be automatically passed to the error-handling middleware.

const express = require('express');
require('express-async-errors');

const app = express();

app.use(async (req, res, next) => {
  // Simulate an async error
  throw new Error('Something went wrong in middleware!');
});

app.get('/', (req, res) => {
  res.send('Hello World');
});

app.use((err, req, res, next) => {
  res.status(500).send('Internal Server Error');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Other packages similar to express-async-errors

Keywords

FAQs

Package last updated on 12 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc