---
title: "Let It Crash: Best Practices for Handling Node.js Errors on Shutdown"
description: "Node.js applications can lose visibility into failures and experience downtime when processes crash or shut down without useful logging and recovery practices. The post presents lessons from consulting and a talk on the Node.js process lifecycle, focusing on graceful shutdown, error visibility, and fast restart after catastrophic errors. It recommends keeping startup lean by prebuilding data or compiling assets, then contrasts process.exit(), which accepts an exit code, with process.abort(), which terminates immediately and may generate a core dump for llnode-based postmortem debugging. It also explains beforeExit and exit, including their differing asynchronous-work behavior, and introduces SIGTERM and SIGINT as operating-system signals that applications can handle. The intended result is a restartable process strategy that reduces downtime, while preserving evidence needed to investigate crashes."
---

# Let It Crash: Best Practices for Handling Node.js Errors on Shutdown

[Heroku](https://yomu.fyi/company/heroku) · Julián Duque · Dec 18, 2019

**Type:** Tutorial

## Summary

Node.js applications can lose visibility into failures and experience downtime when processes crash or shut down without useful logging and recovery practices. The post presents lessons from consulting and a talk on the Node.js process lifecycle, focusing on graceful shutdown, error visibility, and fast restart after catastrophic errors. It recommends keeping startup lean by prebuilding data or compiling assets, then contrasts process.exit(), which accepts an exit code, with process.abort(), which terminates immediately and may generate a core dump for llnode-based postmortem debugging. It also explains beforeExit and exit, including their differing asynchronous-work behavior, and introduces SIGTERM and SIGINT as operating-system signals that applications can handle. The intended result is a restartable process strategy that reduces downtime, while preserving evidence needed to investigate crashes.

## Context

Consulting work revealed Node.js applications with insufficient visibility into crashes, inadequate logging strategies, missing information about failure causes, and downtime during recovery. The material addresses process shutdown and recovery for web, network-based, and other continuously running Node.js applications.

## Approach / What changed

The post explains the Node.js process lifecycle, recommends lean startup processes and prebuilding work, compares process.exit() with process.abort(), describes shutdown events such as beforeExit and exit, and introduces SIGTERM and SIGINT handling for graceful shutdown and restart.

## Takeaways

- Keep Node.js startup lean by prebuilding data or compiling assets outside the startup process, allowing a crashed process to restart with less downtime.
- process.exit() ends a process with an exit code, while process.abort() terminates immediately and may create a core dump that can support postmortem debugging with llnode.
- beforeExit can run asynchronous work before the event loop finishes, whereas exit occurs after the event loop has terminated and cannot perform asynchronous work; SIGTERM and SIGINT are also handleable shutdown signals.

**Tags:** [Debugging](https://yomu.fyi/topic/debugging), [Node.js](https://yomu.fyi/topic/node-js), [Reliability](https://yomu.fyi/topic/reliability)

- Source: [Heroku](https://www.heroku.com/blog/best-practices-nodejs-errors)
- Source URL: https://www.heroku.com/blog/best-practices-nodejs-errors
- Ingested by Yomu: 2026-09-09T16:02:30.648Z

[Read original post](https://www.heroku.com/blog/best-practices-nodejs-errors)
