I have created a new Express application. It generated app.js for me and I have then created the following index.js bringing in socket.io:
var app = require(\'./
I think a better way to do it is to attach the Io server to response object In the first middleware .per the way express is designed the Io server will be available to your subsequent routes.
Check this link