Skip to content

Instantly share code, notes, and snippets.

@alber999
Created January 27, 2016 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alber999/c8169e2aa6394c58945e to your computer and use it in GitHub Desktop.
Save alber999/c8169e2aa6394c58945e to your computer and use it in GitHub Desktop.
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