Better Programming

Advice for programmers.

Follow publication

Member-only story

Error Handling Methods for Asynchronous Code in Express.js

Grow this important skill right from the start

Sifeddine Lamraoui
Better Programming
Published in
4 min readJul 25, 2022

--

Error handling is one of the most important parts of software development, yet it often doesn’t get the attention it deserves, especially for new developers. So we will be looking at two different methods of error handling when working with Express.js, which is the most popular JavaScript server-side framework.

Since Express.js takes care of error handling for synchronous code by default, we will only cover asynchronous code, for example, if we call this route that uses a synchronous handler function.

Express’s default built-in error handler takes care of the error, and our app continues to run.

But, if we run the same route with an async/await handler function, here’s what we get:

--

--

Sifeddine Lamraoui
Sifeddine Lamraoui

Written by Sifeddine Lamraoui

I’m a Software Developer, Interested in Technology and Computer Science.

Responses (2)

Write a response