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!");
By default, Heroku runs npm start while starting deployed Node. js applications, but if you would like to run some other script from your package. json instead you just need to follow one simple step.
Heroku by default installs only the production dependencies, ignoring the development dependencies under devDependencies .
The Heroku Node. js buildpack is open source. For a better technical understanding of how the buildpack works, check out the source code at github.com/heroku/heroku-buildpack-nodejs.
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
.
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
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