title: Best way to set a Node/Express app to live or production mode
body: <p>I'm currently in the process of making my node/express app into a production deployment, and as part of this, I need to make it run in a production friendly mode (e.g. fewer debugs to stdOut, write logs to different places, tell users less when errors occur etc.).</p>
  
  <p>I'm struggling a bit with this, as whenever I set a variable of virtually any kind to invoke a 'production' mode, it doesn't take affect for the program as it runs.</p>
  
  <p>When launched in dev mode, my code runs through Gulp, and runs this script:</p>
  
  <pre><code>#!/usr/bin/env node
  var debug = require('debug')('ascema');
  var app = require('../app');
  
  app.set('port', process.env.PORT || 3000);
  
  var server = app.listen(app.get('port'), function() {
      debug('Express server listening on port ' + server.address().port);
  });
  </code></pre>
  
  <p>Which, as you know, is just the generated launch script from the express generator.</p>
  
  <p>In order to run it in live mode, I created an alternative startup for the server to use (I could hardly use gulp anyway) and live.js runs this:</p>
  
  <pre><code>#!/usr/bin/env node
  var app = require('./app.js');
  
  app.set('env', 'production');
  
  console.log('running on Port 3000');
  
  var server = app.listen(3000);
  </code></pre>
  
  <p>But, when I use <code>app.get('env')</code> anywhere in the app (e.g. in app.js or in it's various dependencies) it still returns 'development' and so none of my production tasks happen.</p>
  
  <p>What am I doing wrong here?</p>
  
  <p>Many thanks.</p>