var express = require('express');
var http = require('http');
var mongoose = require('mongoose');
var kue = require('kue');

var ds = require('./lib/data-store');

// Connect to MongoDB
mongoose.connect('mongodb://127.0.0.1/habweb');
mongoose.connection.on('open', function() {
	console.log('Connected to Mongoose');
});

// Create the job queue
var jobs = kue.createQueue();

// Create the webserver
app = express();

app.configure(function() {
	//app.use(express.logger('dev'));
	app.use(express.static(__dirname + '/public'));
	app.use('/backend', express.basicAuth(function(user, pass, callback) {
		var result = (user === 'admin' && pass === 'password');
		callback(null, result);
	}));
	app.use('/backend/queue', kue.app);
});

http.createServer(app).listen(8080);
console.log('Listening on port 8080');

ds.init();

var cluster = require('cluster');
var mongoose = require('mongoose');

//var ds = require('./lib/data-store');

var numCPUs = require('os').cpus().length;

// Connect to MongoDB
//mongoose.connect('mongodb://127.0.0.1/habweb');
//mongoose.connection.on('open', function() {
//  console.log('Connected to Mongoose');
//});

// Create the cluster
if(cluster.isMaster) { // Master process
  //ds.init();
  for(var i=0; i < numCPUs; i++) {
    cluster.fork();
  }
} else { // Worker process
  // Include express
  var express = require('express');

  // Create an express application
  app = express();

  // Configure express
  app.configure(function() {
    app.use(express.static(__dirname + '/app'));
  });

  // Bind to a port
  app.listen(8000);
}
Add node cluster to app.
Add node cluster to app.
