What process Provides
process is a global object available in every Node.js script (no import needed) that represents the currently running Node.js process — its environment, command-line arguments, and ways to exit or listen for shutdown signals.
Environment Variables
Console Output
Click “Run” to see the console output here.
Command-Line Arguments
Console Output
Click “Run” to see the console output here.
Common process Properties & Methods
| Member | Purpose |
|---|---|
| process.env | Access environment variables |
| process.argv | Command-line arguments passed to the script |
| process.exit(code) | Immediately terminate the process with an exit code |
| process.cwd() | The current working directory |
| process.on('SIGTERM', ...) | Listen for shutdown signals to clean up gracefully |
Graceful Shutdown
Console Output
Click “Run” to see the console output here.
Exit Codes
process.exit(0) signals success; any non-zero code (commonly 1) signals an error. Deployment tools, CI pipelines, and process managers use this exit code to decide whether a run succeeded or failed.
Best Practice
Listen for SIGTERM in any long-running server so it can finish in-flight requests and close database connections cleanly before exiting — this is especially important in containerized deployments, where orchestrators send SIGTERM before forcefully killing a process.