เมธอด process.arch() ใช้สำหรับดึงสถาปัตยกรรม CPU ของคอมพิวเตอร์ที่กระบวนการ Node.js ปัจจุบันกำลังถูกคอมไพล์ ค่าที่เป็นไปได้บางส่วน ได้แก่ 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 'x32', 'x64' ฯลฯ
ไวยากรณ์
process.arch()
พารามิเตอร์
เนื่องจากคืนค่าสถาปัตยกรรมสำหรับโค้ดที่กำลังคอมไพล์ จึงไม่ต้องการอินพุตใดๆ มีแต่คืนค่าชื่อสถาปัตยกรรม
ตัวอย่าง
สร้างไฟล์ชื่อ architecture.js และคัดลอกโค้ดด้านล่าง หลังจากสร้างไฟล์แล้ว ใช้คำสั่งต่อไปนี้เพื่อรันโค้ด:
node architecture.js
architecture.js
// โปรแกรม Node.js สาธิตการใช้ process.arch
// นำเข้าโมดูล process
const process = require('process');
// แสดงสถาปัตยกรรมของระบบที่กำหนด
console.log(process.arch);
ผลลัพธ์
C:\home\node>> node architecture.js x64
ตัวอย่างเพิ่มเติม
ลองดูตัวอย่างอีกหนึ่งกรณี:
// โปรแกรม Node.js สาธิตการใช้ process.arch
// นำเข้าโมดูล process
const process = require('process');
// แสดงค่าสำหรับสถาปัตยกรรมที่กำหนด
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;
// คุณสามารถเพิ่มสถาปัตยกรรมเพิ่มเติมได้หากทราบ...
default:
console.log("This architecture is unknown.");
}
ผลลัพธ์
C:\home\node>> node architecture.js This is a 64-bit extended systems