MONGODB_URI is not defined

I am trying to run my application and connect with my mongodb.

This is my .ts file

import mongoose from 'mongoose';

let isConnected = false;// Variable to track the connection status

export const connectToDB = async () => {
  mongoose.set('strictQuery', true);

  if(!process.env.MONGODB_URI) return console.log('MONGODB_URI is not defined');

  if(isConnected) return console.log('=> using existing database connection');

  try {
    await mongoose.connect(process.env.MONGODB_URI);

    isConnected = true;

    console.log('MongoDB Connected');
  } catch (error) {
    console.log(error)
  }
}

and that’s my .env file variable,
MONGODB_URI=mongodb+srv://test:test@cluster0.frazreq.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0

when running application, its showing the error MONGODB_URI is not defined which is coming from line 8 of my code( if(!process.env.MONGODB_URI) return console.log('MONGODB_URI is not defined'); )

If anything i am doing wrong with my env variable, please let me know. Anyone’s help in this would matter a lot