Back to results for “Environment Variables & Configuration”
Node.js › Global Objects & the process Object

What is the process object in Node.js, and what are some of the most commonly used properties and methods on it?

Beginner

Answer

process is a global object providing information about, and control over, the currently running Node.js process -- commonly used members include process.env (environment variables), process.argv (command-line arguments), process.exit() (terminate the process), process.cwd() (current working directory), process.platform (the OS), and process.on() for listening to process-level events like 'exit', 'uncaughtException', or signals like SIGTERM.
console.log(process.env.NODE_ENV);
console.log(process.argv); // ['node', '/path/to/script.js', 'arg1', 'arg2']
console.log(process.cwd());
console.log(process.platform); // 'linux', 'darwin', 'win32'
console.log(process.version); // e.g. 'v20.11.0'
Real-world example A CLI tool reads its configuration from process.env, accepts additional arguments via process.argv, and uses process.platform to apply OS-specific path handling logic, all without needing any external dependency for these fundamental process-level capabilities.

Common follow-ups: What's the difference between process.argv[0], process.argv[1], and the arguments that follow?;Why is process considered a global object available without needing to require() it, unlike most other Node.js functionality?