-1

I'm trying to run a command that depends on nodejs 14 as a child process of my script. For that I use nvm.

Here is my code:


let ex = require("child_process").execSync;

ex( "nvm use 14 & mycommand" );

When I launch my script, I get the message "nvm: command not found".

I use zsh on Archlinux.

Please how can I fix my issue ?

Archnim
  • 11
  • 1
  • Install `nvm` into the PATH of the user executing the script, perhaps? However this isn’t the right way to set minimum runtime versions - see [this SO thread](https://stackoverflow.com/questions/29349684/how-can-i-specify-the-required-node-js-version-in-package-json) – esqew Mar 28 '22 at 23:31
  • Thank you . I can't add nvm to my path, it doesn't correspond to any program in my bin directory. I can't even locate it with `which nvm`. I'm now trying the method in the thread that you suggested. – Archnim Mar 28 '22 at 23:39
  • 1
    Why are you trying to invoke it if you don’t have it installed anywhere…? – esqew Mar 28 '22 at 23:51
  • It's installed. Even though the executable is no where, the nvm command is available on my terminal, but not in a script file. Just install nvm by your side, you will see the same strange phenomenon. – Archnim Mar 28 '22 at 23:55
  • Even the way nvm is installed is strange: you don't just do something like `npm i -g nvm`, you need to download a bizarre script and run it. – Archnim Mar 28 '22 at 23:58

1 Answers1

1

Finally this works for me:

ex( "source path/to/nvm.sh && nvm use 14 && mycommand" )

Tedious but effective.

Archnim
  • 11
  • 1