DEV Community

Daxesh Italiya
Daxesh Italiya

Posted on • Edited on

How do I prevent the node.js server from crashing on uncaught exception

As a good developer on uncaught exception, we need two things

1. Our Server should not crash
2. Need detailed root cause of the exception as a Log for improvement in code

To achieve both points I would recommend you to Add Wooffer (https://wooffer.io/) in your Code. you will solve this crashing problem and get more than your expectation

Step to achieve feature

Step 1: Install

npm i wooffer

or

yarn add wooffer

Step 2: Setup ENV

token = "<Your Token>";
serviceToken = "<Your Service Token>";
Enter fullscreen mode Exit fullscreen mode

Note: get your token and Service Token from https://app.wooffer.io/

Step 3: Add Wooffer to the Root directory like index.js or app.js

const wooffer = require("wooffer");
const express = require("express");

wooffer(process.env.woofferToken, process.env.woofferServiceToken);

// Add this code to track endpoint usage(Optional)
const app = express();
app.use(wooffer.requestMonitoring);
Enter fullscreen mode Exit fullscreen mode

Once This process is done now your node server no more crash on uncaught exceptions and provide real-time slack alert

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay