Dotenv from NPM & MONGO_URL not being set

Has anyone here gotten the npm version of dotenv working with the MONGO_URL env var?

I have dotenv working, but seems like there is something overwriting MONGO_URL back to the localhost path. Is there any way around this?

1 Like

Looks like
Meteor is overwriting it at some point on start up. I saw the cat workout which will probably work for us, but I’ll keep digging into how Meteor sets that var and when.

So what’s happening in case anyone is looking at the later.

MONGO_URL is set on dev build via the shell function. Dotenv does not support overwriting env vars.

Here’s what I did to fix. I made a env.ts file in my server folder that’s loaded first thing.

  path: `${process.env.PWD}/config/${process.env.ENV}.env`,

const envConfig = dotenv.parse(

process.env.MONGO_URL = envConfig.MONGO_URL

This first loads dotenv, reads it, the overwrites MONGO_URL. I should note that the whole process.env.EVN thing is to have two separate env files prod.env and dev.env in a folder named config.

1 Like