'nvm in child process

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 ?



Solution 1:[1]

Finally this works for me:

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

Tedious but effective.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Archnim