does process.env.NODE_ENV sets to 'production' automatically?
As stated here, NODE_ENV is set to production per default if you deploy it on Heroku:https://devcenter.heroku.com/articles/nodejs-support#runtime-behavior
process.env refers to the environment variables on the system. This depends a whole lot on where the application runs and how the system is configured. Herocku does not know if a specific version of your app is in test or production. So the developer has defined an environment and added 'production' as a variable in that environment.
If you use npm you can add variables with script command
{ .. "scripts": { "dev": "corss-env ENVIRONMENT=development ..", "prod": "cross-env ENVIRONMENT=production .." } ..}
and use the appropriate command as run according to setting.
Inside in your project in Heroku, you can set all environments variables.Go in your project > settings > Config Vars and set NODE_ENV production.