3
votes

Let's say I have NestJs project, that consists of following parts, each with it's own git repository and deployed on different machines:

  1. Api service
  2. Message-queue processing workers service

Both of the services require part #3 - library for accessing RabbitMq. Let's say that #3 is some abstraction around the RabbitMq client that defines entities and services, that access MQ, so the modules #1. and #2. doesn't even know, they are working with RabbitMq. #3 is planned to be included / used as a library in #1 and #2, not as a microservice.

How should this be integrated together? Let's assume it from the perspective of API service:

  • It has the RabbitMq module inside the node_modules folder.
  • I want to use e.g. dependency injection in that RabbitMq library. Ideally, expose it as NestJs module, to be used in @Module imports of API module.

Should I use NestJs as peerDependency in the RabbitMq module?

I have like 3-4 shared-modules I need to share between the modules #1 and #2. Not just MQ.

2

2 Answers

3
votes

You can follow the approach of creating an npm module with the NestJS related modules as per dependencies. John Biundo has a good article on dev.to about creating NestJS modules and publishing them to npm.

1
votes

You can use the workspace concept of nest js. I think monorepo mode will be the one that can help without having the complexity of making npm modules etc.

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