Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js VSCode Debugger Missing Env Variables

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?

like image 422
Dashiell Rose Bark-Huss Avatar asked Sep 04 '26 22:09

Dashiell Rose Bark-Huss


1 Answers

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"
like image 62
Dashiell Rose Bark-Huss Avatar answered Sep 06 '26 10:09

Dashiell Rose Bark-Huss