title: Setup automation for configuration files with node and angularjs
body: <p>I started an application in AngularJS couple of weeks ago. All my configuration variable are stored in a constant like this:</p>
  
  <pre><code>/**
   * defines constants for application
   */
  define(['angular'], function (ng) {
      'use strict';
      return ng.module('app.constants', [])
          .constant('CONFIG', {
              node_port: 3700,
              api_host: 'api.acme.local',
              node_host: 'acme.com',
              facebook_app_id: 'xxxxxxxxx'
          });
  });
  </code></pre>
  
  <p>The problem I have is that I need to change this value each time I want to push my application in stage. I'm using <code>rsync</code> so I could ignore this file and modify it once on the stage server. It might not be the best solution but it would work.</p>
  
  <p>Now recently I've added a <code>nodejs</code> server to my application using <code>express</code> and <code>socket.io</code>, which mean I now have to setup the client in my angularjs application and the <code>server.js</code>.
  Because I'm using <code>requirejs</code> I also need to update the path for <code>socket.io</code>.</p>
  
  <p>requirejs: </p>
  
  <pre><code>paths: {
          'jquery': 'bower_components/jquery/dist/jquery.min',
          ...
          'socketio': 'http://acme.local:3700/socket.io/socket.io'
      },
  </code></pre>
  
  <p>and my <code>server.js</code>:</p>
  
  <pre><code>var express = require('express'),
      debug = true,
      http = require('http'),
      _ = require('underscore'),
      server = express(),
      port = 3700,
      api_host = 'api.acme.local',
      io = require('socket.io').listen(server.listen(port), {log: debug});
  
  ...
  
  var options = {
      hostname: api_host,
      port: 80,
      path: '/courses',
      method: 'GET'
  };
  
  var req = http.request(options, function(res) {
      var output = '';
  
      res.setEncoding('utf8');
      res.on('data', function (chunk) {
          output += chunk;
      });
  ...
  </code></pre>
  
  <p>So basically I'm ending up with duplicated variable for my node application and angular application, plus I need to toggle values between <code>dev</code> and <code>stage</code> variables values.</p>
  
  <p>What would be the best solution to this problem?</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>Just found out that requirejs has a failover option for the path, so for now I'm using it:</p>
  
  <pre><code>paths: {
      'jquery': 'bower_components/jquery/dist/jquery.min',
      ...
      'socketio': [
          'http://stage.acme.com:3700/socket.io/socket.io',
          'http://acme.local:3700/socket.io/socket.io'
      ]
  },
  </code></pre>
  
  <p>Still investigating how to do it properly</p>