javascript - 错误:配置属性“db”未定义'Node.Js
问题描述
运行以下代码时出现错误。
包.json
{
"name": "movies-api-model",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --watchAll --verbose"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.0",
"config": "^1.29.4",
"express": "^4.17.1",
"express-async-errors": "^2.1.0",
"fawn": "^2.1.5",
"joi": "^13.1.0",
"joi-objectid": "^2.0.0",
"joi-oid": "^1.1.2",
"jsonwebtoken": "^8.1.1",
"lodash": "^4.17.4",
"mongoose": "^5.10.10",
"winston": "^2.4.0",
"winston-mongodb": "^3.0.0"
},
"devDependencies": {
"jest": "^22.2.2"
}
}
配置文件夹
测试.json
{
"jwtPrivateKey": "1234",
"db": "mongodb://localhost/vidly_tests"
}
默认.json
{
"jwtPrivateKey": "",
"db": "mongodb://localhost/vidly"
}
数据库.js
const winston = require('winston');
const mongoose = require('mongoose');
const config = require('config');
module.exports = function() {
const db = config.get('db');
mongoose.connect(db)//,{ useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true}
.then(() => winston.info(`Connected to ${db}`));
}
错误_
'错误:未定义配置属性“db”','在 Config.get (C:\Users\projects\movies-api-model\node_modules\config\lib\config.js:194:11)','在module.exports (C:\Users\projects\movies-api-model\startup\db.js:6:23)', ' 在 Object. (C:\Users\projects\movies-api-model\index.js:7:24)', ' 在 Module._compile (internal/modules/cjs/loader.js:1138:30)', ' 在 Object. Module._extensions..js (internal/modules/cjs/loader.js:1158:10)','在 Module.load (internal/modules/cjs/loader.js:986:32)','在 Function.Module ._load (internal/modules/cjs/loader.js:879:14)', ' 在 Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)', ' 在 internal/main/run_main_module .js:17:47'
任何帮助,将不胜感激
解决方案
推荐阅读
- javascript - React JS 解析 JSON 中的数据
- docker - 如何从命令提示符执行在 docker 容器内运行的 dotnetcore 项目?
- c# - 多选DataGridView c#
- c++ - 如何将 GLEW 和 GLFW 以及 OpenGL 链接到 MingW 的 g++
- android - Android:对邮件发送的附件进行排序
- python-3.x - psycopg2.ProgrammingError:无效的dsn:无效的连接选项“dBname”
- ruby-on-rails - 如何将包含敏感数据的文件部署到heroku?(带有 Settingslogic gem 的 Rails 项目)
- javascript - 终端错误 - 有人可以解释我应该在哪里寻找错误吗?
- websphere - 使用 startNode.bat 命令时出现 filenotfoundException
- spring - 如何通过 SpringBoot rest api 中的 PUT 方法更新我的类的特定文件