Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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}`);
});
Comment

why .env file in node.js is not working to connect mongodb

    // Create .env file 
    inside .env 
    MONGO_URI=mongo+src://username:password@cluster0......majority
    //
   // 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'))
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to scan a folder for documents with javascript 
Javascript :: × Error: Invariant failed: You should not use <Switch outside a <Router 
Javascript :: get value from serialized json apex 
Javascript :: how to log bodyparser error 
Javascript :: inline if statement javascript 
Javascript :: js create dom object 
Javascript :: $_GET data using javascript 
Javascript :: javascript download file 
Javascript :: agrgar atributo con id jquey 
Javascript :: how to filter an array of strings to see which letters match javascript 
Javascript :: how to call javascript function with parameter in c# 
Javascript :: how to create a nextjs app from a template 
Javascript :: how to create a blob javascript 
Javascript :: JavaScript - Closures 
Javascript :: duplicate images in webpage js 
Javascript :: Turn array items to matrix javascript 
Javascript :: object assign js 
Javascript :: how to give data from react native to webview 
Javascript :: add image inside a div on specific position javascript 
Javascript :: get data firebase 
Javascript :: onclick timer javascript 
Javascript :: ios safari controls cover element 
Javascript :: datepicker auto select off 
Javascript :: mongoose + populate 
Javascript :: javascript Iterate Through Iterables 
Javascript :: how to copy all elements in an array except for the first one in javascript 
Javascript :: iteration through json with key value pairs 
Javascript :: js addeventlistener input searcb mobile 
Javascript :: delete an item from array javascript 
Javascript :: javascript filter array return index 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =