【问题标题】:Node.js VSCode Debugger Missing Env VariablesNode.js VSCode 调试器缺少环境变量
【发布时间】:2021-01-15 12:43:47
【问题描述】:

当我在 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 文件变量?

【问题讨论】:

    标签: node.js visual-studio-code environment-variables dotenv


    【解决方案1】:

    我通过将其添加到我的launch.json 文件中的.vscode 工作区文件夹来修复它。我向配置对象添加了两个值:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-05
      • 1970-01-01
      • 2022-01-11
      相关资源
      最近更新 更多