在私人应用程序之间共享Nestjs实体(或模块)的最佳方法

发布于 2025-02-11 13:42:44 字数 301 浏览 0 评论 0原文

我们一直在使用Nestjs来构建后端服务(从现在开始)。我们还将创建另一个NESTJS应用程序,该应用程序取决于与原始数据的同一数据库,因此我需要访问原始项目中的实体(TypeOms的实体)。在多个Nestjs应用程序之间共享实体(或模块)的最佳方法是什么?我认为

  1. 创建实体文件的某些方式可能与原始应用程序中的一个相同。 (复制和粘贴)
  2. 创建模块(需要共享)作为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

  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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以酷 2025-02-18 13:42:44

最佳努力/结果解决方案可以是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文