@bashleigh/nest-config
v0.0.9 nestjs config dotenv env
Nest Config
A config component for nestJS.
Install
yarn add @bashleigh/nest-config
npx add --save @bashleigh/nest-config
create a .env
file and insert your configurations
touch .env && echo 'APP_TEST=true' >> .env
How to use
Get
Get a parameter from the config
const test = this.config.get('APP_TEST');
With a default option
const test = this.config.get('APP_TEST', false);
Has
Check your config has a parameter defined
this.config.has('APP_TEST');
Root
Get a root path like /var/www/mypath
this.config.root('mypath'); //returns /var/www/mypath
this.config.root('file.txt'); //returns /var/www/file.txt
Src
Get a path within src (uses root)
this.config.src('mypath'); //returns /var/www/src/mypath
Integrating with modules
import {
Injectable,
} from '@nestjs/common';
import ConfigModule from '@bashleigh/nest-config';
@Injectable({
imports: [
ConfigModule,
],
controllers: [],
providers: [],
})
export class ApplicationModule {
constructor() {}
}
Injection
Inject the component into a controller
import {
Controller,
} from '@nestjs/common';
import {
ConfigService,
} from '@bashleigh/nest-config';
@Controller('user')
export default class UserController {
constructor(private readonly config: ConfigService) {}
}
Injection with decorator
import {
Controller,
} from '@nestjs/common';
import {
InjectConfig,
} from '@bashleigh/nest-config';
@Controller('user')
export default class UserController {
constructor(@InjectConfig() private readonly config) {}
}
npm i @bashleigh/[email protected]
Source Code
github.com/bashleigh/nest-co...Metadata
- MIT
- Whatever
- Aaryanna Simonelli
- released 6/1/2018