Home > Back-end >  "process.arch" returns wrong value when Node script is run through Ruby
"process.arch" returns wrong value when Node script is run through Ruby

Time:07-29

On my Mac with an Apple M1 chip, in a Node script, process.arch returns arm64 as expected, with the following code in script.js:

console.log(process.arch);

Then, I run the Node script through Ruby, with:

`/usr/local/bin/node "script.js"`

Where the backticks run the command in the terminal, and returns the output. But this time, it outputs x64.

How can I force process.arch to return arm64 instead, when ran through Ruby? I tried the following, but it wouldn't let me override the read-only property of arch:

process.arch = 'arm64';

console.log(process.arch);

I need to get process.arch to output arm64, rather than use any workarounds, because I am using some popular Node packages that call process.arch.

CodePudding user response:

I managed to resolve the issue, thanks to the help of the comment from Keith, regarding using the arch command with arguments.

Essentially, where I previously had:

`/usr/local/bin/node "script.js"`

I now have:

`arch -arm64 /usr/local/bin/node "script.js"`

And it works perfectly.

  • Related