Skip to content

Commit

Permalink
Create dbConfig.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Nov 25, 2024
1 parent 3058c04 commit 13bc759
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/config/dbConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const mongoose = require('mongoose');

// Database configuration settings
const dbConfig = {
uri: process.env.DB_URI || 'mongodb://localhost:27017/your_database_name',
options: {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
},
};

// Function to connect to the database
async function connectToDatabase() {
try {
await mongoose.connect(dbConfig.uri, dbConfig.options);
console.log('Database connection successful');
} catch (error) {
console.error('Database connection error:', error);
process.exit(1); // Exit the process with failure
}
}

module.exports = { dbConfig, connectToDatabase };

0 comments on commit 13bc759

Please sign in to comment.