'timeout doesn't work with nvm: nvm no such file or directory

I want to set timeout for each instance of node.js running. but when I run the following commands I got the error timeout: failed to run command ‘nvm’: No such file or directory:

timeout 10 nvm run 17.9.0 file1.js 
timeout 5 nvm run 17.1.0 file2.js 

but running the below commands ends without any error or problem:

timeout 10 ping 8.8.8.8

nvm run 17.9.0 file1.js

what is the matter?



Solution 1:[1]

Try to run the nvm command in interactive shell:

timeout 10 bash -ic "nvm run 17.9.0 file1.js"

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 Markus