Node.js 中的 process.arch() 方法
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
ode>> 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
ode>> node architecture.js This is a 64-bit extended systems
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP