Retrieve local and heroku application hostname outside a request


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 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 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).

Problem courtesy of: DjebbZ


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.

Solution courtesy of: DjebbZ


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.