Skip to content

Instantly share code, notes, and snippets.

@milosdakic
Created September 7, 2012 06:34
Show Gist options
  • Save milosdakic/3663852 to your computer and use it in GitHub Desktop.
Save milosdakic/3663852 to your computer and use it in GitHub Desktop.
Node + Express + Cluster in CoffeeScript
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