Why create this project?
- Know how to load and parse a
.env
file from the project root directory and merge key/value pairs from the.env
file with environment variables assigned toprocess.env
- Know how to use configuration (built-in Nest) to solve some problem
Github: https://github.com/tulehuynhnhat/Nestjs-config
Node: 18.17.1
@nestjs/config: 3.0.0
- App
- Something
- Dependency: App -> Something
Create .env
file
ENV1=value_env1
ENV2=value_env2
Install package
npm i --save @nestjs/config
Situation 1: Import ConfigModule in App and get env from Something service
Situation 2: Import ConfigModule in App module set Global and get env from Something service
Situation 3: Get env from main
Situation 4: Custom configuration files
Situation 5: Use Config Service with interface as the type hint