why .env file in node.js is not working to connect mongodb
mongoose.connect(process.env.MONGO_URI).then(() => {
console.log("DB Connected");
});
mongoose.connection.on("error", err => {
console.log(`DB Connection Error: ${err.message}`);
});
why .env file in node.js is not working to connect mongodb
mongoose.connect(process.env.MONGO_URI).then(() => {
console.log("DB Connected");
});
mongoose.connection.on("error", err => {
console.log(`DB Connection Error: ${err.message}`);
});
why .env file in node.js is not working to connect mongodb
// Create .env file
inside .env
MONGO_URI=mongo+src://username:[email protected]
//
// Inside app.js or server.js
const dotenv = require('dotenv')
dotenv.config()
const mongoose = require('mongoose')
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
});
const db = mongoose.connection
db.on('error', error => console.error(error))
db.once('open', MONGO_URI => console.log('Connected to Database'))
why .env file in node.js is not working to connect mongodb
mongoose.connect(process.env.MONGO_URI).then(() => {
console.log("DB Connected");
});
mongoose.connection.on("error", err => {
console.log(`DB Connection Error: ${err.message}`);
});
why .env file in node.js is not working to connect mongodb
// Create .env file
inside .env
MONGO_URI=mongo+src://username:[email protected]
//
// Inside app.js or server.js
const dotenv = require('dotenv')
dotenv.config()
const mongoose = require('mongoose')
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
});
const db = mongoose.connection
db.on('error', error => console.error(error))
db.once('open', MONGO_URI => console.log('Connected to Database'))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us