process.platform


process.platform 属性返回一个字符串,用于标识 Node.js 二进制文件编译所针对的操作系统平台。

【The process.platform property returns a string identifying the operating system platform for which the Node.js binary was compiled.】

目前可能的值是:

【Currently possible values are:】

  • 'aix'
  • 'darwin'
  • 'freebsd'
  • 'linux'
  • 'openbsd'
  • 'sunos'
  • 'win32'
import { platform } from 'node:process';

console.log(`This platform is ${platform}`);const { platform } = require('node:process');

console.log(`This platform is ${platform}`);

如果 Node.js 构建在 Android 操作系统上,也可能返回值 'android'。然而,Node.js 对 Android 的支持 是实验性的

【The value 'android' may also be returned if the Node.js is built on the Android operating system. However, Android support in Node.js is experimental.】