First of all, check whether you’ve installed the dotenv npm package. If not, install the dotenv package like so:
npm install dotenv
Next, import dotenv inside your main server file ( like app.js or server.js file) like so :
require("dotenv").config();
// you can add this just below your all other imports
See whether your mongoose connection string is properly enabled like the example below :
mongoose
.connect(process.env.MONGO_URI)
.then(() => console.log("MongoDB Connected"))
.catch((err) => console.log(err));
You should be connected to your server now!
One response to “The uri parameter to openUri() must be a string, got “undefined”. Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string – ERROR SOLVED”
I am extremely inspired together with your writing
talents as well as with the format in your blog. Is this a paid theme or
did you customize it yourself? Either way stay up the
excellent high quality writing, it’s uncommon to peer a
great blog like this one today. TikTok ManyChat!