Multiple .env for multiple countries

I don’t handle multiple countries for my own app but my app on companies do. Having these .env files: .env.production.sg .env.production.uk @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true, envFilePath: `.env.${process.env.RAILWAY_ENV}.${process.env.RAILWAY_COUNTRY}`, }), ], }) export class AppModule { constructor() { console.log(`RAILWAY_ENV: ${process.env.RAILWAY_ENV}`); console.log(`RAILWAY_COUNTRY: ${process.env.RAILWAY_COUNTRY}`); } } Above just for non-sensitive data (which can be expose) tho… This post is imported from: https://thebrownbox.hashnode.dev/multiple-env-for-multiple-countries

August 6, 2025 · 1 min

Manual load .env file in NestJS

As I mentioned before that we can just use ConfigModule with .env file. But sometimes we need to access .env variables at the beginning of time, when the module is not fully loaded yet. Then we manually load it in the top of the main.ts file. import * as dotenv from 'dotenv'; dotenv.config(); This post is imported from: https://thebrownbox.hashnode.dev/manual-load-env-file-in-nestjs

August 5, 2025 · 1 min

.env with vite

In vite project I use only 2 files: .env.development .env.production The env auto match with your build process without extra manual modification. This post is imported from: https://thebrownbox.hashnode.dev/env-with-vite

August 2, 2025 · 1 min

Simple .env management with NestJS (with Railway)

I usually deploy my backend in railway. So I usually have only 2 env: local and prod. Create 2 env files: Copy file to .env file in deploy step in package.json Make sure in the PROD deployment we run the correct command (in this case is Railway) Make sure .env file is in .gitignore Note: Variables only load if you install @nestjs/config and import it from AppModule @Module({ imports: [ConfigModule.forRoot()], controllers: [AppController], providers: [AppService], }) export class AppModule {} This post is imported from: https://thebrownbox....

July 20, 2025 · 1 min