I'm developing a Express + PostgreSQL app and I want to implement a global error handler system. Now I want to caught all uncaught exceptions from my entire project. Server is running with nodemon
.
A code like this console.log(x)
should give a custom error that I created because x is not defined;
I'm putting process.on('uncaughtException', () => {})
in my server.js
file, located in root directory and inserting error with console.log(x)
in app.js
that is also in root directory folder.
Here is my server.js
code:
import './src/config/dotenv.js';
import app from './app.js';
process.on('uncaughtException', (err) => {
console.log(err.name, err.message);
console.log('UNCAUGHT EXCEPTION!