Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Phương thức process.arch trong Node.js


Thuộc tính process.arch trả về kiến trúc CPU của máy tính nơi tiến trình Node.js hiện tại được biên dịch. Các giá trị có thể: 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 'x32', 'x64', v.v.

Cú pháp

process.arch

Tham số

Vì chỉ trả về tên kiến trúc, không cần đầu vào.

Ví dụ

Tạo file architecture.js và sao chép mã. Chạy lệnh:

node architecture.js

architecture.js

// Chương trình Node.js minh họa process.arch
const process = require('process');

// In kiến trúc
console.log(process.arch);

Kết quả

C:\home\node>> node architecture.js
x64

Ví dụ 2

Xử lý theo kiến trúc với switch-case.

// Chương trình Node.js minh họa process.arch
const process = require('process');

switch(process.arch) {
    case 'x32':
        console.log("Hệ thống 32-bit mở rộng");
        break;
    case 'x64':
        console.log("Hệ thống 64-bit mở rộng");
        break;
    case 'arm':
        console.log("Advanced RISC Machine 32-bit");
        break;
    case 'arm64':
        console.log("Advanced RISC Machine 64-bit");
        break;
    case 'mips':
        console.log("Microprocessor without Interlocked Pipelined Stages 32-bit");
        break;
    case 'ia32':
        console.log("Intel Architecture 32-bit");
        break;
    case 'ppc':
        console.log("PowerPC Architecture");
        break;
    case 'ppc64':
        console.log("PowerPC Architecture 64-bit");
        break;
    default:
        console.log("Kiến trúc không xác định.");
}

Kết quả

C:\home\node>> node architecture.js
Hệ thống 64-bit mở rộng