2

I am working on the Ubuntu system on Amazon Web Services EC2. I have created an instance and need to run a node.js server on the system. Once I ssh into my working directory and use the following command,

:~/Test1$ node server.js

the server works fine. The code runs without any issues

Now, what I want is to run the server.js code even when the terminal is closed, as a background process. For that, I am using nohup command with &

:~/Test1$ nohup node server.js &

This, also gets the server.js started but the nohup command seems nonfunctional since the server.js stops working when I close the terminal. I tried the code with sudo command as well

:~/Test1$ nohup sudo node server.js &

but it does nothing.

What am I doing wrong? And, how shall I get this working? Thanks.

  • you can try to just use systemd – hhoke1 Mar 25 '18 at 14:34
  • @hhoke1 had at the link, will certainly try that out. Right now, I have setup a RDP connection to the server and am useing that – pi3.14 Mar 26 '18 at 11:34
-1

I had exactly the same issue. I was running my node server as you do:

nohup node server.js &

In this way, the process is running in the terminal session, that's the reason the process lives longer as the terminal session stay opened.

Instead, try to run the process in a separated session:

setsid nohup serve.js &

Try in this way, it worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.