node server crashing on uncaught exception
Asked Answered
D

1

0

what is the best strategy to make node server not crash on uncaught exceptions? I have a web application in node. Whenever some uncaught error happens , server fails completely.we have to go to production soon.So this cannot happen in production.

How can we handle this?

Defector answered 24/3, 2017 at 20:40 Comment(3)
There is a detailed answer already here #7311021Cyrie
Thanks..are there any new practices developed over time?Defector
Refer to this document from Joyent joyent.com/node-js/production/design/errorsCyrie
M
1

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>";

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

Microampere answered 20/5 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.