title: Node.js setup for easy deployment and updating
body: <p>We're currently developing a website (TYPO3 under Apache) for a customer that is supported by a node.js/socket.io application that provides realtime updates to the content served from the CMS.</p>
  
  <p>As this is our first node.js project I don't have any best practices to go by when it comes to 'the perfect setup' so I've spent some time researching deployment techniques.</p>
  
  <p>A couple of questions remain for me to achieve a good setup which:</p>
  
  <ol>
  <li><p><strong>Is easy for the customer to deploy</strong>. This is very important because our website will be integrated in their 'live' TYPO3 installation which serves an abundance of websites and is running on servers which aren't managed by the customer but another (centralized) organization which makes support calls and server changes a slow process.</p></li>
  <li><p><strong>Should be easy to update.</strong> As mentioned requesting restarts and making server changes is a slow process, so idealy the node installation should restart / update when it receives changes that are pushed onto the live installion using <code>git</code>.</p></li>
  </ol>
  
  <p><strong>Deployment</strong></p>
  
  <p>The <a href="https://stackoverflow.com/questions/4681067/how-to-deploy-node-js">general consensus</a> seems to be to use <code>forever</code> when it comes to deploying node applications to keep them running. I've tested <code>forever</code>, and it seems to work fine when installed by <code>npm install forever -g</code> (global). This would require external assistance to globally install on the live environment though, so I'd prefer to have it running from the application's <code>node_modules</code> directory, but I haven't been able to create a solid wrapper to do so.</p>
  
  <p>Additionally, <code>forever</code> works fine, but it has to be started manually. What would be the best approach to ensure that it gets started on server boot and keeps running? </p>
  
  <ul>
  <li>A simple <code>init.d</code> script?</li>
  <li>Writing a watchdog wrapper?</li>
  <li>A TYPO3 scheduler task that checks <code>forever</code> status?  </li>
  </ul>
  
  <p><strong>Rapid development / Restart on update</strong></p>
  
  <p>We're currently still in the development stage of the project and every time I make changes to the node.js application I manually restart <code>node</code> or <code>forever</code>. This works, but is far from ideal.
  There are several smaller <code>npm</code> modules that check for file modifications and restart <code>node</code> upon detected changes, like:</p>
  
  <ul>
  <li><a href="http://remysharp.com/2010/10/12/nodejs-rapid-development-nodemon/" rel="nofollow noreferrer">Nodemon</a></li>
  <li><a href="http://fgnass.posterous.com/nodejs-supervisor" rel="nofollow noreferrer">Node.js Supervisor</a></li>
  <li><a href="https://github.com/weepy/bounce" rel="nofollow noreferrer">Bounce</a></li>
  <li><a href="https://stackoverflow.com/a/2929366/813718">Nodules</a> (which doesn't require restarting node, so might be easier to combine with <code>forever</code>)</li>
  <li><a href="https://github.com/LearnBoost/up" rel="nofollow noreferrer">Up</a> </li>
  </ul>
  
  <p>Does anyone have experience with any of these?</p>
  
  <p><strong>Update: Why don't you just use Cluster?</strong></p>
  
  <p>The <a href="https://github.com/LearnBoost/cluster" rel="nofollow noreferrer">Cluster module</a> provides similar functionality through the <a href="http://learnboost.github.com/cluster/docs/reload.html" rel="nofollow noreferrer">reload</a> mechanism, but <a href="https://github.com/kriszyp/multi-node/issues/14" rel="nofollow noreferrer">doesn't work with Node 0.5+</a>. The <a href="http://nodejs.org/api/cluster.html" rel="nofollow noreferrer">core Cluster module (Node 0.6+)</a> that replaced it doesn't have all these features but only provides clustering. Which in turn <a href="https://github.com/LearnBoost/cluster/issues/95" rel="nofollow noreferrer">doesn't play well with socket.io</a>. At least <a href="https://stackoverflow.com/questions/8395407/using-socket-io-with-cluster">not without using Redis</a> (which is a problem for us, because we can't force another prereq service to the customer).  </p>
  
  <p>--</p>
  
  <p>Obviously I'm trying to find the most stable solution that combines an update-restarter with <code>forever</code> before handing over the project to the customer and I'm really hoping anyone has produced a proven combination of techniques.</p>