Appearance
NestKit Configuration
NestKit provides predefined configurations that can be installed directly from the package.
How to install predefined config from NestKit
NestKit provides predefined configurations that can be installed directly from the package. For instance, NestKit has an AppConfig
that can be installed using the createAppConfig
function.
To use the createAppConfig
, update the src/config/index.ts
file to import and use the createAppConfig
function from the NestKit package:
ts
// src/config/index.ts
import { AppEnv } from '@deeepvision/nest-kit';
import { useDotEnv } from '@deeepvision/dotenv-yaml';
import {
createAppConfig,
} from '@deeepvision/nest-kit/dist/configs';
/* Inject environment variables from .env.yaml */
if (process.env.APP_ENV === AppEnv.LOCAL) {
useDotEnv();
}
export const AppConfig = createAppConfig({
name: 'Jetstream Stock',
shortname: 'stk',
});
export * from './app.config';
To inject the AppConfig
into a service or a controller, you can use the @Inject()
decorator provided by NestJS. Here's an example of how to do this in a service:
- Import
ConfigType
andInject
from the respective packages.
ts
import { ConfigType } from '@nestjs/config';
import { Inject } from '@nestjs/common';
- Import the
AppConfig
from your configuration file.
ts
import { AppConfig } from './config';
- Use the
@Inject()
decorator to inject theAppConfig
into your service or controller class.
ts
@Injectable()
export class YourService {
constructor(
@Inject(AppConfig.KEY) private appConfig: ConfigType<typeof AppConfig>,
) {}
// Your service methods...
}
By injecting the AppConfig
this way, you have access to the configuration values within your service or controller. You can use the appConfig
object to read and utilize the configuration values as needed.