Das*_*uss 4 environment-variables node.js visual-studio-code dotenv
当我在 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.
Run Code Online (Sandbox Code Playgroud)
我意识到这是因为调试器无法访问我的.env文件。我的数据库 uri 存储在我的.env文件中。所以调试器看不到它。
如何让调试器访问我的.env文件变量?
launch.json我通过将其添加到工作区文件夹中的文件中来修复它.vscode。我向配置对象添加了两个值:
"env": { "PORT": "4000" },
"envFile": "${workspaceFolder}/backend/.env"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1855 次 |
| 最近记录: |