John Anderson John Anderson - 1 year ago 103
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) {


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download