Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample of NodeJS as a cluster + Express + Hogan
/*
* Cluster NodeJS + Express + Hogan
*
* "dependencies": {
* "express": "~4.13.3",
* "hogan-middleware": "*"
* }
*/
var cluster = require('cluster');
if (cluster.isMaster) {
var cpuCount = require('os').cpus().length;
for (var i = 0; i < cpuCount; i += 1) {
cluster.fork();
}
} else {
var express = require('express');
var app = express();
app.set('view engine', 'mustache');
app.engine('mustache', require('hogan-middleware').__express);
app.get('/', function (req, res) {
res.render('index',{msg:'Hello world!'})
});
app.listen(3000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment