Skip to content

App Config

The NestKit AppConfig is a customizable and extensible configuration module designed for managing the main application settings.

Environment variables used in the AppConfig

  1. PORT: The application port. (optional, 3000 by default)
  2. APP_HOST: The application host URL.
  3. APP_UI_HOST: The application UI host URL.
  4. APP_ENV: The application environment, which can be local, development, stage, or production.
  5. APP_SERVICE_ACCOUNT_ID: The application service account ID (optional).
  6. FALLBACK_LANGUAGE: The application's fallback language. (optional, en by default)

Here's a YAML formatted example of the environment variables used in the AppConfig:

yaml
PORT: 3020
APP_HOST: 'https://app-api.example.com'
APP_UI_HOST: 'https://app.example.com'
APP_ENV: 'local'
APP_SERVICE_ACCOUNT_ID: 'hcu:xxxxxxxxxxx'
FALLBACK_LANGUAGE: 'en'

You can adjust the example values according to your application's needs.

How to create and customize AppConfig

Some static parameters can be customized using an options object passed as the first argument to createAppConfig. Below is the list of available options:

  1. name (string): The full name of the application. This is a human-readable name that can be used for display purposes. Example: 'Jetstream'.

  2. shortname (string): The short name of the application. This is an abbreviated version of the application name, often used for internal purposes or as a prefix for unique identifiers. Example: 'js'.

Here's an example of how to use the createAppConfig function with these options:

ts
import { createAppConfig } from '@deep/nest-kit/dist/configs';

export const AppConfig = createAppConfig({
  name: 'Jetstream Stock',
  shortname: 'stk',
});

In this example, the full name of the application is set to 'Jetstream Stock', and the short name is set to 'stk'.

How to inject the AppConfig into a service or a controller

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:

  1. Import ConfigType and Inject from the respective packages.
ts
import { ConfigType } from '@nestjs/config';
import { Inject } from '@nestjs/common';
  1. Import the AppConfig from your configuration file.
ts
import { AppConfig } from './config';
  1. Use the @Inject() decorator to inject the AppConfig 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 this.appConfig object to read and utilize the configuration values as needed.

Created by DeepVision Software.