Skip to content
Discussion options

You must be logged in to vote

The best practice is to handle promise rejections at the source using try/catch (with async/await) or .catch() on promises. This prevents unhandled rejections in the first place.

You can use:

process.on('unhandledRejection', (reason) => { console.error('Unhandled Rejection:', reason); process.exit(1); // recommended in production });

But this should only be a safety net not your main error-handling strategy.
In production, it’s generally safer to log the error and exit the process, then let a process manager (PM2, Docker, etc.) restart the app.

hope, you get that!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jeet-dev111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants