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.
console.log(process.platform, process.arch); // e.g. linux x64
Try it
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.
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
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
win32also means 64-bit Windows. Do not look forwin64.- Binary architecture, not the machine. A 32-bit Node on a 64-bit machine reports
ia32; Node under Rosetta on Apple Silicon reportsx64. Useos.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:pathinstead of hard-coding/or\; usepath.win32andpath.posixwhen you need one style explicitly. - Packages with native code pick a prebuilt binary using
${platform}-${arch}names. - Testing branches. Mocking
process.platformfor tests is possible withObject.defineProperty, but only affects code that reads it afterwards. process.versionsandprocess.releasehold the version details, not the OS.