0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【NestJS】グローバルで使用するモジュールを別途class定義せずapp.moduleにグローバルの設定する

Last updated at Posted at 2023-03-11

概要

NestJSでグローバルで使用できるModuleを設定する場合、@Globalのアノテーションを付けてclassの定義をする方法が挙げられます。
ただ、ライブラリ等で用意されているModuleはclassの定義をせずに、グローバルの設定を付与したい時はあります。今回はその方法をメモ書きします。

対応方法

動的モジュールの機能を使用します。importする際にglobal: trueの設定を付与すれば実現できます。

設定サンプル

サンプルとして、HttpModuleをapp.moduleでglobal設定するものは、以下のようになります。

import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    {
      global: true,
      module: HttpModule,
    },
  ],
})
export class AppModule {}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?