【问题标题】:Why am I getting Error: Configuration property “jwtPrivateKey” is not defined?为什么我收到错误:未定义配置属性“jwtPrivateKey”?
【发布时间】:2021-04-04 03:14:32
【问题描述】:

当我通过 NodeJS 终端运行我的 index.js 文件时,我不断收到此错误消息。我的编辑器是 VS Code。我在 Windows 上。

我将 npm 配置模块加载到我的 index.js 文件中。我创建了一个自定义环境变量.json。我在节点终端中设置了密码 vidlyPrivateKey。我不知道为什么会这样。任何帮助将不胜感激!

这是我的 index.js 代码:

const config = require('config');
try {
    const myKey = config.get("jwtPrivateKey");
    debug(myKey);
} catch (error) {
    debug(error, "FATAL ERROR: jwtPrivateKey is not defined.");
   return process.exit(1);
}

自定义环境变量.json:

{
    "jwtPrivateKey": "vidlyPrivateKey"
}

【问题讨论】:

    标签: node.js config


    【解决方案1】:

    这是因为文件的命名,它应该在config文件夹内,名称为default.jsonconfig/default.json

    这些是文档https://www.npmjs.com/package/config

    【讨论】:

    • 我有一个配置文件夹。我尝试将属性/值放在 default.json 文件中。我仍然收到相同的错误消息。
    猜你喜欢
    • 1970-01-01
    • 2020-09-28
    • 2012-01-30
    • 1970-01-01
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    相关资源
    最近更新 更多