Skip to content

Instantly share code, notes, and snippets.

@florindumitru
Created March 21, 2018 21:49
Show Gist options
  • Select an option

  • Save florindumitru/0bdb1b81270881a1368b836fb69517dc to your computer and use it in GitHub Desktop.

Select an option

Save florindumitru/0bdb1b81270881a1368b836fb69517dc to your computer and use it in GitHub Desktop.
Run websocket (e.g socket.io) in pm2 cluster on multiple ports(for NGINX reverse proxy)
// run: pm2 start app.js -i max
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.send(process.env.NODE_APP_INSTANCE);
});
io.on('connection', function(socket){
console.log('a user connected');
});
var p = 3000 + (parseInt(process.env.pm_id) || 0);
http.listen(p, function(){
console.log('listening on *:3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment