Skip to content
Node.js nd process 4 min read

The process Object

The process object is a global that gives your code a window into the running Node.js instance: its identity, the version of Node executing it, the operating system underneath, where it was launched, and how much memory it is using. Because it is available everywhere without an import, it is the canonical way to inspect the runtime, read environment configuration, and react to lifecycle events. This page focuses on the most commonly used informational members—pid, version, versions, platform, arch, cwd(), chdir(), memoryUsage(), and uptime().

What process is

process is an instance of EventEmitter and a property of the global object, so you can use it in any module—ESM or CommonJS—without requiring it. That said, modern Node also lets you import it explicitly, which is clearer and helps tooling:

// Explicit import works in ESM and CommonJS, and is recommended for clarity
import process from "node:process";

console.log(typeof process); // 'object'
console.log(process === globalThis.process); // true

Output:

object
true

Because every member lives on this single object, it is easy to print a quick runtime report from anywhere in your app.

Identifying the process: pid and ppid

process.pid is the operating-system process ID of the current Node instance, and process.ppid is the parent process ID. These are useful for logging, for correlating a Node process with ps/top output, and for sending signals between processes.

import process from "node:process";

console.log(`PID:  ${process.pid}`);
console.log(`PPID: ${process.ppid}`);

Output:

PID:  48213
PPID:  48190

pid is a number that is only meaningful while the process is alive. Don’t persist it as a long-lived identifier—after the process exits, the OS may reuse that number for a different program.

Version information: version and versions

process.version is a string holding the Node.js version, always prefixed with v (for example, v22.11.0). process.versions is an object exposing the versions of Node and every bundled dependency—V8, libuv, OpenSSL, zlib, and more. This is the reliable way to check the runtime instead of parsing CLI output.

import process from "node:process";

console.log(process.version);
console.log(process.versions.node);
console.log(process.versions.v8);
console.log(process.versions.openssl);

Output:

v22.11.0
22.11.0
12.4.254.21-node.20
3.0.15+quic

Note that process.version includes the leading v, while the entries in process.versions do not.

Where the code runs: platform and arch

process.platform reports the operating system as a short string, and process.arch reports the CPU architecture. Together they let you branch on the host environment—for choosing a binary, a path separator strategy, or a platform-specific shell.

PropertyExample valuesMeaning
process.platformlinux, darwin, win32, freebsdOperating system identifier
process.archx64, arm64, ia32, armCPU architecture
import process from "node:process";

if (process.platform === "win32") {
  console.log("Running on Windows");
} else {
  console.log(`Running on ${process.platform} (${process.arch})`);
}

Output:

Running on linux (x64)

darwin is macOS and win32 is Windows (even on 64-bit systems—the name is historical). For OS-specific logic, prefer the node:os and node:path modules where possible; they abstract many differences for you.

The working directory: cwd() and chdir()

process.cwd() returns the absolute path of the directory from which the process was launched (or the directory it has since changed to). This is distinct from a module’s own location (import.meta.dirname / __dirname)—cwd() depends on where the user ran the command, not where your file lives. process.chdir(directory) changes the current working directory at runtime.

import process from "node:process";

console.log("Started in:", process.cwd());

process.chdir("/tmp");
console.log("Now in:   ", process.cwd());

Output:

Started in: /home/dev/app
Now in:    /tmp

Use cwd() to resolve paths the user typed relative to their shell, and use __dirname/import.meta.dirname to resolve files that ship with your code. Calling chdir() with a non-existent directory throws, so wrap it in a try/catch if the path is user-supplied.

Memory and uptime: memoryUsage() and uptime()

process.memoryUsage() returns an object describing the process’s memory footprint in bytes. The most-watched field is rss (Resident Set Size, total memory held in RAM); heapTotal and heapUsed describe the V8 JavaScript heap, and external covers C++ objects bound to JS. process.uptime() returns the number of seconds the process has been running, as a float.

import process from "node:process";

const mb = (bytes) => (bytes / 1024 / 1024).toFixed(2);
const mem = process.memoryUsage();

console.log(`RSS:       ${mb(mem.rss)} MB`);
console.log(`Heap used: ${mb(mem.heapUsed)} MB`);
console.log(`Uptime:    ${process.uptime().toFixed(1)} s`);

Output:

RSS:       42.18 MB
Heap used: 4.73 MB
Uptime:    0.1 s

These two calls are the building blocks of lightweight health checks and metrics endpoints—sample them periodically to spot memory leaks (a steadily climbing heapUsed) or to report how long a service has been live.

A runtime report at a glance

Combining these members produces a compact diagnostic snapshot that is handy in logs and crash reports:

import process from "node:process";

console.log({
  pid: process.pid,
  node: process.versions.node,
  platform: process.platform,
  arch: process.arch,
  cwd: process.cwd(),
  uptimeSeconds: Number(process.uptime().toFixed(2)),
});

Output:

{
  pid: 48213,
  node: '22.11.0',
  platform: 'linux',
  arch: 'x64',
  cwd: '/home/dev/app',
  uptimeSeconds: 0.12
}

Best Practices

  • Read the runtime via process.versions.node rather than parsing CLI output—it is structured and reliable.
  • Treat process.pid as a transient value for logging and signaling, not as a durable identifier.
  • Use process.platform and process.arch to branch on the host, but prefer node:os and node:path to abstract platform differences when you can.
  • Keep process.cwd() (where the command ran) distinct from import.meta.dirname/__dirname (where your file lives) when resolving paths.
  • Guard process.chdir() with error handling, since changing to a missing directory throws.
  • Sample process.memoryUsage() and process.uptime() periodically for health endpoints instead of calling them on every request.
  • Import process explicitly with import process from "node:process" for clearer, more tool-friendly code, even though it is also a global.
Last updated June 14, 2026
Was this helpful?