Skip to content
Snippets Groups Projects
Commit 7455a7d5 authored by Jesus Galaz Reyes's avatar Jesus Galaz Reyes
Browse files

Merge branch '6-configure-mongodb-connection' into 'main'

Resolve "Configure MongoDB Connection"

Closes #6

See merge request !4
parents a46e5b3d cebc490e
No related branches found
No related tags found
1 merge request!4Resolve "Configure MongoDB Connection"
Pipeline #15657 passed
const mongoose = require('mongoose');
// Function to connect to MongoDB using Mongoose and create collections
async function connectDB() {
try {
// Connect using the MongoDB URI from environment variables
const conn = await mongoose.connect(process.env.MONGO_URI || "mongodb://127.0.0.1:27017/todo_app");
console.log(`MongoDB connected: ${conn.connection.host}`);
} catch (err) {
console.error(`Error: ${err.message}`);
process.exit(1); // Exit the process with failure if the connection fails
}
}
module.exports = connectDB;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment