0

I build an app and I want to make an installer written in nodejs for this app. Installer should do : - update os - change ip / hostname - install nginx, nodejs, node additional modules(pg,pm2,...), postgresql - download app from git hub - make director for config files - run app with pm2

I search on the internet and i found child_process from node and i tried to run bash commands with it but i receive ENOENT error on commands like "apt-get update" ,"apt-get install node".. Seems the function from child_process work only on simple commands like : "ls","pwd". Do you have any advice for me? It is good strategy to make app installer in nodejs or use pure bash commands? Thank you in advice.

dudufx
  • 121
  • 1
  • 3
  • 13
  • The child_process library can be used to run any external command or program. The last part of your question seems to be purely a call for opinions on different ways to build an installer which is off-topic for stack overflow. There are hundreds of ways to write an installer. Which is best for any specific situation is not an absolute and depends upon the situation and your own opinions. As it stands now, it's hard to figure out what on-topic question you are actually asking. – jfriend00 Oct 22 '17 at 16:30
  • Have you seen this? https://stackoverflow.com/questions/44647778/how-to-run-shell-script-file-using-nodejs – Buddhi Oct 22 '17 at 16:30
  • If you want to ask about why you get ENOENT errors when trying to run bash commands, then rewrite your question to show the code you were using and describe exactly what errors you got back and where and people can help you solve that specific coding problem. That type of question would be on-topic for stack overflow, but not a rambling question that asks for opinions about a bunch of things with no specific details. – jfriend00 Oct 22 '17 at 16:32
  • I solve the issue. I send the issue as a string. The good way is to send "sudo" as main command and "apt-get" "update" asi options. – dudufx Oct 22 '17 at 16:35
  • If you have solved your own question and the answer would be useful as a general reference to others, then you can write your own answer here. Otherwise, you can delete your question. Please do one or the other top finish off this question. – jfriend00 Oct 22 '17 at 16:36

1 Answers1

0

The error appear because I sent to spawnSync all bash command as a string. The correct way is

let cmd = spawnSync("sudo", ["apt-get","upgrade"]);
dudufx
  • 121
  • 1
  • 3
  • 13
  • Since you didn't show your original code in the question, nobody but you could possibly have answered this. (If you had been calling something that spawned a shell, such as `child_process.exec`, a single string would be correct; with `spawn`, by contrast, you're directly invoking the executable with no shell involved -- meaning what you're running *isn't* a "bash command" at all). – Charles Duffy Oct 22 '17 at 16:45