Reputation: 21836
How do I check within my Node / Express app if it is running within Heroku?
My understanding is that .env files don't work in Heroku. So this line will crash the app in Heroku. So, I want to prevent running this within a Heroku environment.
const dotenv = require('dotenv');
dotenv.config();
Upvotes: 0
Views: 295
Reputation: 18939
One way you can do it is to create an environment variable called IS_HEROKU
. On Heroku that's done in the app's dashboard, in the Settings tab, under Config Variables. Add IS_HEROKU: true
. You can also use the CLI:
heroku config:set IS_HEROKU=true
It's described here.
You will now have access to it with process.env.IS_HEROKU
. The value is a string.
I feel is simpler to use environment variables this way compared to using dotenv. If it was my project I would specify all the environment variables this way.
Upvotes: 3