0

I currently have two modules:

  • Auth which handles login and registration
  • User which handles all user crud operations

Auth requires the User module to register and validate users. So currently, Auth imports the User module:

@Module({
    imports: [UserModule],
    components: [JwtStrategy, GithubStrategy, TokenService, LoginService],
    controllers: [AuthController],
})

However, as a result if I ever wanted to re-use these modules, I'd have to include both. Furthermore, if I moved the User module, I'd have to update all the references to it within the Auth module. Is there a better way to organise two dependent modules? Should they be combined?

Is there a better way to do this?

1 Answer 1

1

If your UserModule will be used everywhere, say in OrdersModules, NotificationsModule..., and you found yourself importing it and reimporting everywhere, then you should take a step to make this Module a GlobalModule, then it will be available everywhere in your project since it imported in RootModule i.e ApplicationModule

Just annotate your Module by @Global

Example

See also: Modules | Nest Documentations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.