
We sometimes need to know whether NodeJS is installed on 32-bit or 64-bit Windows, Linux, Mac, and Ubuntu PCs.
32 bit is 4 bytes of data, 64 bit is 8 bytes of data memory allocated, so Each machine has a different architecture to store and process the data.
Nodejs offers multiple ways to know it.
- using REPL
- Javascript programming
Check 32 bit or 64 bit using REPL
REPL
is a console for NODEJS to execute commands.
It is like a windows command prompt or Linux shell prompt.
It comes with a default installation of the Nodejs platform.
First way,
Type node in command prompt to get into REPL
mode.
You will get REPL mode in interactive mode.
Nodejs provides an OS module to get current installed machine information. arch() function returns current system CPU information, return values are x32, x64.
C:\Users\Kiran>node
>
>
> require('os').arch()
'x64'
The second way, using a global process object, get the current node process information. It is not required to import the module as it is a global object.
C:\Users\Kiran>node
>process.env
And it outputs a lot of processes meta data environment information. One of the properties is PROCESSOR_ARCHITECTURE and its value tells about 64bit or not.
Platform: 'MCD',
platformcode: 'KV',
PROCESSOR_ARCHITECTURE: 'AMD64',
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 is a 32
for 32-bit machine, or x64
for 64bit machines
Find 32 bit or 64 bit using JavaScript
First, using OS inbuilt module, import it using require keyword using arch() method return process architecture
const os = require('os');
console.log(os.arch());
Second way is using process global object with arch property
console.log(process.arch);
Finally, using process.env
returns process meta information
console.log(process.env.PROCESSOR_ARCHITECTURE) //returns AMD64 or IA32
Conclusion
To summarize, Nodejs offers many ways to get process current machine information, either REPL command or Javascript code.