在私人应用程序之间共享Nestjs实体(或模块)的最佳方法
我们一直在使用Nestjs来构建后端服务(从现在开始)。我们还将创建另一个NESTJS应用程序,该应用程序取决于与原始数据的同一数据库,因此我需要访问原始项目中的实体(TypeOms的实体)。在多个Nestjs应用程序之间共享实体(或模块)的最佳方法是什么?我认为
- 创建实体文件的某些方式可能与原始应用程序中的一个相同。 (复制和粘贴)
- 创建模块(需要共享)作为NPM软件包,然后将其安装在新项目中。 =>我觉得这太过分了,因为我需要创建帐户并向NPM付款以制作私人NPM模块。
有什么想法或建议吗?提前致谢!
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
- creating entity files which might looks same with the one in original applications. (copy and paste)
- 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最佳努力/结果解决方案可以是 monorepo 。这个想法是创建一个类型
library
的Nestjs项目,该项目可以持有您要共享的资产。其他实例可以从那里非常简单地导入资产/接口/类。如果您比Monorepos走得更远,那么NX之类的工具也是一种选择,但也需要更多时间来设置。
在我看来,复制/粘贴将是一场维护噩梦,手动库/依赖关系共享的努力几乎与使用诸如MonorePo模式之类的提供的解决方案相同。
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.