In my Heroku environment where I deploy my NestJS application, I set all my Config Vars through the Heroku UI. I have set my NODE_ENV
config var to staging
using the Heroku UI. I've even ran this command heroku config:set NODE_ENV=staging -a <my-staging-environment
. When I run heroku config -a <my-staging-environment>
, I see that NODE_ENV
is set to staging
, but for whatever reason, when I console.log this variable from my code, it outputs development
. Below is some example code where it is logs development
as the value for NODE_ENV
in my TypeOrm configuration. This is causing the ssl
property to not get set to the correct value, and I cannot connect to my Heroku Postgres database because of it. I only intend to set it to development
for local development purposes.
require('dotenv').config();
console.log(process.env.NODE_ENV); // outputs "development" - idk where this value is coming from
console.log(process.env.DATABASE_URL); // outputs the correct value that I set in Heroku Config Vars
const typeOrmConfig: TypeOrmModuleOptions = {
type: 'postgres',
url: process.env.DATABASE_URL,
ssl: process.env.NODE_ENV !== 'development' ? { rejectUnauthorized: false } : false, // ternary evaluates to the wrong value
// ... other config options
};
I use dotenv
, and I made sure to .gitignore
my .env
file. I don't recall ever setting this variable to development
. The only place I see it set to NODE_ENV=development
in my code is in my .env-example
file. I do commit this file to source control, but it's just an example file and not a real .env
file and it shouldn't actually be being used.
Does anyone have any idea why this is happening?