I try to start a project but when I try to connect the mongo with the server I encounter an error that shows that the connection is not working because it can not find the folder where the connection string.
my db file:
const mongoose = require('mongoose');
const config = require('config');
const db = config.get('mongoURI')
const connectDB = async () => {
try{
await mongoose.connect(db);
console.log('MongoDB connected..');
}catch(err){
console.error(err.message);
process.exit(1)
}
}
module.exports = connectDB;
my defualt.json:
{
"mongoURI": "mongodb+srv://<username>:<password>@devconector-
zfloj.mongodb.net/test?retryWrites=true&w=majority"
}
the error: WARNING: No configurations found in configuration directory:C:\Users\Yair Azaria\Desktop\תכנות\node.js\DevConnector\config WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment. C:\Users\Yair Azaria\Desktop\node.js\DevConnector\node_modules\config\lib\config.js:203 throw new Error('Configuration property "' + property + '" is not defined'); ^
Error: Configuration property "mongoURI" is not defined at Config.get(C:\Users\YairAzaria\Desktop\תכנות\node.js\DevConnector\node_modules\config\lib\config.js:203:1)
at Object.<anonymous>
(C:\Users\YairAzaria\Desktop\תכנות\node.js\DevConnector\config\db.js:3:19)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous>
(C:\Users\YairAzaria\Desktop\תכנות\node.js\DevConnector\server.js:2:19)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)