How to fix npm ERR! code ELIFECYCLE npm ERR! errno SIGTERM npm ERR! process terminated with signal SIGTERM in npm

npmINTERMEDIATEMEDIUMUpdated Dec 6, 2025· 176 views

SIGTERM errors in npm occur when a process is terminated externally, often by Docker, CI timeouts, or process managers. Run Node directly instead of via npm for proper signal handling.

Quick fix

Fixes npm ERR! code ELIFECYCLE npm ERR! errno SIGTERM npm ERR! process terminated with signal SIGTERM

CMD ["npm", "start"]
  1. Run Node directly instead of via npm
  2. Add signal handlers to your application
  3. Use exec form in Dockerfile
  4. Update Procfile for Heroku/similar platforms
npm — error
CMD ["npm", "start"]
npm ERR! code ELIFECYCLE
npm ERR! errno SIGTERM
npm ERR! process terminated with signal SIGTERM

What this error means

SIGTERM (signal 15) is a termination signal sent to gracefully shut down a process. When npm reports this error, it means an external system (Docker, Kubernetes, CI/CD, or a process manager) sent SIGTERM to your npm process. The issue is that npm doesn't properly forward SIGTERM signals to child processes. When npm receives SIGTERM, it often kills child processes immediately without allowing graceful shutdown handlers to execute. This is a known limitation of running Node.js applications via npm scripts.

Typical symptoms

  • npm script exits with "signal SIGTERM" during shutdown
  • Graceful shutdown code never executes
  • Database connections left open when container stops
  • Process terminates without cleanup in Docker/Kubernetes
  • CI/CD jobs timeout and report SIGTERM error
  • Different behavior between Node 20.2 and 20.3+

Common causes

  1. Docker/Kubernetes sending SIGTERM during container shutdown
  2. CI/CD pipeline timeout killing the process
  3. Process manager (systemd, PM2) stopping the service
  4. npm bug: doesn't properly forward signals to child processes
  5. Running npm as PID 1 in Docker (doesn't receive signals properly)
  6. Memory limits triggering OOM killer (shows as SIGTERM)

How to fix "npm ERR! code ELIFECYCLE npm ERR! errno SIGTERM npm ERR! process terminated with signal SIGTERM"

1Run Node directly instead of via npm

The best fix—bypass npm's signal handling issues:

Before (problematic):

dockerfile
CMD ["npm", "start"]

After (correct):

dockerfile
CMD ["node", "index.js"]

This makes your Node.js process PID 1, ensuring it receives signals directly.

2Add signal handlers to your application

Handle SIGTERM in your code for graceful shutdown:

javascript
// At the top of your entry file
process.on('SIGTERM', async () => {
  console.log('SIGTERM received, shutting down gracefully');

  // Close server
  await server.close();

  // Close database connections
  await db.disconnect();

  process.exit(0);
});

process.on('SIGINT', async () => {
  console.log('SIGINT received, shutting down gracefully');
  await server.close();
  process.exit(0);
});
3Use exec form in Dockerfile

Ensure your process receives signals in Docker:

Shell form (bad—signals go to shell, not Node):

dockerfile
CMD npm start

Exec form (good—Node receives signals):

dockerfile
CMD ["node", "index.js"]

Or use ENTRYPOINT:

dockerfile
ENTRYPOINT ["node", "index.js"]
4Update Procfile for Heroku/similar platforms

Use Node directly in your Procfile:

Before:

bash
web: npm start

After:

bash
web: node index.js
5Use process.once for signal handlers

Prevent duplicate signal handling:

javascript
// Use once() instead of on() to handle only first signal
process.once('SIGTERM', shutdownHandler);
process.once('SIGINT', shutdownHandler);

async function shutdownHandler() {
  console.log('Shutting down...');
  // Cleanup code
  process.exit(0);
}

npm can sometimes send signals twice; once() prevents double execution.

6Use a process manager for production

For production deployments, use a proper process manager:

bash
# PM2
pm2 start index.js

# Or in ecosystem.config.js
module.exports = {
  apps: [{
    name: 'app',
    script: 'index.js',
    kill_timeout: 5000
  }]
}

Process managers handle signals correctly and provide additional features like clustering.

Advanced notes

This issue became more prominent in Node.js 20.3.0+ due to changes in how npm handles signals. If you must use npm scripts, consider downgrading npm or Node.js version temporarily while the npm team addresses this.

For Kubernetes, set appropriate termination grace periods:

yaml
spec:
  terminationGracePeriodSeconds: 30

The graceful-shutdown npm package can help manage shutdown across different environments with various cleanup requirements.

Frequently asked questions

What does "npm ERR! code ELIFECYCLE npm ERR! errno SIGTERM npm ERR! process termi" mean?
SIGTERM (signal 15) is a termination signal sent to gracefully shut down a process. When npm reports this error, it means an external system (Docker, Kubernetes, CI/CD, or a process manager) sent SIGTERM to your npm process. The issue is that npm doesn't properly forward SIGTERM signals to child processes.
How do I fix "npm ERR! code ELIFECYCLE npm ERR! errno SIGTERM npm ERR! process termi"?
SIGTERM errors in npm occur when a process is terminated externally, often by Docker, CI timeouts, or process managers. Run Node directly instead of via npm for proper signal handling.
What causes "npm ERR! code ELIFECYCLE npm ERR! errno SIGTERM npm ERR! process termi"?
Docker/Kubernetes sending SIGTERM during container shutdown CI/CD pipeline timeout killing the process Process manager (systemd, PM2) stopping the service
Is the "npm ERR! code ELIFECYCLE npm ERR! errno SIGTERM npm ERR! process termi" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading