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!