1

I am looking for a way to run an Electron app (npm startcommand) independently of the terminal itself. Meaning that I expect the Electron app to keep running even if the terminal closes..

I am not sure whether it is possible.

I have tried cd electron-directory-path && nohup npm start &, but this though allows me to use the terminal instance for other commands and prevents any electron messages from popping up in the terminal. But, closing the terminal still kills the Electron app.

Even cd electron-directory-path && npm start & does the same thing, but I haven't yet been able to find a way to run the Electron app completely independent of the terminal instance...

Martin Medro
  • 137
  • 9

2 Answers2

2

You start an Electron app through nohup npm start &, but when closing the terminal window, the Electron app also terminates (against expectation).

I can reproduce the behavior, but not all the times. In roughly 30% of my experiments, the Electron app was not terminated. I was not able to find the reason for this varying behavior yet.

Workaround

The following workaround closes the terminal without terminating the Electron app. In my tests, it has worked every time:

  • Start the Electron app as before: nohup npm start &

  • Close the running terminal by issuing nohup kill $$ &

    The $$ gives the current process id. Note that kill $$ doesn't work.


If you don't necessarily need to run from a terminal, you can also create a desktop file to start the app.

snwflk
  • 3,341
  • 4
  • 25
  • 37
  • In my case, it terminates every time the terminal is closed. Moreover, not just Electron, any app run in a similar fashion closes on terminal close. Thanks for the answer, it worked!! – Martin Medro Aug 31 '20 at 07:50
0

Let pathname be the path to the node app location. Just use the command:

cd pathname && npm start && ^Z &


  • cd to change directory to where we need to execute the terminal command.
  • && to mean there are other commands to be executed after this one.
  • npm start to start npm app
  • ^Z to suspend the process running in the terminal, and hence disconnect the terminal part of node from the original app.
  • & to mean that we don't want the terminal to wait for the command to execute.

Now we can close the terminal, and the electron app should keep running...!


Credits:

Martin Medro
  • 137
  • 9