As a good developer on uncaught exception, we need two things
- Our Server should not crash
- 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>";
Note : get your token and Service Token from https://app.wooffer.io/
Step 3 : Add Wooffer to Root directory
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);
Once This process is done now your node server no more crashing on uncaught exception