On this page
Tracks

Production & Deployment Tips

Last reviewed 2 Sept 2026

Advance / Production

  1. Always use nvm and create .nvmrc file in root directory with node version and add engines in package.json

.nvmrc

20.18.3

"engines": {
"node": ">=18.17.0",
"npm": ">=9.0.0"

},

  1. We can use winston and a custom log error defined in logger.js in utils. Refer github repo

  2. Always add common config.js under config for all process.env

  3. We can use pm2 for managing automatic restart

  4. Add global error handler for exit

    const ERROR_THRESHOLD = 50; _// Maximum number of consecutive errors before considering shutdown_
    const ERROR_RESET_INTERVAL = 60000; _// Reset error count after 1 minute_
    let errorCount = 0;

// Reset error count periodically

setInterval(() => {
errorCount = 0;
}, ERROR_RESET_INTERVAL);
process.on('uncaughtException', (_error_) => {
errorCount++;
logger.logError('[Server.js] Uncaught Exception:', _error_, {errorCount });

// Only exit if we’re hitting too many errors too quickly

if (errorCount >= ERROR_THRESHOLD) {

logger.error(`Error threshold (${ERROR_THRESHOLD}) exceeded. Shutting down gracefully...`);

// Give time for existing requests to complete

setTimeout(() => process.exit(1), 5000);
}
});
process.on('unhandledRejection', (_error_) => {
errorCount++;

logger.error(‘Unhandled Rejection:’, {

message: error.message,
stack: error.stack,
timestamp: new Date().toISOString(),

errorCount

});

// Only exit if we’re hitting too many errors too quickly

if (errorCount >= ERROR_THRESHOLD) {

logger.error(`Error threshold (${ERROR_THRESHOLD}) exceeded. Shutting down gracefully...`);

// Give time for existing requests to complete

setTimeout(() => process.exit(1), 5000);
}
});