DevAcademy
LearnNode.jsThe process Object
IntermediateNode.js

The process Object

A global object giving your script access to environment variables, arguments, and process control.

Reading Time

12 min

Lesson

Lesson 15 of 34

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

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Command-Line Arguments

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Common process Properties & Methods

MemberPurpose
process.envAccess environment variables
process.argvCommand-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

Try it yourself — edit and run

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.

Interview Questions

Quick Quiz

1. Do you need to import process in Node.js scripts?

2. What does process.argv contain?

3. Why listen for the SIGTERM signal in a server?