如何解决错误:未定义配置属性“ db”'Node.Js
运行以下代码时出现错误。
Package.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"
}
}
配置文件夹
test.json
{
"jwtPrivateKey": "1234","db": "mongodb://localhost/vidly_tests"
}
default.json
{
"jwtPrivateKey": "","db": "mongodb://localhost/vidly"
}
db.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)', '在对象。 (C:\ Users \ projects \ movies-api-model \ index.js:7:24)', '位于Module._compile(internal / modules / cjs / loader.js:1138:30)', 'at 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 [作为runMain](internal / modules / run_main.js:71:12)', '位于internal / main / run_main_module.js:17:47'
任何帮助将不胜感激
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。