Node.js VSCode 调试器缺少环境变量
Node.js VSCode Debugger Missing Env Variables
当我在 vscode 中 运行 调试器时,我得到这个错误:
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.
我意识到这是因为调试器无法访问我的 .env
文件。我的数据库 uri 存储在我的 .env
文件中。所以调试器是看不到的。
如何让我的调试器访问我的 .env
文件变量?
我通过将此添加到 .vscode
工作区文件夹中的 launch.json
文件来修复它。我向配置对象添加了两个值:
"env": { "PORT": "4000" },
"envFile": "${workspaceFolder}/backend/.env"
当我在 vscode 中 运行 调试器时,我得到这个错误:
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.
我意识到这是因为调试器无法访问我的 .env
文件。我的数据库 uri 存储在我的 .env
文件中。所以调试器是看不到的。
如何让我的调试器访问我的 .env
文件变量?
我通过将此添加到 .vscode
工作区文件夹中的 launch.json
文件来修复它。我向配置对象添加了两个值:
"env": { "PORT": "4000" },
"envFile": "${workspaceFolder}/backend/.env"