John Anderson John Anderson - 2 months ago 5x
Node.js Question

Is starting a server inside a get request ok to do?

New to and wanted to know if starting a socket server inside of a get request is ok to do if I want to match a session id (http request) with a socket id?

app.get('/', function(req, res, next) {


io.on('connection', function (socket) {



That will attach a additional listener for every request that is made, so it is probably not such a good idea. All previous listeners for io.on('connection', ...) will be executed when the next connection is made.