2

Here I'm trying to run node file in AWS server with the ssh command through the shell script, where inside the shell file there is a command to run node file (node test.js)

Executing the below command, will run the shell file inside AWS server

ssh -i sample-test.pem ubuntu@ip 'bash -s' < my-folder/test.sh
  • test.sh file [Shell file]

    node test.js
    
  • test.js file [Node file]

    console.log("Venkatesh");
    

If I run the shell command directly inside the AWS server, node file runs perfectly. But if I run with the ssh command, it throws an error like this:

line 1: node: command not found

I have also tried from nodejs by using node-ssh package, same error occurs again.

How do I suppose to run a node file through shell script from ssh command?

13
  • did you install nodejs in? May I know what are the commands you used Commented Jun 5, 2020 at 17:22
  • Yeah! I have installed the nvm. For your reference, these are the commands I have used : sudo apt-get -y install build-essential libssl-dev curl -o- raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash export NVM_DIR="${HOME}/.nvm" [ -s "${NVM_DIR}/nvm.sh" ] && . "${NVM_DIR}/nvm.sh" [ -s "${NVM_DIR}/bash_completion" ] && . "${NVM_DIR}/bash_completion" nvm install 8 nvm use 8 Commented Jun 5, 2020 at 17:25
  • Can you please type the command node -v, npm -v Commented Jun 5, 2020 at 17:29
  • v8.17.0 - node 6.13.4 - npm Commented Jun 5, 2020 at 17:34
  • Did you defined paths in bash profile? Commented Jun 5, 2020 at 17:39

1 Answer 1

1

Thanks to ROOT

Add the node path while running the node file. The response of which node will be add to run the node file.

which node  #FULL/PATH/TO/NODE
FULL/PATH/TO/NODE test.js
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.