node.js - 为什么我收到错误:未定义配置属性“jwtPrivateKey”?
问题描述
当我通过 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"
}
解决方案
这是因为文件的命名,它应该在一个config
文件夹内,名称为default.json
,config/default.json
推荐阅读
- java - AroundInvoke:好奇的名字?
- android - 如何找出使用我的应用程序的用户年龄的全部统计数据?
- security - 缓冲区溢出示例
- java - 如何使用 Kafka Publisher 将行数据发布为 Avro 记录
- node.js - 使用 AWS-CDK 部署时无法从 Lambda 服务连接到 Elasticache Redis 集群
- csv - 使用不包括列名的 csv 文件加载 DB2 Warehouse
- time-complexity - 函数仅在循环结束时运行时的时间复杂度?
- vue.js - 当使用带有 Vue 3 组合 API 的自定义 webpack 设置时,输出包非常大
- javascript - 设置状态对象以重新获取时反应查询隐藏错误消息
- ipfs - 如何获取文件夹的 CID?