Created
September 7, 2012 06:34
-
-
Save milosdakic/3663852 to your computer and use it in GitHub Desktop.
Node + Express + Cluster in CoffeeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cluster = require 'cluster' | |
express = require 'express' | |
workers = require('os').cpus().length | |
app = express() | |
app.get '/', (req, res) -> | |
res.send('Working!') | |
if cluster.isMaster | |
for i in [0...workers] | |
worker = cluster.fork() | |
cluster.on 'listening', (worker) -> | |
console.log 'Worker %s is listening', worker.process.pid | |
cluster.on 'death', (worker) -> | |
console.log 'Worker %s died.', worker.process.pid | |
cluster.on 'disconnect', (worker) -> | |
console.log 'The worker #' + worker.id + ' has disconnected' | |
else | |
app.listen 5000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment