I'm getting an error while running the below code.
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"
}
}
Config folder
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}`));
}
The error
'Error: Configuration property "db" is not defined', ' at Config.get (C:\Users\projects\movies-api-model\node_modules\config\lib\config.js:194:11)', ' at module.exports (C:\Users\projects\movies-api-model\startup\db.js:6:23)', ' at Object. (C:\Users\projects\movies-api-model\index.js:7:24)', ' at Module._compile (internal/modules/cjs/loader.js:1138:30)', ' at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)', ' at Module.load (internal/modules/cjs/loader.js:986:32)', ' at Function.Module._load (internal/modules/cjs/loader.js:879:14)', ' at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)', ' at internal/main/run_main_module.js:17:47'
Any help would be appreciated