title: How to run node.js process with forever and logging?
body: <p>I see here <a href="http://socket.io/docs/logging-and-debugging/" rel="nofollow">http://socket.io/docs/logging-and-debugging/</a> that if I want to run logs, I do like this: </p>
  
  <pre><code>DEBUG=* node yourfile.js
  </code></pre>
  
  <p>this works. </p>
  
  <p>But I want to also run process with forever. </p>
  
  <p><a href="https://www.npmjs.com/package/forever" rel="nofollow">https://www.npmjs.com/package/forever</a></p>
  
  <p>But now actually I do not even know if I need forever. Then intention of running forever was - if server dies - forever restarts it.</p>
  
  <p>But the problem is that server dies, clients cannot connect and forever does not restart it. Then node process is using socket.io. </p>
  
  <p>So as I understand - process is not dead, but there is something wrong inside the process - with socket.io.</p>
  
  <p>After we restart node server file, it is working again, for about 2 weeks.</p>
  
  <p>As far as I remember - I need forever to run node process in the background. Otherwise process will be stopped when I close terminal.</p>
  
  <p><strong>How do I run command</strong> </p>
  
  <pre><code>DEBUG=* node yourfile.js
  </code></pre>
  
  <p>with forever so it would log output to files?</p>
  
  <p>I tried like this</p>
  
  <pre><code>$ forever -c 'DEBUG=* node' server.js
  </code></pre>
  
  <p>but it did not work.</p>
  
  <p>Also tried like this:</p>
  
  <pre><code>forever -o out.log -e err.log my-script.js
  </code></pre>
  
  <p>But also did not work, it looks different.</p>
  
  <p>Running like this:</p>
  
  <pre><code>forever -o out.log -e err.log start my-script.js
  </code></pre>
  
  <p>starts proccess, but when I run </p>
  
  <pre><code>forever logs
  </code></pre>
  
  <p>I do not see any logs, so its no the same. </p>
  
  <pre><code>DEBUG=* node yourfile.js
  </code></pre>
  
  <p>floods many logs instantly. I am not sure if I want that much logs, but I have no idea how to solve disconnection problem.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Based on comments I tried like this:</p>
  
  <p>DEBUG=* forever start server.js > node.log</p>
  
  <p>node.log file was created, but it just has 3 lines, which means it is not the same log as is when I run </p>
  
  <p>DEBUG=* node server.js</p>
  
  <p>This is what the logs look like which I want to see in text files.</p>
  
  <pre><code>socket.io:server initializing namespace / +0ms
    socket.io:server creating engine.io instance with opts {"path":"/socket.io"} +                                                                                            5ms
    socket.io:server attaching client serving req handler +3ms
  </code></pre>