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

Copy file to
.envfile in deploy step inpackage.json

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

Make sure
.envfile 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.hashnode.dev/simple-env-management-with-nestjs-with-railway