var path = require('path'),
    express = require('express'),
    ecstatic = require('ecstatic'),
    favicon = require('serve-favicon');

var cfg = require('../build.config.js');

process.title = process.env.npm_package_config_processName;

var app = express(),
    environment = process.env.npm_config_dev ? 'development' : 'production',
    port = parseInt( process.env.npm_config_port, 10 ) || process.env.npm_package_config_defaultPort;

// Set up the static directory.
var publicDir = path.join( __dirname, '..' );
if( environment === 'development' ) {
    publicDir = path.join( publicDir, cfg.build_dir );
} else {
    publicDir = path.join( publicDir, cfg.compile_dir );
}

// Use Ecstatic to serve static files.
app.use( ecstatic( { root: publicDir, gzip: true } ) );

// Favicon.
app.use( favicon( path.join( publicDir, 'assets', 'favicon.ico' ) ) );

// Index.
app.get( '/', function ( req, res ) {
    res.redirect( path.join( publicDir, 'index.html' ) );
});

// API: user.
app.get( '/api/user', function ( req, res ) {
    var userInfo = {
        username: 'testuser',
        fullName: 'Test User',
        created: new Date()
    };
    res.writeHead( 200, { 'Content-Type' : 'application/json' } );
    res.end( JSON.stringify( userInfo ) );
});

//TODO:serve favicon
//http://stackoverflow.com/questions/15463199/how-to-set-custom-favicon-in-node-js-express

// TODO:API
//require('./api/whatever')(app);

// Start the server.
var server = app.listen( port, function () {
    console.log( 'In %s mode. Listening on port %d.', environment, server.address().port );
});
@@ -17,24 +17,58 @@
 re('path'),%0A
+    cluster = require('cluster'),%0A
     express 
@@ -85,24 +85,24 @@
 'express'),%0A
-
     ecstatic
@@ -212,69 +212,8 @@
 );%0A%0A
-process.title = process.env.npm_package_config_processName;%0A%0A
 var 
@@ -1405,20 +1405,899 @@
 art 
-the server.%0A
+server with cluster%0Aif(cluster.isMaster)%7B%0A%0A    console.log('App Master Process ID is %25d',process.pid);%0A    process.title = process.env.npm_package_config_processName + '_Master';%0A    var cpuCount = require('os').cpus().length;%0A%0A%0A    // Setup some cluster handlers to handle worker events%0A    cluster.on('listening', function(worker, address) %7B%0A        //console.log(%22Worker %25d is now connected.%22, worker.id);%0A    %7D);%0A%0A    cluster.on('online', function(worker) %7B%0A        console.log(%22Worker %25d is now online.%22,worker.id);%0A    %7D);%0A%0A    cluster.on('disconnect', function(worker)%7B%0A        console.log(%22Worker %25d disconnected%22, worker.id);%0A        cluster.fork();%0A    %7D);%0A%0A    // Create a worker for each CPU%0A    for (var i = 0; i %3C cpuCount; i += 1) %7B%0A        cluster.fork();%0A    %7D%0A%7Delse%7B%0A%0A    process.title = process.env.npm_package_config_processName + '_Worker';%0A    // Start the server.%0A    
 var 
@@ -2333,24 +2333,28 @@
 nction () %7B%0A
+    
     console.
@@ -2389,16 +2389,34 @@
 on port 
+%25d with worker ID 
 %25d.', en
@@ -2447,15 +2447,42 @@
 s().port
- );%0A%7D);
+, cluster.worker.id);%0A    %7D);%0A%0A%7D%0A%0A

Set server to use Node's cluster