Q:

shell check if file exist in one line with ssh, then cd, and npm install

I have these lines in my script:
ipserver=1.1.1.1
fullpathfile="/var/www/html/mysite"
ssh "root@${ipserver}" "[[ -d ${fullpathfile}/node_modules ]] echo "Directory exist" ||  cd ${fullpathfile} && npm install "

But I get this error:
Unexpected remote arg: root@1.1.1.1:/var/www/html/mysite/\#012ssh root@1.1.1.1 [[

I need to connect through ssh and then check if a folder exist (node_module), if it does not exist, then do: cd folder and npm install.
what am I doing  wrong ?

A:

Note that [[ (and [ and test) are commands like any other. So you need && to only execute the echo if the [[ succeeds.
ssh "root@${ipserver}" "[[ -d ${fullpathfile}/node_modules ]] && echo "Directory exist" || cd ${fullpathfile} && npm install "

However, enclosing a series of commands in double quotes like that can get hairy pretty fast, especially if your directory name contains spaces, or your commands need quoted arguments of their own.
To avoid headaches, better to install a little script on the server (for example, as "$HOME/bin/do_npm_install.sh") that does what you need, then invoke that with ssh, like
ssh "root@${ipserver}" "bash ~/bin/do_npm_install.sh"

