Simple .env management with NestJS (with Railway)

The Brown BoxThe Brown Box
1 min read

I usually deploy my backend in railway.
So I usually have only 2 env: local and prod.

  1. Create 2 env files:

  1. Copy file to .env file in deploy step in package.json

  1. Make sure in the PROD deployment we run the correct command (in this case is Railway)

  1. 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 {}
0
Subscribe to my newsletter

Read articles from The Brown Box directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

The Brown Box
The Brown Box