Search code examples
node.jsheroku

Is there a programmatic way to know a node.js app is running in Heroku?


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!");

Solution

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