nestjs : import another module(export & import)

◾️ create auth module and need to use UserService (※ youtube lecture content)

auth.module.ts / auth.controller.ts / auth.service.ts

user.module.ts / user.controller.ts / user.service.ts

import { Module } from '@nestjs/common';
import { UsersModule } from 'src/users/users.module';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';

@Module({
  imports: [
    UsersModule,
  ],
  controllers: [AuthController],
  providers: [AuthService],
})
export class AuthModule {}

◾️ UserModule exports UsersService

import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { UserSchema } from './schemas/user.schema';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';

@Module({
  imports: [MongooseModule.forFeature([{ name: 'User', schema: UserSchema }])],
  controllers: [UsersController],
  providers: [UsersService],
  exports: [UsersService],
})
export class UsersModule {}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です