Heroku + node.js: I have a server which uses multiple ports. How can I get Heroku to allocate them? Heroku + node.js: I have a server which uses multiple ports. How can I get Heroku to allocate them? heroku heroku

Heroku + node.js: I have a server which uses multiple ports. How can I get Heroku to allocate them?


Okay, after doing some research I've found out that opening ports in Heroku is disabled and not allowed.

The only way around this is to use sub-domains and then in-app to use a proxy module (like subdomain-router which I use).

BUT - Heroku don't let you create sub-domains on their domain, meaning that your-app.herokuapp.com is fixed and cannot have sub-domains.
In Heroku manuals, they demand you to have your own domain and dns provider to do such thing, by creating an A-alias (CNAME) in the dns table in your domain settings, that will refer to your app herokuapp domain, and then using the command heroku domains:add to add your domain to the allowed origin list.

You can read more here. It provides all the info you need.

Hope it helped some.


I know this is an old post, but I wanted to provide an up-to-date response for reference and future use:

If you're using socket-io, binding to the same port is easy. Other websocket libs should have a similar approach (from https://github.com/socketio/socket.io#how-to-use):

In conjunction with Express Starting with 3.0, express applications have become request handler functions that you pass to http or http Server instances. You need to pass the Server to socket.io, and not the express application function. Also make sure to call .listen on the server, not the app.

const app = require('express')();const server = require('http').createServer(app);const io = require('socket.io')(server);io.on('connection', () => { /* … */ });server.listen(3000);

You'll now have http & ws traffic flowing through a single port (Heroku doesn't route http/tcp separately, if it did your websockets wouldn't work period).

I prefer this method due to environment parity & testing, i.e. no need to setup subdomains or port routing


I also learned about this today, I learned that if you run a service on a port in Heroku, you can still access it locally. Wouldn't work for above user's concern but it did fix my issue which led me to this question.