How do I set the correct port in a Scala app?

Issue

Your app is failing to start as it did not bind to the correct port.

Resolution

Scala apps on Heroku need to bind to the value given by the PORT environment variable. This is set to a randomly chosen port each time the dyno boots up.

To read this when running on Heroku, but fall back to a known port when running locally you can use the following:

    val port = Properties.envOrElse("PORT", "8080").toInt

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support