Skip to content
Tutorials Center
My learning

Topics

Node.js Reference ยท process

Node.js process.platform and process.arch

Reference for process.platform and process.arch in Node.js: the operating system and CPU identifiers, possible values, and how they differ from the os module.

process.platform is a string naming the operating system Node.js was compiled for, and process.arch names the CPU architecture. They describe the Node binary that is running, which is fixed at build time, so they are cheap constants you can read at any moment.

Use them to choose a path separator convention, pick a native binary name, or skip a feature that only exists on some systems.

NODE
console.log(process.platform, process.arch); // e.g. linux x64

Try it

Node.js Detecting the platform

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Node.js Platform-specific code paths

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Syntax

NODE
process.platform: 'aix' | 'darwin' | 'freebsd' | 'linux' | 'openbsd' | 'sunos' | 'win32' | 'android'
process.arch: 'arm' | 'arm64' | 'ia32' | 'loong64' | 'mips' | 'mipsel' | 'ppc64' | 'riscv64' | 's390x' | 'x64'
Value Meaning
'win32' Windows, including 64-bit Windows (the name never changed).
'darwin' macOS.
'linux' Linux. Android builds of Node report 'android' on recent versions.
'x64' 64-bit Intel or AMD.
'arm64' 64-bit ARM, such as Apple Silicon or AWS Graviton.
'ia32' 32-bit x86.

Returns: a string. Both are read-only in practice and are set when Node is built.

Usage notes

  • win32 also means 64-bit Windows. Do not look for win64.
  • Binary architecture, not the machine. A 32-bit Node on a 64-bit machine reports ia32; Node under Rosetta on Apple Silicon reports x64. Use os.machine() for the hardware type.
  • Prefer feature detection. Check whether a file or API exists rather than assuming from the platform name.
  • Path handling. Use node:path instead of hard-coding / or \; use path.win32 and path.posix when you need one style explicitly.
  • Packages with native code pick a prebuilt binary using ${platform}-${arch} names.
  • Testing branches. Mocking process.platform for tests is possible with Object.defineProperty, but only affects code that reads it afterwards.
  • process.versions and process.release hold the version details, not the OS.