How to use nestjs-config - 10 common examples

To help you get started, we’ve selected a few nestjs-config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kuangshp / nestjs-mysql-api / src / app.module.ts View on Github external
import { CurlModule } from './core/curl/curl.module';
import { UploadFileModule } from './core/upload-file/upload-file.module';
import { FileModule } from './file/file.module';
import { RoleModule } from './core/role/role.module';
import { ResourceModule } from './core/resource/resource.module';
import * as path from 'path';

const entitiesPath =
  process.env.NODE_ENV === 'production'
    ? path.resolve('./**/*.entity.js')
    : path.resolve('./**/*.entity.ts');
Logger.log(process.env.NODE_ENV, '当前环境');

@Module({
  imports: [
    ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}'), {
      modifyConfigName: name => name.replace('.config', ''),
    }), // 配置加载配置文件
    TypeOrmModule.forRootAsync({
      useFactory: async (config: ConfigService) => ({
        type: config.get('database.type'),
        host: config.get('database.host'),
        port: config.get('database.port'),
        username: config.get('database.username'),
        password: config.get('database.password'),
        database: config.get('database.database'),
        entities: [entitiesPath],
        synchronize: config.get('database.synchronize'),
        logging: config.get('database.logging'),
      }),
      inject: [ConfigService],
    }),
github nestjsx / nestjs-braintree / src / __tests__ / braintree.module.spec.ts View on Github external
it('Does it instance with options using async registry', async () => {
    const module = await Test.createTestingModule({
      imports: [
        ConfigModule.load(
          path.resolve(__dirname, '__stubs__', 'config', '*.ts'),
        ),
        BraintreeModule.forRootAsync({
          useFactory: config => config.get('braintree'),
          inject: [ConfigService],
        }),
      ],
    }).compile();

    const options = module.get(BRAINTREE_OPTIONS_PROVIDER);
    const provider = module.get(BraintreeProvider);

    expect(options.environment).toBe(braintree.Environment.Sandbox);
    expect(typeof options.merchantId).toBe('string');
    expect(typeof options.publicKey).toBe('string');
    expect(typeof options.privateKey).toBe('string');
github nestjsx / nestjs-braintree / src / __tests__ / e2e / braintree.controller.e2e-spec.ts View on Github external
@BraintreeWebhookHandler()
    class TestProvider {
      @BraintreeSubscriptionCanceled()
      canceled() {
        return true;
      }

      @BraintreeSubscriptionChargedSuccessfully()
      callMe() {
        throw new Error('hello I am errors');
      }
    }

    module = await Test.createTestingModule({
      imports: [
        ConfigModule.load(
          path.resolve(__dirname, '../', '__stubs__', 'config', '*.ts'),
        ),
        BraintreeModule.forRoot({
          environment: braintree.Environment.Sandbox,
          merchantId: 'merchantId',
          publicKey: 'publicKey',
          privateKey: 'privateKey',
        }),
        BraintreeWebhookModule,
      ],
      providers: [TestProvider],
    }).compile();

    app = module.createNestApplication();
    await app.init();
  });
github nestjsx / nestjs-braintree / src / __tests__ / braintree.webhook.provider.spec.ts View on Github external
class SubscriptionProvider {
      public static called = false;

      @BraintreeSubscriptionCanceled()
      canceled(webhook) {
        //this is a work around the jest spyon reflect issue
        SubscriptionProvider.called = true;
      }

      @BraintreeSubscriptionExpired()
      expired(webhook) {}
    }

    const module: TestingModule = await Test.createTestingModule({
      imports: [
        ConfigModule.load(
          path.resolve(__dirname, '__stubs__', 'config', '*.ts'),
        ),
        BraintreeModule.forRootAsync({
          useFactory: async config => config.get('braintree'),
          inject: [ConfigService],
        }),
        BraintreeWebhookModule,
      ],
      providers: [SubscriptionProvider],
    }).compile();

    const gateway = braintree.connect({
      environment: braintree.Environment.Sandbox,
      merchantId: 'merchantId',
      publicKey: 'publicKey',
      privateKey: 'privateKey',
github nestjsx / nestjs-braintree / src / __tests__ / braintree.transactions.spec.ts View on Github external
beforeEach(async () => {
    module = await Test.createTestingModule({
      imports: [
        ConfigModule.load(
          path.resolve(__dirname, '__stubs__', 'config', '*.ts'),
        ),
        BraintreeModule.forRootAsync({
          useFactory: async config => config.get('braintree'),
          inject: [ConfigService],
        }),
      ],
    }).compile();

    provider = module.get(BraintreeProvider);
  });
github nestjsx / nestjs-braintree / src / __tests__ / braintree.controller.spec.ts View on Github external
beforeEach(async () => {
    module = await Test.createTestingModule({
      imports: [
        ConfigModule.load(
          path.resolve(__dirname, '__stubs__', 'config', '*.ts'),
        ),
        BraintreeModule.forRootAsync({
          useFactory: async config => config.get('braintree'),
          inject: [ConfigService],
        }),
        BraintreeWebhookModule,
      ],
      providers: [SubscriptionProvider],
    }).compile();
  });
github FusionWorks / react-admin-nestjsx-crud-dataprovider / example / api / src / app.module.ts View on Github external
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from 'nestjs-config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import * as path from 'path';

@Module({
  imports: [
    ConfigModule.load(path.resolve(__dirname, 'config', '*.{ts,js}')),
    TypeOrmModule.forRootAsync({
        useFactory: (config: ConfigService) => config.get('database'),
        inject: [ConfigService],
    }),
    UserModule
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
github nestjsx / nestjs-config / examples / basic / main.ts View on Github external
import { Module } from '@nestjs/common';
import { ConfigModule } from 'nestjs-config';
import * as path from 'path';

import UserController from './user.controller';

@Module({
  imports: [
    ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}')),
  ],
  controllers: [UserController],
})
export default class UserModule {}
github nestjsx / nestjs-config / examples / typeorm / index.ts View on Github external
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from 'nestjs-config';
import { TypeOrmModule } from '@nestjs/typeorm';
import * as path from 'path';

@Module({
  imports: [
    ConfigModule.load(path.resolve(__dirname, 'config/**/!(*.d).{ts,js}')),
    TypeOrmModule.forRootAsync({
      useFactory: async (config: ConfigService) => config.get('database'),
      inject: [ConfigService],
    }),
  ],
})
export default class AppModule {}
github ramesaliyev / mom / services / be-api / .backups / tutorial / app.module.ts View on Github external
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { ConfigModule } from 'nestjs-config';

import { AppController } from './app.controller';
import { AppService } from './app.service';

import { logger, LoggerMiddleware } from './middlewares/logger.middleware';

import { CatsController } from './cats/cats.controller';
import { CatsModule } from './cats/cats.module';

@Module({
  imports: [ConfigModule.load(), CatsModule],
  controllers: [AppController],
  providers: [AppService],
})
export class ApplicationModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(logger).forRoutes(CatsController);
  }
}

nestjs-config

Easy to use Nest configuration module

MIT
Latest version published 1 year ago

Package Health Score

54 / 100
Full package analysis