How to handle HTTP upgrade in ExpressJS?

Since my comment seemed to work for you, I'll put it in an answer.

express.createServer() has been deprecated for a long time and removed from Express 4. You would create the app object in Express 4 with:

var app = express()

The http server object is then returned from

var server = app.listen(...)

If you need direct access to the http server object.


Create a HTTP server with an express app:

const app = express()

const server = http.createServer(app);

server.on('upgrade', function (req, socket, head) {
  // ...
});

server.listen(5000);

see https://github.com/expressjs/express/issues/2556#issuecomment-75310480