Skip to content
Snippets Groups Projects
Commit 7b13998a authored by Jesus Galaz's avatar Jesus Galaz
Browse files

Wrong version of this file, fixed with this commit

parent 1cb210ae
No related branches found
No related tags found
1 merge request!5User authentication implemented
const mongoose = require('mongoose'); const mongoose = require('mongoose');
require('dotenv').config();
// Function to connect to MongoDB using Mongoose and create collections const connectDB = async () => {
async function connectDB() {
try { try {
// Connect using the MongoDB URI from environment variables const conn = await mongoose.connect(process.env.MONGO_URI);
const conn = await mongoose.connect(process.env.MONGO_URI || "mongodb://127.0.0.1:27017/todo_app");
console.log(`MongoDB connected: ${conn.connection.host}`); console.log(`MongoDB connected: ${conn.connection.host}`);
} catch (err) { } catch (err) {
console.error(`Error: ${err.message}`); console.error(`Error: ${err.message}`);
process.exit(1); // Exit the process with failure if the connection fails process.exit(1);
} }
} };
module.exports = connectDB; 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