SSH command works manually but not in SSH node


When I connect via the SSH module, and issue the command “node /root/scraping/scrape-new.js” or variations thereof, I receive the error below.

When I connect to the server via my terminal and run the same command, it works.

/root/scraping/scrape-new.js:63\n})().catch(err => console.error(err)). finally(() => browser ?. close());\n ^\n\nSyntaxError: Unexpected token .\n at Module._compile (internal/modules/cjs/loader.js:723:23)\n at Object.Module._extensions…js (internal/modules/cjs/loader.js:789:10)\n at Module.load (internal/modules/cjs/loader.js:653:32)\n at tryModuleLoad (internal/modules/cjs/loader.js:593:12)\n at Function.Module._load (internal/modules/cjs/loader.js:585:3)\n at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)\n at startup (internal/bootstrap/node.js:283:19)\n at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

The workflow is below. The SSH1 node works, issuing the command “dropbox start”. So my connection is good and my login has the correct permissions etc.

The 2nd SSH node doesn’t work. I have tried it with a slash in the “Working Directory” field and without. I have tried putting the full path to the file in the “Working Directory” field. Lastly I have tried putting the path to the folder the “scrape-new.js” file is in, and doing the “ls” command, and the output shows that I am in fact in the correct folder. I’m not sure what else to try.

Hey @mmac,

Looking at the error it is not an n8n one and it is coming back from your script, I am not sure what the script it is doing so it isn’t something I can really debug but for reference when we make an SSH connection it is non-interactive so sometimes the users profile isn’t fully loaded. It might be worth popping in some debug lines in the script to see if there is anything specific it is not happy with.

1 Like

I messed around with environment variables and profile and whatnot for ages, after reading up on non-interactive shells not having the same env as a user profile, but turns out the solution was much simpler.

I just needed to use the full path to node, so the working command in my case is:

/root/.nvm/versions/node/v19.3.0/bin/node /root/scraping/scrape-new.js

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.