Search code examples
expressnpmnestjstypeormnpm-publish

Best way to share NestJS entities(or modules) between the private applications


We've been using the NestJS to build the backend service(=original project from now on). We're also going to create another NestJS application which is depending on same database with the original one so I need to access the entities(typeorm's entities) in original project. What's the best way of the sharing the entities(or modules) between multiple NestJS applications? Some ways I've thought are

  1. creating entity files which might looks same with the one in original applications. (copy and paste)
  2. creating module(need to be shared) as a npm package and install it in new project. => I feel like it's quite overkill as I need to create account and pay to npm for making private npm modules.

Any ideas or suggestion? Thanks in advance!


Solution

  • The optimal effort/result solution may be a monorepo. The idea is to create a nestJS project of type library which can hold assets you want to share. Other instances can import assets/interfaces/classes very easly from there.

    If you go further than that into monorepos, tools like Nx are also an option but also require more time to set up.

    Copy/paste would be a maintenance nightmare in my opinion and manual library/dependency share is pretty much the same effort if not more as using provided solutions like monorepo pattern.