const mongoose = require('mongoose');
const connectDB = async () => {
mongoose
.connect('mongodb://localhost:27017/playground', {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
})
.then(() => console.log('Connected Successfully'))
.catch((err) => console.error('Not Connected'));
}
module.exports = connectDB;
const mongoose = require("mongoose");
// database connection with mongoose
mongoose.connect("mongodb://localhost/todos", {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log("connection successful"))
.catch((err) => console.log(err));
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});
//config/db.js
const mongoose = require('mongoose');
const connect = async () => {
try {
await mongoose.connect(process.env.MONGODB);
console.log('database connect');
} catch (error) {
console.log(error.message);
}
};
module.exports = connect;
//index.js
require('dotenv').config();
const connect = require('./config/db');
connect();