My app uses port 80, but heroku does not let my app access port 80. So, I used 3000 and ran it.
However, now, I cannot access it because port 3000 is not accessible in heroku. How can my app gain access to heroku?
My app uses port 80, but heroku does not let my app access port 80. So, I used 3000 and ran it.
However, now, I cannot access it because port 3000 is not accessible in heroku. How can my app gain access to heroku?
First of all, I think this is a misunderstanding regarding ports. Your app will run behind the proxy (aka load balancer), so you don't actually need to specify use 80
port (and you can't). Heroku provides env variable PORT
and you must use that port to start your application. Heroku proxy runs on 80
port (and 443, which supports SSL) and redirect all traffic to PORT
port.
Your Node.js app is improperly configured to bind to a port other than the one provided by Heroku via the
$PORT
environment variable.
Example:
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Our app is running on port ${ PORT }`);
});
Simple answer is you can't.
Heroku doesn't allow you to assign listening ports to your web apps directly. Your web apps are self contained and they will be assigned a dynamic port by Heroku. The only way to access that is to use the default port (80).