Reputation: 52510
Is there some variable or function I can call to know if a node.js application is running inside Heroku? Something like:
if (process.heroku)
console.log("I'm in Heroku!");
Upvotes: 11
Views: 2422
Reputation: 3601
You can do this without setting custom environment variables. You can do it like this:
if (process.env._ && process.env._.indexOf("heroku") !== -1)
console.log("I'm in Heroku!");
This is possible because on a Heroku dyno the _
environment variable is set to /app/.heroku/node/bin/node
.
Upvotes: 12
Reputation: 21
On this specific case I've used if test -d /app; then npm run build; fi
which can be used also inside npm-scripts.
Upvotes: 0
Reputation: 488
You use for that usual environment variables. Just set some variable on your heroku instance and check this:
process.env.HEROKU
On the heroku cli you would do:
heroku config:set HEROKU=true
You can also set it on the web interface, see heroku docs for more: https://devcenter.heroku.com/articles/config-vars
Upvotes: 13