Platform-specific integration
Select platform-specific paths or commands when an application must integrate with the host operating system.
Node.js · Pipe
process.platform is a read-only string identifying the operating-system platform for which the Node.js binary was compiled. Common values include linux, darwin, win32, and other documented platform identifiers.
Read-only string property that identifies the operating-system platform for which the Node.js binary was compiled. Access it directly through the global process object, or import platform from node:process.
process.platformstring
console.log(`This platform is ${process.platform}`);Prints the platform identifier reported by the running Node.js process.
Select platform-specific paths or commands when an application must integrate with the host operating system.
Add diagnostic output that records the runtime platform alongside application logs.
Choose a supported implementation when behavior differs between Windows and Unix-like systems.
process.platform is a string property that identifies the operating-system platform for which the Node.js binary was compiled. Typical values include linux, darwin, win32, freebsd, aix, openbsd, and sunos.
Follow-up: How can code access it without relying on the global? Import platform from node:process, then use that binding instead of process.platform.
It returns a string rather than an enum or numeric code. The value describes the platform associated with the Node.js binary, so applications can use it when selecting platform-specific behavior.
Follow-up: What additional value may occur? Android may be returned for an Android build, but its Node.js support is experimental.
Use the property directly, for example process.platform, and compare it with documented identifiers such as 'win32' or 'linux'. The documentation also demonstrates importing platform from node:process.
Follow-up: Why should platform checks be narrowly scoped? Because behavior should be selected only where platform differences matter, while the identifier itself should not be treated as a general feature-detection mechanism.
processprocess.archnode:process