'Express route not working but deliberate error in code shows it is being called correctly

I have a very strange problem with an Express route whereby a perfectly valid console.log does not display and no other lines of code after it execute when the route is hit.

For example:

app.get('/api/v1/users', (req, res) => {
   console.log('Users route has been reached....') // does not display in console
   ...
  // No other code executes
}

However, to test if the route is actually being hit I purposely created an error in the console.log like so:

console.log('Route has been reached....) // missing end quote

And when I check the logs, I can see the following error.

0|index | /home/ubuntu/apps/api/server/index.js:119 0|index | console.log('Route has been reached........) 0|index | ^^^^^^^^^^^^^^^^^^^^^^^ 0|index | 0|index | SyntaxError: Invalid or unexpected token

This must mean that the route is being hit correctly but for some reason doesn't execute its request properly. My logic is that if the line with the bad console.log is reached then I cannot see why the correct one doesn't even log out at all.

I am a bit stumped as to what is going on so any ideas or assistance on what the problem could be is very welcome.

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source