process.platform屬性是流程模塊的內置應用程序編程接口,用於獲取操作係統平台信息。
用法:
process.platform
返回值:此屬性返回代表操作係統平台的字符串。返回值可以是“ aix”,“ android”,“ darwin”,“ freebsd”,“ linux”,“ openbsd”,“ sunprocess”和“ win32”之一。該值在編譯時設置。
以下示例說明了Node.js中process.platform屬性的用法:
範例1:
// Node.js program to demonstrate the
// process.platform Property
// Include process module
const process = require('process');
// Printing process.platform property value
console.log(process.platform);
輸出:
win32
範例2:
// Node.js program to demonstrate the
// process.platform Property
// Include process module
const process = require('process');
// Printing process.platform property value
var platform = process.platform;
switch(platform) {
case 'aix':
console.log("IBM AIX platform");
break;
case 'darwin':
console.log("Darwin platfrom(MacOS, IOS etc)");
break;
case 'freebsd':
console.log("FreeBSD Platform");
break;
case 'linux':
console.log("Linux Platform");
break;
case 'openbsd':
console.log("OpenBSD platform");
break;
case 'sunos':
console.log("SunOS platform");
break;
case 'win32':
console.log("windows platform");
break;
default:
console.log("unknown platform");
}
輸出:
windows platform
注意:上麵的程序將通過使用 node filename.js
命令。
參考: https://nodejs.org/api/process.html#process_process_platform
相關用法
注:本文由純淨天空篩選整理自anwesha0107大神的英文原創作品 Node.js | process.platform Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。