Skip to content

Files

Latest commit

 

History

History
23 lines (16 loc) · 472 Bytes

no-process-exit.md

File metadata and controls

23 lines (16 loc) · 472 Bytes

Pattern: Use of process.exit()

Issue: -

Description

The process.exit() method should only be used in command-line applications. In other contexts, throwing an error provides better error handling and stack traces.

Examples

Example of incorrect code:

if (problem) process.exit(1);

Example of correct code:

if (problem) throw new Error("message");

// In CLI apps:
#!/usr/bin/env node
if (problem) process.exit(1);