Node.js platform/arch possible values | Jacob Hummer
The official Node.js docs (v25.2.1) say that process.platform can be 'aix' | 'darwin' | 'freebsd' | 'linux' | 'openbsd' | 'sunos' | 'win32' and process.arch can be 'arm' | 'arm64' | 'ia32' | 'loong64' | 'mips' | 'mipsel' | 'ppc64' | 'riscv64' | 's390' | 's390x' | 'x64'. That's not quite true. This is my chronicle for future me.
TL;DR:
node:process platform & node:os platform(): "netbsd", "os390", "win32", "darwin", "sunos", "freebsd", "openbsd", "linux", "android", "aix", "os400", "ios", "openharmony", "emscripten", "wasm", "wasi", "cloudabi"
node:process arch & node:os arch(): "s390x", "arm64", "arm", "ia32", "mipsel", "mips", "mips64el", "ppc64", "x64", "riscv64", "riscv32", "loong64"
node:os machine(): x86_64, ia64, i386, i486, i586, i686, mips, alpha, powerpc, sh, arm, unknown on Windows; ppc64 or any uname -m value on Unix.
node:process platform & node:os platform()
The Node.js process object is defined across some C++ files as a global object. The node:process module just reexports it with all the appropriate named properties. This means there's nothing to see in lib/process.js
lib/process.js
'use strict';
// Re-export process as a built-in module<br>module.exports = process;
Instead, we have to jump to the src/node_*.cc files to see anything that defines process.* properties & methods. Don't worry about where and how this v8 process object gets set as a global variable; that's not important right now.
src/node_process_object.cc
// process.platform<br>READONLY_STRING_PROPERTY(process, "platform", per_process::metadata.platform);
What's this per_process::metadata struct? Where is it defined? It must be some kind of singleton/constant since it's being used to access .platform as a property. Sure enough, it is!
src/node_metadata.h
// Per-process global<br>namespace per_process {<br>extern Metadata metadata;
src/node_metadata.cc
namespace per_process {<br>Metadata metadata;
node::Metadata is a class that has a single constructor that sets .arch and .platform (std::string-s) to some #define-ed macro string literals.
src/node_metadata.h
class Metadata {<br>public:<br>Metadata();<br>Metadata(Metadata&) = delete;<br>Metadata(Metadata&&) = delete;<br>Metadata operator=(Metadata&) = delete;<br>Metadata operator=(Metadata&&) = delete;
struct Versions {<br>// -- โ๏ธ SNIP --
Versions versions;<br>const Release release;<br>const std::string arch;<br>const std::string platform;<br>};
src/node_metadata.cc
Metadata::Metadata() : arch(NODE_ARCH), platform(NODE_PLATFORM) {}
So far we know that node.platform is set to whatever value NODE_PLATFORM is set to. Where is that set? It's set by the GYP build system configuration.
'target_name': ',<br>'type': 'executable',
'defines': [<br>'NODE_ARCH=",<br>'NODE_PLATFORM=", # ๐<br>'NODE_WANT_INTERNALS=1',<br>],
# -- โ๏ธ SNIP --
What's this OS variable? Where does it come from? It is a GYP predefined variable. I don't really know if you're supposed to manually set it or if it's inferred from your host platform.
OS: The name of the operating system that the generator produces output for. Common values for values for OS are:
'linux'
'mac'
'win'
But other values may be encountered and this list should not be considered exhaustive.
โ GYP input format reference docs
There are other files that appear to overwrite the value of NODE_PLATFORM to other values that are more specialized than just .
node.gypi
[ 'OS=="win"', {<br>'defines!': [<br>'NODE_PLATFORM="win"',<br>],<br>'defines': [<br>'FD_SETSIZE=1024',<br># we need to use node's preferred "win32" rather than gyp's preferred "win"<br>'NODE_PLATFORM="win32"', # ๐<br>'_UNICODE=1',<br>],<br># -- โ๏ธ SNIP --
node.gypi
[ 'OS=="mac"', {<br># linking Corefoundation is needed since certain macOS debugging tools<br># like Instruments require it for some features. Security is needed for<br># --use-system-ca.<br>'libraries': [ '-framework CoreFoundation -framework Security' ],<br>'defines!': [<br>'NODE_PLATFORM="mac"',<br>],<br>'defines': [<br># we need to use node's preferred "darwin" rather than gyp's preferred "mac"<br>'NODE_PLATFORM="darwin"', # ๐<br>],<br>}],
node.gypi
[ 'OS=="solaris"', {<br>'libraries': [<br>'-lkstat',<br>'-lumem',<br>],<br>'defines!': [<br>'NODE_PLATFORM="solaris"',<br>],<br>'defines': [<br># we need to use node's preferred "sunos"<br># rather than gyp's preferred "solaris"<br>'NODE_PLATFORM="sunos"', # ๐<br>],<br>}],
common.gypi
['OS == "zos"', {<br>'defines': [<br>'_XOPEN_SOURCE_EXTENDED',<br>'_XOPEN_SOURCE=600',<br>'_UNIX03_THREADS',<br>'_UNIX03_WITHDRAWN',<br>'_UNIX03_SOURCE',<br>'_OPEN_SYS_SOCK_IPV6',<br>'_OPEN_SYS_FILE_EXT=1',<br>'_POSIX_SOURCE',<br>'_OPEN_SYS',<br>'_OPEN_SYS_IF_EXT',<br>'_OPEN_SYS_SOCK_IPV6',<br>'_OPEN_MSGQ_EXT',<br>'_LARGE_TIME_API',<br>'_ALL_SOURCE',<br>'_AE_BIMODAL=1',<br>'__IBMCPP_TR1__',<br>'NODE_PLATFORM="os390"', # ๐<br>'PATH_MAX=1024',<br>'_ENHANCED_ASCII_EXT=0xFFFFFFFF',<br>'_Export=extern',<br>'__static_assert=static_assert',<br>],<br># -- โ๏ธ SNIP --
But what are the other possible values for this OS variable? We have to take a look at how GYP initializes that variable with a default value. It seems like all code paths...