I think the problem is misunderstanding that the shell executing the node has a complete environment such as an interactive ssh session. Most likely, this is not so.
When an SSH session spawns a shell, it goes through many cycles to create an environment suitable for interactive interaction. Things like inheriting the login process, reading /etc/profile , reading ~/.profile . But in cases where your bash launch is direct, this is not always guaranteed. In fact, $PATH can be completely empty.
When /usr/bin/env node is executed, it searches for a node in your $PATH , which in the non-interactive shell can be anything or empty.
On most systems, by default PATH=/bin:/usr/bin usually /usr/local/bin not included in the default environment.
You can try to force login using ssh to use ssh โฆ '/bin/bash -l -c "โฆ"' .
You can also write a specialized script on a server that knows how the environment should work outside the interactive shell:
#!/bin/bash # Example shell script; filename: /usr/local/bin/my_script.sh export PATH=$PATH:/usr/local/bin export NODE_PATH=/usr/local/share/node export USER=myuser export HOME=/home/myuser source $HOME/.nvm/nvm.sh cd /usr/bin/share/my_script nvm use 0.12 /usr/bin/env node ./script_name.js
Then call it via ssh: ssh โฆ '/usr/local/bin/my_script.sh' .
Besides these ideas, I donโt see how to help further.
source share