@nestjs/config#ConfigModule TypeScript Examples
The following examples show how to use
@nestjs/config#ConfigModule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: auth.module.ts From nestjs-rest-sample with GNU General Public License v3.0 | 7 votes |
@Module({
imports: [
ConfigModule.forFeature(jwtConfig),
UserModule,
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.registerAsync({
imports: [ConfigModule.forFeature(jwtConfig)],
useFactory: (config: ConfigType<typeof jwtConfig>) => {
return {
secret: config.secretKey,
signOptions: { expiresIn: config.expiresIn },
} as JwtModuleOptions;
},
inject: [jwtConfig.KEY],
}),
],
providers: [AuthService, LocalStrategy, JwtStrategy],
exports: [AuthService],
controllers: [AuthController],
})
export class AuthModule {}
Example #2
Source File: auth.module.ts From 42_checkIn with GNU General Public License v3.0 | 6 votes |
@Module({
imports: [
HttpModule,
PassportModule,
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
secret: configService.get('jwt.secret'),
signOptions: { expiresIn: '7d' },
}),
}),
LoggerModule,
],
providers: [AuthService, JwtStrategy, FtStrategy],
exports: [AuthService],
})
export class AuthModule {}
Example #3
Source File: app.module.ts From nest-js-boilerplate with MIT License | 6 votes |
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
MongooseModule.forRoot(process.env.MONGODB_URL as string, {
useCreateIndex: true,
// flag to allow users to fall back to the old
// parser if they find a bug in the new parse
useNewUrlParser: true,
useUnifiedTopology: true,
}),
RedisModule.forRootAsync({
useFactory: (cfg: ConfigService) => ({
config: {
url: cfg.get('REDIS_URL'),
},
}),
inject: [ConfigService],
}),
V1Module,
],
controllers: [AppController],
providers: [AppService],
})
export default class AppModule { }
Example #4
Source File: config.module.ts From runebot with MIT License | 6 votes |
@Module({
imports: [
ConfigModule.forRoot({
load: [configuration],
}),
],
providers: [ConfigService, AppConfigService],
exports: [ConfigService, AppConfigService],
})
export class AppConfigModule {}
Example #5
Source File: app.module.ts From nest-js-quiz-manager with MIT License | 6 votes |
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
TypeOrmModule.forRootAsync(typeOrmAsyncConfig),
EventEmitterModule.forRoot(),
MulterModule.register({ dest: './uploads' }),
QuizModule,
UserModule,
AuthModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(ApiTokenCheckMiddleware)
.forRoutes({ path: '/', method: RequestMethod.ALL });
}
}
Example #6
Source File: account.module.ts From amplication with Apache License 2.0 | 6 votes |
@Module({
imports: [
ConfigModule,
PrismaModule,
PermissionsModule,
SegmentAnalyticsModule
],
providers: [AccountService, PasswordService, AccountResolver],
exports: [AccountService, PasswordService, AccountResolver]
})
export class AccountModule {}
Example #7
Source File: app.module.ts From nestjs-rest-microservices with MIT License | 6 votes |
@Module({
imports: [
ConfigModule.forRoot(),
LoggerModule.forRoot({
pinoHttp: {
safe: true,
prettyPrint: process.env.NODE_ENV === 'development'
}
}),
HealthCheckModule,
OrganizationsModule
]
})
export class AppModule {}
Example #8
Source File: api-gateway.module.ts From gear-js with GNU General Public License v3.0 | 6 votes |
@Module({
imports: [
ConfigModule.forRoot({
load: [configuration],
}),
],
controllers: [ApiGatewayController],
providers: [ApiGatewayService],
})
export class ApiGatewayModule {}
Example #9
Source File: app.module.ts From nestjs-rest-sample with GNU General Public License v3.0 | 6 votes |
@Module({
imports: [
ConfigModule.forRoot({ ignoreEnvFile: true }),
DatabaseModule,
PostModule,
AuthModule,
UserModule,
SendgridModule,
LoggerModule.forRoot(),
],
controllers: [AppController],
providers: [AppService],
exports:[AppService]
})
export class AppModule { }
Example #10
Source File: app.module.ts From aws-nestjs-starter with The Unlicense | 6 votes |
@Module({
imports: [
ConfigModule.forRoot(),
GraphQLModule.forRoot({
autoSchemaFile: true,
playground: {
endpoint:
process.env.IS_NOT_SLS === 'true'
? '/graphql'
: `/${process.env.STAGE}/graphql`,
},
}),
DynamooseModule.forRoot({
local: process.env.IS_DDB_LOCAL === 'true',
aws: { region: process.env.REGION },
model: {
create: false,
prefix: `${process.env.SERVICE}-${process.env.STAGE}-`,
suffix: '-table',
},
}),
NotificationModule,
],
})
export class AppModule {}
Example #11
Source File: test-app.ts From ironfish-api with Mozilla Public License 2.0 | 6 votes |
export async function bootstrapTestApp(): Promise<INestApplication> {
const module = await Test.createTestingModule({
imports: [
AuthModule,
ConfigModule.forRoot({
envFilePath: '.env.test',
isGlobal: true,
validationSchema: joi.object({
API_URL: joi.string().required(),
BLOCK_EXPLORER_URL: joi.string().required(),
CHECK_EVENT_OCCURRED_AT: joi.boolean().default(true),
CHECK_USER_CREATED_AT: joi.boolean().default(true),
DATABASE_CONNECTION_POOL_URL: joi.string().required(),
DATABASE_URL: joi.string().required(),
DATADOG_URL: joi.string().required(),
DISABLE_FAUCET: joi.boolean().default(false),
DISABLE_LOGIN: joi.boolean().default(false),
INCENTIVIZED_TESTNET_URL: joi.string().required(),
INFLUXDB_API_TOKEN: joi.string().required(),
INFLUXDB_BUCKET: joi.string().required(),
INFLUXDB_URL: joi.string().required(),
IRONFISH_API_KEY: joi.string().required(),
MAGIC_SECRET_KEY: joi.string().required(),
NETWORK_VERSION: joi.number().required(),
NODE_ENV: joi.string().required(),
NODE_UPTIME_ENABLED: joi.boolean().default(true),
PORT: joi.number().default(8003),
}),
}),
DatadogModule,
...JOBS_MODULES,
...REST_MODULES,
],
}).compile();
const app = module.createNestApplication();
app.use(json({ limit: '10mb' }));
return app;
}
Example #12
Source File: app.module.ts From coronatest with GNU Affero General Public License v3.0 | 6 votes |
@Module({
imports: [
SequelizeModule.forFeature([Submission]),
DatabaseModule,
ConfigModule.forRoot({
load: [configuration],
isGlobal: true
}),
SessionsModule,
AuthModule
],
controllers: [AppController, SubmissionsController],
providers: [AppService, SubmissionsService]
})
export class AppModule {}
Example #13
Source File: shared.module.ts From mamori-i-japan-api with BSD 2-Clause "Simplified" License | 6 votes |
@Module({
imports: [ConfigModule.forRoot(configModuleOptions), FirebaseModule, LoggerModule],
providers: [
{ provide: APP_INTERCEPTOR, useClass: LoggingInterceptor },
{
provide: APP_FILTER,
useClass: AllExceptionsFilter,
},
],
exports: [ConfigModule, FirebaseModule, LoggerModule],
})
export class SharedModule {}
Example #14
Source File: shared.module.ts From nestjs-starter-rest-api with MIT License | 6 votes |
@Module({
imports: [
ConfigModule.forRoot(configModuleOptions),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
type: 'mysql',
host: configService.get<string>('database.host'),
port: configService.get<number | undefined>('database.port'),
database: configService.get<string>('database.name'),
username: configService.get<string>('database.user'),
password: configService.get<string>('database.pass'),
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
// Timezone configured on the MySQL server.
// This is used to typecast server date/time values to JavaScript Date object and vice versa.
timezone: 'Z',
synchronize: false,
debug: configService.get<string>('env') === 'development',
}),
}),
AppLoggerModule,
],
exports: [AppLoggerModule, ConfigModule],
providers: [
{ provide: APP_INTERCEPTOR, useClass: LoggingInterceptor },
{
provide: APP_FILTER,
useClass: AllExceptionsFilter,
},
],
})
export class SharedModule {}
Example #15
Source File: test-environment.ts From relate with GNU General Public License v3.0 | 6 votes |
static async init(filename: string): Promise<TestEnvironment> {
const shortUUID = uuid().slice(0, 8);
const dirname = path.basename(path.dirname(filename));
const name = `${dirname}_${path.basename(filename, '.ts')}_${shortUUID}`;
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
SystemModule.register(),
],
})
class AppModule {}
const app = await NestFactory.createApplicationContext(AppModule);
const systemProvider = app.get(SystemProvider);
await systemProvider.createEnvironment({
name,
type: ENVIRONMENT_TYPES.LOCAL,
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const environment: LocalEnvironment = await systemProvider.getEnvironment(name);
// eslint-disable-next-line no-restricted-syntax
return new TestEnvironment(filename, app, systemProvider, environment);
}
Example #16
Source File: app.module.ts From game-store-monorepo-app with MIT License | 6 votes |
@Module({
imports: [
HttpModule,
ConfigModule,
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
}),
],
providers: [GameResolver, GenreResolver, TagResolver, PublisherResolver],
})
export class AppModule {}
Example #17
Source File: app.module.ts From office-hours with GNU General Public License v3.0 | 6 votes |
@Module({
imports: [
TypeOrmModule.forRoot(typeormConfig),
ScheduleModule.forRoot(),
LoginModule,
ProfileModule,
CourseModule,
QueueModule,
NotificationModule,
QuestionModule,
SeedModule,
ResourcesModule,
ConfigModule.forRoot({
envFilePath: [
'.env',
...(process.env.NODE_ENV !== 'production' ? ['.env.development'] : []),
],
isGlobal: true,
}),
AdminModule,
CommandModule,
SSEModule,
BackfillModule,
ReleaseNotesModule,
InsightsModule,
// Only use 'pub' for publishing events, 'sub' for subscribing, and 'db' for writing to key/value store
RedisModule.register([{ name: 'pub' }, { name: 'sub' }, { name: 'db' }]),
HealthcheckModule,
AlertsModule,
SemesterModule,
],
})
export class AppModule {}
Example #18
Source File: app.module.ts From twilio-voice-notification-app with Apache License 2.0 | 6 votes |
/**
* Main module used in Development and Production.
* It uses PostgreSQL database connector.
*/
@Module({
imports: [
TwilioModule,
SharedModule.forRoot(shouldServeStaticContent),
SequelizeModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => {
const database = configService.get<any>(ENV_VAR.DATABASE_KEY);
return {
dialect: 'postgres',
...database,
synchronize: true,
dialectOptions: {
ssl: {
rejectUnauthorized: false
}
},
ssl: true,
models: [TestCall, Call, Broadcast],
};
},
inject: [ConfigService],
}),
],
})
export class AppModule {
constructor(sequelize: Sequelize) {
// It will create the database the first time.
// For a list of options, see: https://sequelize.org/master/class/lib/sequelize.js~Sequelize.html#instance-method-sync
sequelize.sync();
}
}
Example #19
Source File: app.module.ts From nestjs-starter with MIT License | 6 votes |
typeOrmConfig = {
imports: [
ConfigModule.forRoot({
load: [databaseConfig],
expandVariables: true,
}),
],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => {
initializeTransactionalContext();
patchTypeORMRepositoryWithBaseRepository();
return configService.get('database');
},
}
Example #20
Source File: app.module.ts From 42_checkIn with GNU General Public License v3.0 | 5 votes |
@Module({
imports: [
ConfigModule.forRoot({
load: [configuration],
isGlobal: true,
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
type: 'mysql',
host: configService.get('database.host'),
port: configService.get('database.port'),
username: configService.get('database.username'),
password: configService.get('database.password'),
database: configService.get('database.name'),
entities: [join(__dirname, '/**/*.entity.js')],
synchronize: true,
}),
}),
// ServeStaticModule.forRoot({
// rootPath: resolve(__dirname, '../../../client/build'),
// }),
TerminusModule,
UserModule,
AuthModule,
CardModule,
LogModule,
HealthModule,
LoggerModule,
ThrottlerModule.forRoot({
ttl: 60,
limit: 20,
}),
WaitingModule,
HttpModule,
// MailerModule.forRootAsync({
// imports: [ConfigModule],
// inject: [ConfigService],
// useFactory: (configService: ConfigService) => ({
// transport: configService.get('mailer.mail'),
// defaults: {
// from: '"42 출입 시스템" <[email protected]>',
// },
// template: {
// dir: __dirname + '/templates',
// adapter: new EjsAdapter(),
// options: {
// strict: true,
// },
// },
// }),
// }),
ScheduleModule.forRoot(),
],
controllers: [AppController, HealthController, WaitingController],
providers: [
AppService,
Logger,
{ provide: APP_GUARD, useClass: TokenThrottlerGuard },
],
})
export class AppModule {}
Example #21
Source File: app.module.ts From nest-js-boilerplate with MIT License | 5 votes |
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
MongooseModule.forRoot(process.env.MONGODB_URL as string, {
autoReconnect: true,
useCreateIndex: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000,
useNewUrlParser: true,
useUnifiedTopology: true,
}),
RedisModule.forRootAsync({
useFactory: (cfg: ConfigService) => ({
config: {
url: cfg.get('REDIS_URL'),
},
}),
inject: [ConfigService],
}),
MailerModule.forRootAsync({
useFactory: (cfg: ConfigService) => ({
transport: {
host: cfg.get('MAILER_HOST'),
port: Number(cfg.get('MAILER_PORT')),
secure: false,
auth: {
user: cfg.get('MAILER_USERNAME'),
pass: cfg.get('MAILER_PASSWORD'),
},
},
defaults: {
from: cfg.get('MAILER_FROM_EMAIL'),
},
template: {
adapter: new HandlebarsAdapter(),
options: {
strict: true,
},
},
}),
inject: [ConfigService],
}),
V1Module,
],
controllers: [AppController],
providers: [AppService],
})
export default class AppModule {}
Example #22
Source File: typeorm.config.ts From nest-js-quiz-manager with MIT License | 5 votes |
typeOrmAsyncConfig: TypeOrmModuleAsyncOptions = {
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (): Promise<TypeOrmModuleOptions> => {
return {
type: 'mysql',
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT, 10),
username: process.env.DB_USERNAME,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
entities: [__dirname + '/../**/*.entity.{js,ts}'],
migrations: [__dirname + '/../database/migrations/*{.ts,.js}'],
cli: {
migrationsDir: __dirname + '/../database/migrations',
},
extra: {
charset: 'utf8mb4_unicode_ci',
},
synchronize: false,
logging: true,
};
},
}
Example #23
Source File: app.module.ts From amplication with Apache License 2.0 | 5 votes |
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath: ['.env.local', '.env']
}),
SendGridModule.forRootAsync({
imports: [ConfigModule, GoogleSecretsManagerModule],
inject: [ConfigService, GoogleSecretsManagerService],
useClass: SendgridConfigService
}),
ServeStaticModule.forRoot({
rootPath: path.join(
__dirname,
'..',
'..',
'..',
'amplication-client',
'build'
),
exclude: ['/graphql']
}),
RootWinstonModule,
GraphQLModule.forRootAsync({
useFactory: async (configService: ConfigService) => ({
autoSchemaFile:
configService.get('GRAPHQL_SCHEMA_DEST') || './src/schema.graphql',
debug: configService.get('GRAPHQL_DEBUG') === '1',
playground: configService.get('PLAYGROUND_ENABLE') === '1',
context: ({ req }: { req: Request }) => ({
req
})
}),
inject: [ConfigService]
}),
RootStorageModule,
MorganModule,
SegmentAnalyticsModule.registerAsync({
useClass: SegmentAnalyticsOptionsService
}),
CoreModule
],
controllers: [],
providers: [
{
provide: APP_INTERCEPTOR,
useClass: InjectContextInterceptor
}
]
})
export class AppModule implements OnApplicationShutdown {
onApplicationShutdown(signal: string) {
console.trace(`Application shut down (signal: ${signal})`);
}
}
Example #24
Source File: app.module.ts From nestjs-crud-prisma with MIT License | 5 votes |
@Module({
imports: [ConfigModule.forRoot({ isGlobal: true }), ...modules],
controllers: [],
providers: []
})
export class AppModule {}
Example #25
Source File: app.module.ts From codeclannigeria-backend with MIT License | 5 votes |
Config = ConfigModule.forRoot({
isGlobal: true,
validationSchema: envValidation(),
expandVariables: true,
validationOptions: {
abortEarly: true
}
})
Example #26
Source File: app.module.ts From trading-bot with MIT License | 5 votes |
@Module({
imports: [ConfigModule.forRoot(), BotModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Example #27
Source File: app.module.ts From bad-cards-game with GNU Affero General Public License v3.0 | 5 votes |
@Module({
imports: [ConfigModule.forRoot(), CacheModule.register()],
controllers: [AppController, GameController],
providers: [AppService],
})
export class AppModule {}
Example #28
Source File: database.module.ts From nestjs-rest-sample with GNU General Public License v3.0 | 5 votes |
@Module({
imports: [ConfigModule.forFeature(mongodbConfig)],
providers: [...databaseConnectionProviders, ...databaseModelsProviders],
exports: [...databaseConnectionProviders, ...databaseModelsProviders],
})
export class DatabaseModule { }
Example #29
Source File: app.module.ts From ironfish-api with Mozilla Public License 2.0 | 5 votes |
@Module({
imports: [
ApiConfigModule,
AuthModule,
ConfigModule.forRoot({
isGlobal: true,
validationSchema: joi.object({
ALLOW_BLOCK_MINED_POINTS: joi.boolean().default(false),
API_URL: joi.string().required(),
BLOCK_EXPLORER_URL: joi.string().required(),
CHECK_EVENT_OCCURRED_AT: joi.boolean().default(true),
CHECK_USER_CREATED_AT: joi.boolean().default(true),
DATABASE_CONNECTION_POOL_URL: joi.string().required(),
DATABASE_URL: joi.string().required(),
DATADOG_URL: joi.string().required(),
DISABLE_FAUCET: joi.boolean().default(false),
DISABLE_LOGIN: joi.boolean().default(false),
INCENTIVIZED_TESTNET_URL: joi.string().required(),
INFLUXDB_API_TOKEN: joi.string().required(),
INFLUXDB_BUCKET: joi.string().required(),
INFLUXDB_URL: joi.string().required(),
IRONFISH_API_KEY: joi.string().required(),
MAGIC_SECRET_KEY: joi.string().required(),
NETWORK_VERSION: joi.number().required(),
NODE_UPTIME_ENABLED: joi.boolean().default(true),
NODE_ENV: joi.string().required(),
PORT: joi.number().default(8003),
}),
}),
DatadogModule,
LoggerModule,
...JOBS_MODULES,
...REST_MODULES,
],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer): void {
consumer
.apply(RequireSslMiddleware, ContextMiddleware)
.forRoutes({ path: '*', method: RequestMethod.ALL });
}
}