I have to configure one of the module in my application and give it a specific URL, based on the hostname. Something like http://localhost
locally and http://myapp.herokuapp.com
. I know I can just hardcode the value depending on NODE_ENV
, or even store it as an environment value and use process.env.CUSTOMVAR_HOSTNAME
. But somehow it feels wrong, since myapp
is already configured in the Heroku admin panel. And I can't use request.headers.host
since the module configuration happens at the start of the application, before any request can be handled.
Is there a way to retrieve the Heroku application name from the code ? Or from an environment variable ? I want my code to stay the same whether I'm executing code locally or on Heroku (or any other place actually).
I didn't find any way, so I created a local variable hostname
based on NODE_ENV (development
or production
) with the proper hostname value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With