DEV Community

Cover image for Prevent app crashes with ExpressJS
Hidayt Rahman
Hidayt Rahman

Posted on

Prevent app crashes with ExpressJS

Most annoying experience of any app when it get crashed so basically it blocks the entire operation in expressJS

Lets fix this using the middleware, so even if the app has some issue will work continually and wont impact user on other part of the app

// An error handling middleware
app.use(function (err, req, res, next) {
  res.json({ message: "Oops, something went wrong :(", error: err.message });

Enter fullscreen mode Exit fullscreen mode

Thats it!

Let me know if you have any other suggestions :)

Top comments (0)