Continue to live the express process after closing the terminal

I am trying to continue the process after closing the terminal. Is a node.js project with an expression. Basically, for another process, I continued to live with:

$ node server.js & 

With this, I was able to end the SSH connection and close the console. But with the expression, I started my process with:

 $ npm start & 

And always, after one request, the process died. Is there a way to keep the process alive? I am using EC2 with an instance of Ubuntu.

+8
source share
3 answers

I found the answer https://unix.stackexchange.com/questions/89483/keeping-a-process-running-after-putty-or-terminal-has-been-closed

Essentially, you can use the nohup process. (Execute commands after exiting the shell prompt).

And I used:

 $ nohup npm start & 

And now it works well.

+11
source

I know this is an old question, but for new visitors who identify with him, I’m going to go to the final destination and assume that you want to run a web application that works constantly: one that can serve visitors at your IP address , day and night. If this is not the case, then screen or nohup may work fine, but if it is, it is best to use a daemon such as pm2 or forever .

Perhaps daemons are the best way to constantly maintain the service ... for example, how does your Ubuntu instance know when you want to communicate with it through SSH? This is due to sshd, the SSH daemon. The daemon has a code that always listens, just as you would like a web application to do.

In addition, pm2 and forever have other useful features, such as reloading the daemon if a crash and reboot occurred on your computer.

+1
source

Use sceen

in your terminal:

 screen 

then

 npm start 

And cancel the session by pressing "Ctrl + a" and then "d".

Here to pin session again: Source

Powered by CentOS7

0
source

Source: https://habr.com/ru/post/1205522/


All Articles