'Create a common/shared microservice in nestjs

How can i create a microservice that contains all the shared/common login/classes between projects?

I have a gateway, and different microservices, let say auth and account. How can I share the user.model for example, considering that both services will use that entity?

Also considering that some common methods can be located in this common microservices in order to not have the code duplicated.



Solution 1:[1]

Check out the library module of microservice in Nestjs

https://docs.nestjs.com/cli/libraries

Here you can create a library module with the command

nest g library my-library

Then in that module, you can put the shared module like constant, util, etc which are common in all microservices.

To use that module import like this

import { MyLibraryModule } from '@app/my-library';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 iamsr