My Development Notes


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


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!


Leave a Reply

Your email address will not be published. Required fields are marked *