Configuration
Read deployment configuration such as NODE_ENV or PORT from the environment.
Node.js · Const
process is a Node.js global object representing the currently running process. It exposes runtime information, environment data, command-line arguments, and process control APIs.
The globally available process object exposes information about and control over the Node.js process. Use its properties for runtime and environment details, and its methods and events for process-level behavior.
process<Object> The process object.
console.log({pid: process.pid, node: process.version, mode: process.env.NODE_ENV ?? "development"});Prints selected information from the current Node.js process and reads an optional environment variable.
Read deployment configuration such as NODE_ENV or PORT from the environment.
Inspect command-line arguments when building a CLI.
Report runtime identity and diagnostics such as the process ID or Node.js version.
process is a global object that provides information about and control over the current Node.js process. Node.js applications can use it without importing it.
Follow-up: How would you inspect runtime metadata? Use properties such as process.version and process.versions.
process.env exposes the user environment as an object. Applications commonly read configuration from it, but should account for missing variables and deployment-specific values.
Follow-up: How can a program distinguish an unset variable from an empty one? Check explicitly for undefined and compare the resulting string with an empty value.
process.argv is an array containing the command-line arguments passed when the Node.js process was launched. The application can inspect it to implement command-line options.
Follow-up: How would you parse complex options safely? Use a dedicated argument parser rather than relying on positional indexes throughout the application.
process.argvprocess.envprocess.versionprocess.versionsprocess.pidprocess.exit()