Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get processor architecture from Node

Tags:

node.js

I know that I can get the OS details using process.platform or with the os Module, but I'd also like to know if the OS is a 32 or 64 bit flavor.

Is that possible?

like image 832
Eliseo Soto Avatar asked Oct 26 '11 01:10

Eliseo Soto


2 Answers

It's far easier than that, just use process.arch. It'll return x64 or x32 depending on the architecture.

like image 164
Luis Cuende Avatar answered Oct 03 '22 16:10

Luis Cuende


I would use process.env['MACHTYPE'] or process.env['HOSTTYPE']. If either are undefined, then check with uname -m (that is supposed to work on all POSIX systems, though the output can be any string in fact, see uname(1P)).

var exec = require('child_process').exec, arch;

exec('uname -m', function (error, stdout, stderr) { 
  if (error) throw error;
  arch = stdout;
});

Well, may be it's not quite as brief as you wish, however you would probably find a plenty of shell scripts which do just that for whatever system you are running on and you can just run such script instead. That way you will have just one thing to run and check the output of from your Node app.

Another solution would be to write a module for Node in C++ which would check for low-level system features, including the endianess and whatever else one might need to check. There plenty of example on how to check such things.

like image 34
errordeveloper Avatar answered Oct 03 '22 14:10

errordeveloper