angry kiwi
angry kiwi

Reputation: 11475

nodejs server - mac terminal crash every one hour

I got a live server running nodejs chat app. I connect to server using terminal on mac. I start the server by typing server.js.

the problem is, my terminal always hung after one hour running, and there are no error outputs. when it hangs, I press ctrl+c I got the message [process completed].

note: My terminal runs node apps locally without any problems. And my current chat app run well when I initiate it with WinSCP in windows platform.

Upvotes: 1

Views: 688

Answers (1)

maerics
maerics

Reputation: 156534

Try launching your node process on the remote server using a tool like nohup.

bash$ nohup /path/to/node server.js > out.txt 2> err.txt &
[1] 53032
# Now you can logout of the remote server without
#   killing the "node" process and chat server.

[Edit]

Note that the number printed by "nohup" (e.g. 53032) is the id of detached process, so if you need to terminate it you can do something like "kill -9 53032". If you forgot to record that number then you'll have to find it by using a program such as "ps"; for example, you can run "ps auxwww | grep node" (the flags will vary depending on your system) and you'll see output similar to this:

maerics  81694   0.6  0.5  2543604  21216 s000  S+   10:34AM   0:09.45 /Users/maerics/opt/node/node server.js

In this example, on my system, the number in the second column is the process id.

Upvotes: 3

Related Questions