Node.js VSCode Debugger Missing Env Variables

1.9k views Asked by At

When I run the debugger in vscode I get this error:

MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.

I realized this was because the debugger isn't getting access to my .env file. My database uri is stored in my .env file. So the debugger can't see it.

How can I give my debugger access to the my .env file variables?

1

There are 1 answers

0
Dashiell Rose Bark-Huss On BEST ANSWER

I fixed it by adding this to my launch.json file in my .vscode workspace folder. I added two values to the configurations object:

"env": { "PORT": "4000" },
"envFile": "${workspaceFolder}/backend/.env"