NodeJSThe process Object

The process Object

process is a global object that represents — and lets you control — the currently running Node.js process. It is your window into the environment, command-line arguments, standard I/O streams, lifecycle events, resource usage, and the exit code. You will reach for it constantly, and several of its members are important enough to have their own pages. This page is the map of the whole object.

Identity & runtime information

JS
process.pid              // process ID, e.g. 48213
process.ppid             // parent process ID
process.platform         // 'darwin' | 'linux' | 'win32'
process.arch             // 'x64' | 'arm64'
process.version          // Node version string, e.g. 'v20.11.0'
process.versions         // { node, v8, uv, openssl, ... }
process.cwd()            // current working directory
process.uptime()         // seconds since the process started
process.execPath         // absolute path to the node binary
process.title            // process name shown in 'ps' / Task Manager
pid 48213 on linux/x64, Node v20.11.0, up 0.07s
version vs versions
`process.version` is just Node's version string. `process.versions` is an object with the versions of *every* bundled component — handy when a bug depends on the V8 or OpenSSL version: `process.versions.v8`, `process.versions.openssl`.
The members you will use most

Member

What it gives you

process.env

Environment variables → process.env

process.argv

Command-line arguments → process.argv

process.stdin/stdout/stderr

Standard I/O streams

process.exit([code])

Terminate immediately with an exit code

process.exitCode

Set the code without forcing an immediate exit

process.on(event, fn)

Subscribe to lifecycle events & signals → Process Events

process.nextTick(fn)

Run a callback before the next loop phase → nextTick

process.memoryUsage()

Heap and RSS memory statistics

process.cpuUsage()

User/system CPU time consumed

process.hrtime.bigint()

High-resolution nanosecond timer

Standard streams

process.stdout and process.stderr are writable streams; process.stdin is a readable stream. In fact console.log is essentially process.stdout.write with formatting and a trailing newline, and console.error writes to stderr. Writing directly gives you control over newlines and lets you build pipelines.

Reading piped input — echo 'hi there' | node app.js

JS
process.stdout.write('Type something and press Enter:\n')

process.stdin.setEncoding('utf8')
process.stdin.on('data', (chunk) => {
  process.stdout.write(`You typed: ${chunk}`)
})
process.stdin.on('end', () => process.stdout.write('Input closed.\n'))

Because they are streams, they also expose whether they are connected to a terminal via .isTTY — useful for deciding whether to print colours.

Exit codes and exiting cleanly

A process ends with an exit code: 0 means success, any non-zero value means failure (CI systems and shells rely on this). There are two ways to set it, and the difference matters:

JS
// PREFERRED: signal failure but let pending I/O drain naturally.
process.exitCode = 1
// ...the process exits with code 1 once the event loop empties.

// FORCEFUL: terminate right now. Pending writes/logs may be lost.
process.exit(1)
Avoid abrupt process.exit() mid-async
Calling `process.exit()` while asynchronous work is in flight can **truncate** output — a half-written log, a response still flushing to the client, a database write not yet committed. Prefer setting `process.exitCode` and `return`-ing, so Node exits *after* the loop drains. Reserve `process.exit()` for genuine "stop now" situations.
Measuring resources and time

Benchmark a block of work

JS
const startCpu = process.cpuUsage()
const start = process.hrtime.bigint()

doExpensiveWork()

const ns = process.hrtime.bigint() - start
const cpu = process.cpuUsage(startCpu)   // delta since startCpu
console.log(`Wall time: ${Number(ns) / 1e6} ms`)
console.log(`CPU user: ${cpu.user / 1000} ms, system: ${cpu.system / 1000} ms`)

const m = process.memoryUsage()
console.log(`Heap used: ${(m.heapUsed / 1e6).toFixed(1)} MB`)
hrtime vs Date.now()
`process.hrtime.bigint()` is a **monotonic** high-resolution clock (nanoseconds) that never jumps backward when the system clock is adjusted — use it for measuring durations. `Date.now()` is wall-clock time and can drift or jump; use it for timestamps, not benchmarks.
Lifecycle events (preview)

process is an EventEmitter, so you can subscribe to important moments — exit, beforeExit, uncaughtException, unhandledRejection, and OS signals like SIGTERM/SIGINT. These power graceful shutdown and last-resort error handling, covered fully in Process Events & Signals.

JS
process.on('exit', (code) => {
  // Synchronous cleanup only — the loop is already stopping.
  console.log(`Exiting with code ${code}`)
})
Next
Drill into the parts you will use most: [Command-Line Arguments](/nodejs/process-argv), [Environment Variables](/nodejs/process-env), and [Process Events & Signals](/nodejs/process-events).