0 votes
1 view
in Web Technology by (14.5k points)

I have an express service where a lot of my endpoints look like the following.

var express = require('express');

var router = express.Router();

router.get('/updateThisValue', (req, res) => {

  let value = req['query'].value 

  try {

    database.update(value, function() {  // callback function on update

       console.log(undefinedValue.undefined) // crash the server


  } catch (err) {

    // Log the error and other stuff



Looking at this code, if a database update is called, something will crash in the callback function and since there is no try-catch, the whole server should crash as well.

Right now, I am okay with the server crashing. The problem is that I would like to be able to log some debugging information in the callback before it crashes, namely the express endpoint hit and the parameters passed to it.

One solution is that I could just log every single endpoint hit, but the only problem with that is that the server starts to have very large logs. So we don't log endpoints hit by default. The frustration however is that recently an endpoint hit the server that did cause it crash and I'm still unsure what the actual endpoint hit and parameters passed to it where.

Basically, I want the server to still crash but at least I would be able to trace the endpoint hit and its parameters

1 Answer

0 votes
by (25.1k points)

Could this help: https://expressjs.com/en/guide/error-handling.html

Normally you would see the exception in the console or in the logs of your process manager (like pm2).

Welcome to Intellipaat Community. Get your technical queries answered by top developers !