Skip to content

engine io and Express on the same port #546

@dennisat

Description

@dennisat

You want to:

  • report a bug
  • request a feature
  • help how to setup my app for Heroku

Current behaviour

Hello engine io

I want to load the engineIo together with an Express application on the same port.

I managed to do that with the follow way:

import express from 'express';
const engineIo = require('engine.io');

export const serverPort = process.env.PORT || 3222;		// grab the port of the environment or use the dev 3222

const appExpress = express();
const httpServer = http.createServer(appExpress);	
const wsServer = engineIo(httpServer);
httpServer.listen(serverPort);							// here the server starts to listen

This works perfectly on my machine.
The Express application is working correctly as webserver and as api server and the services that use websockets are also working properly!

But... on production environment, in precise on Heroku, although I grap the correct port number I get the error EADDRINUSE, (error address is in use).
I am getting this error after both Express and Websocket instances are initialized (without errors).

The EADDRINUSE is a known error when you load the websocket server on a port that it is already used from another application.

This is the heroku error log:

2017-12-10T18:56:08.466921+00:00 app[web.1]: Error: listen EADDRINUSE :::8212
2017-12-10T18:56:08.466922+00:00 app[web.1]:     at Object._errnoException (util.js:1024:11)
2017-12-10T18:56:08.466923+00:00 app[web.1]:     at _exceptionWithHostPort (util.js:1046:20)
2017-12-10T18:56:08.466927+00:00 app[web.1]:     at Server.setupListenHandle [as _listen2] (net.js:1351:14)
2017-12-10T18:56:08.466928+00:00 app[web.1]:     at listenInCluster (net.js:1392:12)
2017-12-10T18:56:08.466929+00:00 app[web.1]:     at Server.listen (net.js:1476:7)
2017-12-10T18:56:08.466930+00:00 app[web.1]:     at Function.listen (/app/server/node_modules/express/lib/application.js:618:24)
2017-12-10T18:56:08.466931+00:00 app[web.1]:     at dynaNodeServer.start.then.then (/app/server/dist/index.js:10873:9)
2017-12-10T18:56:08.466931+00:00 app[web.1]:     at <anonymous>
2017-12-10T18:56:08.466932+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:188:7)

Any help is appreciated.

Setup

  • OS: heroku container
  • browser:
  • engine.io version: 3.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions