Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run npm in a shell script

In a continuous deployment context I have a shell script executed to update and restart my app in the remote server

the script is:

ssh user@myserver <<'ENDSSH'
cd /opt/myapp
git pull
npm i
forever stop src
npm run staging
ENDSSH

the output is:

stdin: is not a tty
Already up-to-date.
-bash: line 3: npm: command not found
-bash: line 4: forever: command not found
-bash: line 5: npm: command not found

Note:

  • everything work if I ssh onto the remote server and enter those commands manually

  • node and npm are installed with nvm on the remote server which npm give /root/.nvm/versions/node/v6.10.0/bin/npm

like image 536
Jordane Avatar asked Apr 13 '17 14:04

Jordane


1 Answers

I was facing same problem in jenkins.

Following lines was on bottom of .bashrc file , I just put top of .bashrc file

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
like image 106
Shree Prakash Avatar answered Oct 11 '22 20:10

Shree Prakash