process.exit()
A Node.js function that ends the process at once with the exit code you give, skipping any work still waiting on the event loop.
In more detail
Pending writes and timers are dropped, so call it only after cleanup has finished. Setting process.exitCode and letting the loop empty is the gentler way to exit.
Related terms
- exit code — A number a process returns when it finishes: 0 means success, anything else means something went wrong.
- beforeExit and exit events — Process events: beforeExit fires when the event loop has run out of work and may schedule more, while exit fires just before the process ends and allows only synchronous code.
- graceful shutdown — Stopping a service in an orderly way: finish current work, close connections, then exit.
Taught in
- Close Phase & Signal Dispatch: Sockets & Teardown — Node.js Internals & Backend Services
- Global Error Trapping: uncaughtException & Exits — Node.js Internals & Backend Services
- Production Hardening: Graceful Shutdown & Docker — Node.js Internals & Backend Services