#ConfigModule caching old .env?
13 messages · Page 1 of 1 (latest)
it does not seems to be related with nestjs
if you stop the process and start it again, it still uses the wrong value? 🤔
Yes
And this is on my own macbook, not using Docker and I don't have any shell overrides
I tried doing this in main.ts import * as fs from 'fs'; console.log('ENV FILE CONTENTS:', fs.readFileSync('.env.test', 'utf8')); and the file does exist and it shows the right output but then I console log this
console.log('DATABASE_URL:', process.env.DATABASE_URL); and it shows the old value from the .env for some reason
well, then it's not related with nestjs but with your setup
are you trying to read .env or another file (.env.test)?
I'm reading from .env.test which is in the root of the project
and my config module is configured accordingly
ConfigModule.forRoot({
envFilePath: ['.env.test'],
}),
And this started happening after I upgraded NestJS it's been fine for the past 8 or so months otherwise
Fixed by adding this at the top
import * as dotenv from 'dotenv';
dotenv.config({ path: '.env.test' , override: true}); // or just dotenv.config() for .env
I think this is a Cursor issue, somewhere its caching the .env variables and loading them hopefully there is a better fix somewhere out there
I'd say that something else is reading .env for you