La aplicación NodeJS que se ejecuta en VPS (linux) falla cuando pongo mi computadora portátil a dormir

I absolutely 100% new to VPS and linux as of yesterday, and I'm running into an issue. Here's the process:

  1. I SSH into my VPS box in OSX terminal. The VPS is running CentOS 6 for what it's worth.
  2. I navigate to the correct folder and I run node app.js to launch my app in NodeJS/ExpressJS.
  3. App launches and is readily accessible via the web at my VPS' ip address + the allocated port number.
  4. If I put my laptop to sleep, the app crashes and is no longer accessible via web.

Again, being new to Linux I'm not sure how to solve this problem. It makes sense, as the terminal that was running/taking logs of the node app is no longer responding, but what I'd like is:

a) To be able to start up the app remotely then have it, until I manually stop it b) To be able to SSH back into my server intermittently to check the logs, either via my mobile phone or my laptop.

Are either of these two things possible? Clearly my protocol of launching the app via terminal (as I'd normally do if running it locally) isn't the correct way to do it but I'm having trouble finding resources telling me what to do!

EDIT: I'm actually using Node Supervisor to run the app which helps keep it up and running when things crash, not sure if that affects the situation.

preguntado el 27 de noviembre de 13 a las 04:11

1 Respuestas

Most probably your app is printing to standard out (the console), and that stream is closed/broken, when you put your laptop to sleep.

Hay al menos dos opciones:

  1. Utilice la herramienta detectar: Sólo tipo screen before starting your app. Then start your app. Then Ctrl-A-D to detach from the screen. You can then safely log out from the VPS and put your laptop to sleep. To go back to the output of your app, log back in and type screen -r

  2. Run the app in the background: node app.js &.

respondido 27 nov., 13:05

Just to clarify, with Screen do I run it from OSX or from within my SSH connection to CentOS? - JVG

From within your ssh connection on CentOS. - Christian Fritz

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.