The npm SIGHUP error occurs when the controlling terminal is closed or disconnected, typically during SSH sessions, remote deployments, or when terminal windows are closed while npm is running.
SIGHUP (signal hangup) is a Unix/Linux signal sent to a process when its controlling terminal is closed or disconnected. Historically used to notify programs of modem hangups, it's now primarily triggered by terminal window closures, SSH session disconnections, or connection timeouts. When npm receives SIGHUP, it means the terminal that spawned the npm process has either closed, dropped the connection, or the controlling process terminated unexpectedly. This is particularly problematic during long-running operations like npm install in CI/CD pipelines, remote SSH sessions, or unstable network conditions. npm doesn't always handle this signal gracefully—it simply terminates with an error code rather than cleaning up resources properly.
The nohup (no hangup) utility allows processes to continue running even after terminal disconnection:
# For npm install
nohup npm install > install.log 2>&1 &
# For npm scripts
nohup npm run build > build.log 2>&1 &
# Check progress
tail -f install.logThe > install.log 2>&1 redirects both stdout and stderr to a file, and & backgrounds the process.
For remote SSH work, use a terminal multiplexer that survives SSH disconnection:
# With tmux (recommended, more modern)
tmux new-session -d -s install "npm install"
tmux attach-session -t install
# Or with screen (older but widely available)
screen -d -m npm install
screen -ls # See running sessions
screen -r [session-id] # ReconnectBoth tools create persistent pseudo-terminals that survive connection drops.
If SIGHUP is caused by SSH timeouts, adjust server-side keep-alive:
# On the remote server, edit /etc/ssh/sshd_config
sudo nano /etc/ssh/sshd_config
# Add or modify these lines:
ClientAliveInterval 300
ClientAliveCountMax 3
# Restart SSH daemon
sudo systemctl restart sshdOn the client side, add to ~/.ssh/config:
Host *
ServerAliveInterval 60
ServerAliveCountMax 3npm's signal handling has issues in some versions. Running node directly avoids this:
# Instead of:
npm start
# Use:
node ./dist/index.jsFor Procfile deployments (Heroku, etc.):
# Bad (npm signal handling issues)
web: npm start
# Better
web: node server.jsFor flaky networks or slow connections, increase npm's fetch timeout:
# Set timeout to 5 minutes (300 seconds)
npm config set fetch-timeout 300000
npm config set fetch-retry-mintimeout 10000
npm config set fetch-retry-maxtimeout 120000Or use a .npmrc file in your project root:
fetch-timeout=300000
fetch-retry-mintimeout=10000
fetch-retry-maxtimeout=120000
fetch-retries=5Signal Handling Deep Dive: SIGHUP is signal #1 on POSIX systems. When a shell receives SIGHUP, it intercepts the signal and resends SIGHUP to all child processes in its job table before exiting. npm doesn't register a SIGHUP handler, so it simply terminates.
Docker Considerations: In Docker, SIGHUP can be sent when the PID 1 process terminates. The proper Docker solution is to use an init system (like dumb-init) and run npm indirectly: dumb-init npm install or simply node app.js without npm as a wrapper.
CI/CD Environments: Most CI/CD platforms (GitHub Actions, GitLab CI, CircleCI) don't send SIGHUP during normal job execution. If you see SIGHUP in CI, check for job timeout settings, dependency download timeouts, or OOM conditions.
stdout Buffering: A subtle issue: if npm's stdout/stderr is buffered and the terminal closes before the buffer flushes, the process may receive SIGPIPE instead. Using output redirection to files avoids this entirely.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error