`nohup: failed to run command 'node': No such file or directory` when running script through ssh

fr flag

I have a remote server in which I serve a webserver using node (express) and nginx. I have a ./devops/ script which starts the webserver and restarts nginx. Said script works correctly if I manually connect to the instance (ssh <user>@<ip>) and then run

cd my-repo
git pull

I can not however set up a script which automates this. I tried with this script

set -euo pipefail

usage() {
  cat << EOF
Usage: ./devops/ <user@ip>
  exit -1


if [ -z $CONNECTION_STRING ]; then

cd my-repo
git pull

but it gives me nohup: failed to run command 'node': No such file or directory. This is the deploy script which I'm running locally from my machine

set -euo pipefail

lsof -ti:3000 && kill $(lsof -ti:3000)
echo bar
echo $(node -v)
nohup node runner.js &

cp devops/nginx-config $NGINX_CONFIG_PATH
nginx -t
nginx -s reload

node runner.js simply starts an express app, so nothing weird there.

What I want to achieve is very similar to this other post but no mention of this nohup + node error is given.
After looking at it I realized I'm most probably doing something wrong in how I call my deploy script but I don't really understand what it could be. In the update script I tried doing nohup ./devops/ & instead of simply ./devops/ but got the same nohup: failed to run command 'node': No such file or directory error.
If I put the content of the ./devops/ script inside the ssh ... << EOF <content here> EOF I also get the same nohup: failed to run command 'node': No such file or directory error

Switched the ssh command to

export NVM_DIR="\$HOME/.nvm"
\. "\$NVM_DIR/"
\. "\$NVM_DIR/bash_completion"
cd my-repo
git pull
nohup ./devops/ 1>api.stdout 2>api.stderr &
bd flag

Running an executable file (in this case, node) by simply giving its name without a path requires that the file lies in one of the directories specified in the environment variable PATH. The exact content of that variable tends to vary between different ways of running a shell, such as logging in interactively or starting a script. Your node executable probably lies in a directory which is listed in PATH when you log in interactively, but not if you run your script.

There are basically two ways to solve this:

  1. Set the PATH variable explicitly at the beginning of your script to include all the directories from which the script intends to run executable files. Do not forget to include /bin and /usr/bin because that's where standard commands reside. So, for example, if your node executable lies in /opt/MyPrettyDevops/bin, you would add the line

    export PATH=/bin:/usr/bin:/opt/MyPrettyDevops/bin
  2. Specify the path to the node executable explicitly, by changing the nohup line to

    nohup /opt/MyPrettyDevops/bin/node runner.js &
ffigari avatar
fr flag
That was it, I'm managing node via nvm and it seems logging in through ssh would load the bash profile, which would then load nvm and node. Had to manually load nvm and node in the script. I then had to follow the stdout / stdin suggestions for the ssh call to finish.

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.