terminalelectronnpm-start

How to run Electron app independent of terminal?


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...


Solution

  • 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: