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
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.
Type node in command prompt to get into
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.
And it outputs a lot of processes metadata 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',
The third way,
process.arch gives Nodejs process global objects arch gives.
node -p "process.arch"
These returns are a
32 for 32-bit machines or
x64 for 64bit machines.
First, using OS inbuilt module, import it using the required keyword using arch() method return process architecture
const os = require('os'); console.log(os.arch());
The second way is using the process global object with the arch property
process. envreturns process meta information
console.log(process.env.PROCESSOR_ARCHITECTURE) //returns AMD64 or IA32