Nodejs, Find 32 or 64-bit in windows/Linux

We sometimes need to know whether NodeJS is installed on the 32-bit or `64-bit version on 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

You can also check other posts on npm command deprecate option is deprecated

Node REPL to Check 32-bit or 64-bit

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.

There are two ways to know the bit version.

First way, Type node in the 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 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',

or 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.

Find 32-bit or 64-bit using JavaScript code

First, using the OS inbuilt module, import it using the required keyword OS has an arch() method that returns process architecture information.

const os = require("os");
console.log(os.arch());

The second way is using the process global object with the arch property.

console.log(process.arch);

Finally, using the process.envreturns 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.