Nest JS ConfigService cannot able to read the .env file after fresh clone

On my old pc, let’s call it PC-1, I have a nest js backend application and environmental files are working properly when I run npm run start:dev . I’m using nest js built-in ConfigService/ConfigModule to read the environtmental variables from .env file. However, when I transfer to other new pc(PC-2) and clone the files, then the below error exist.

MongooseError: 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.

Obviously, my .env files is not read. That is why it returns undefined.

Alternatively when i install dotenv and call the config function, then it will work smoothly. But Im wondering on my previous computer I didn’t install dotenv package and it works smootly because under the hood, Nest JS ConfigService/ConfigModule uses dotenv.

Please help!


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.