process.arch() 方法用於獲取正在編譯當前 node.js 進程的計算機的 CPU 架構。一些可能的值是:'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 'x32', 'x64', 等等。
用法
process.arch()
參數
因為它返回正在編譯的代碼的體係結構。它不需要任何輸入。它隻返回架構名稱。
示例
創建一個名為 architecture.js 的文件並複製以下代碼片段。創建文件後,使用以下命令運行此代碼,如下例所示 -
node architecture.js
architecture.js
// Node.js program to demonstrate the use of process.arch
// Importing the process module
const process = require('process');
// Printing the arch of given system
console.log(process.arch);
輸出
C:\home\node>> node architecture.js x64
示例
讓我們再看一個例子。
// Node.js program to demonstrate the use of process.arch
// Importing the process module
const process = require('process');
// Printing the value for given architecture
switch(process.arch) {
case 'x32':
console.log("This is a 32-bit extended systems");
break;
case 'x64':
console.log("This is a 64-bit extended systems");
break;
case 'arm':
console.log("This is a 32-bit Advanced RISC Machine");
break;
case 'arm64':
console.log("This is a 64-bit Advanced RISC Machine");
break;
case 'mips':
console.log("This is a 32-bit Microprocessor without " + "Interlocked Pipelined Stages");
break;
case 'ia32':
console.log("This is a 32-bit Intel Architecture");
break;
case 'ppc':
console.log("This is a PowerPC Architecture.");
break;
case 'ppc64':
console.log("This is a 64-bit PowerPC Architecture.");
break;
// You can add more architectures if you know...
default:
colsole.log("This architecture is unknown.");
}
輸出
C:\home\node>> node architecture.js This is a 64-bit extended systems
相關用法
- Node.js process.argv()用法及代碼示例
- Node.js process.argv0()用法及代碼示例
- Node.js process.abort()用法及代碼示例
- Node.js process.allowedNodeEnvironmentFlags用法及代碼示例
- Node.js process.stdin用法及代碼示例
- Node.js process.noDeprecation用法及代碼示例
- Node.js process.setUncaughtExceptionCaptureCallback()用法及代碼示例
- Node.js process.getgid()用法及代碼示例
- Node.js process.setgid()用法及代碼示例
- Node.js process.getuid()用法及代碼示例
- Node.js process.report.reportOnSignal用法及代碼示例
- Node.js process.report.directory用法及代碼示例
- Node.js process.emitWarning()用法及代碼示例
- Node.js process.getgroups()用法及代碼示例
- Node.js process.nextTick()用法及代碼示例
- Node.js process.chdir()用法及代碼示例
- Node.js process.umask()用法及代碼示例
- Node.js process.setegid()用法及代碼示例
- Node.js process.cpuUsage()用法及代碼示例
- Node.js process.report.signal用法及代碼示例
注:本文由純淨天空篩選整理自Mayank Agarwal大神的英文原創作品 process.arch() Method in Node.js。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。