nestjsnestjs-confignestjs-passportnestjs-jwtnestjs-gateways

How to setup different environment file in nest js using postgresql


I am new this framework. I connected PostgreSQL database using ormconfig file. but I need to configure development environment, production environment, test environment. How to achieve this scenarios. I tried to use config service in my project. but always connected only .env file configuration.

development.env

POSTGRES_HOST=127.0.0.1
POSTGRES_PORT="5432"
POSTGRES_USER=postgres
POSTGRES_PASSWORD='*****'
POSTGRES_DATABASE=testdb123
PORT=4000

Solution

  • Well, I would recomment to keep .env file under git ignore and have a .env.example with all possible configuration items.

    If you like to have a default settings for every env, you can use something like https://www.npmjs.com/package/dotenv-defaults

    If you want to use DI & typing as well as env files for each environments, take a look at the nest configuration module