#Reuse code/modules/services in different Nest.js apps in one repo

6 messages · Page 1 of 1 (latest)

lost granite
#

Hello Community!

I'm creating multiple microservice in one git repostitory. In both services I'm using partially we same integrations (for example AWS S3). I would like to reuse my service AWS S3 to have in /common folder and to be able to import it inside /service1 and /service2 without building private npm package. I want to avoid copy pasting the same service in **/service1 **and /service2. How to do it?

#

Reuse code/modules/services in different Nest.js apps in one repo

thin ember
#

How are you managing the multiplpe projects nad libraries? WHat monorepo approach are you using? Something custom, nx, turbo, something else?

lost granite
# thin ember How are you managing the multiplpe projects nad libraries? WHat monorepo approac...

So far nothing. I was wondering what is the best approach for managing it. I've seen the video explainig how to structure it using nx. Is it recommended way? What will happen to reusable packages, do I have to build it and keep the build dir inside the git repo or move it to private npm package? Reusable package has it own Nest.js dependencies and my service also has. Is it not making the service weight more?

Link to video:
https://www.youtube.com/watch?v=r9SnFrwH1gs&list=PLIGDNOJWiL1-zscX224pibRBb4RChTpgM&index=10

Hi everyone welcome to my another brand new playlist in this playlist, In this playlist, we are talking "all about Node js microservices"

Playlist All about Microservices
https://www.youtube.com/watch?v=_fK8g2dhzvU&list=PLIGDNOJWiL19WHIxJ0Q4aP4X3oljPha5n&ab_channel=Codewithtkssharma

Playlist on Nest JS Microservices
https://www.youtube.com/...

▶ Play video
thin ember
#

Personally, I use Nx. It allows everything to be setup automatically, it enforces the single-package-version policy that works best with NestJS, and overall, it integrates with Nest better than just about anything else, while still allowing for freedom of structure and development.

What will happen to reusable packages, do I have to build it and keep the build dir inside the git repo or move it to private npm package?
That depends, do you actually want to publish it, or do you want it to just get bundled into the applications? I usually just let Nx bundle things in with their webpack/swc config and call it a day. Same thing for react libraries into my react frontend. However, if you want, you are able to set up these libraries to b e publishable

Reusable package has it own Nest.js dependencies and my service also has. Is it not making the service weight more?
Those should set the @nestjs/ packages as peerDependencies and all of the microservices should use the same workspace version of Nest rather than installing the nest packages into multiple node_moduels directories. trust me, you'll thank me later

thorny ivy