Sometimes, We need to know whether NodeJS is installed on 32 bit or 64 bit machine of a Current windows, Linux,mac and ubuntu. 32 bit is 4 bytes of data, 64 bit is 8 bytes of data memory allocated, so Each machine has different architecture to store and process the data.
Nodejs offers multiple ways to know it
REPL is an console for NODEJS to execute commands, It is like windows command prompt or Linux shell prompt. This comes with default installation of Nodejs platform
First way, To get into REPL mode, Type node in command prompt, You will get REPL mode in interactive mode.
Nodejs provides OS module, to get current installed machine information. arch() function returns current system CPU information, return values are x32, x64
Second way, using process global object , get the current node process information. it is not required to import module as it is global object.
And it outputs lot of process meta data environment information. One of the property is PROCESSOR_ARCHITECTURE and it’s value tells about 64bit or not.
PROCESSOR_IDENTIFIER: 'Intel64 Family 6 Model 78 Stepping 3, GenuineIntel',
or Third way, process.arch gives Nodejs process global objects arch gives
node -p "process.arch"
This returns ia32 for 32 machine, or x64 for 64bit machines
First, using OS inbuilt module, import it using require keyword using arch() method return process architecture
const os = require('os');
Second way is using process global object with arch property
Finally, using process.env returns process meta information
console.log(process.env.PROCESSOR_ARCHITECTURE) //returns AMD64 or IA32
Nodejs offers many ways to know about process current machine information either REPL command or Java script code.
I hope you liked :-)