How I manage multiple NestJS applications

Sdílet
Vložit
  • čas přidán 10. 12. 2023
  • In this video we walk through how to create and maintain multiple Nest applications in a single repository using Nest CLI's built-in support for monorepo. Plus we'll walk through how to create libraries to share code across your applications.

Komentáře • 44

  • @z0rn86
    @z0rn86 Před 7 měsíci +10

    i would highly suggest to use nx, instead of the nest monorepos, as it offers a wide variety of different plugins (i.e., also allows to host react, angular, ... apps within the monorepository)

    • @mariusespejo
      @mariusespejo  Před 6 měsíci

      Yes this is a simple Nest-only setup, anything more complicated use nx or turborepo

  • @robtangled8816
    @robtangled8816 Před 5 měsíci

    Great video!! Thanks a lot!!!! Keep it up!

  • @dungng1321
    @dungng1321 Před 7 měsíci

    Thank you 🎉

  • @pathanazamkhan6746
    @pathanazamkhan6746 Před 6 měsíci

    Thank you so much for sharing the knowledge i would suggest if you could make a seperate vedio explaining nestjs microservices because thats something i want to learn and you are my go to option for nestjs tutorials 😂

    • @mariusespejo
      @mariusespejo  Před 6 měsíci

      Thanks for the suggestion! I do hope to create much more nest content this year!

  • @nikitabalakin1498
    @nikitabalakin1498 Před 6 měsíci

    Thank you sir

  • @mochamadrasyad338
    @mochamadrasyad338 Před 7 měsíci

    Thanks 🙌😊

  • @joebowbeer
    @joebowbeer Před 7 měsíci +1

    Very helpful, as always. I love the NestJS content. Building on this example, I'd like to see what a devcontainer would look like. To deploy to k8s, would you publish a separate image for each app? At what point would you think about adding nx?

    • @mariusespejo
      @mariusespejo  Před 7 měsíci

      There are some challenges with using docker on a monorepo, if you plan to do that honestly you would be better off just using turborepo or nx which likely would offer much better support for it.
      For example here’s some docs from turborepo that talks about some of the challenges and how you’d solve it: turbo.build/repo/docs/handbook/deploying-with-docker
      Not very familiar with nx yet, but in general I think any setup that’s slightly more complex than what I show here is probably worth switching over. Also if you think you’d mix other types of applications into your monorepo, then this solution won’t work.

  • @joshdev4404
    @joshdev4404 Před 5 měsíci

    Great video, Marius! Very insightful. 👏
    I have a question, though… will those sub-apps share the same env created in the root?

    • @mariusespejo
      @mariusespejo  Před 5 měsíci +1

      That would depend on your deployment strategy

  • @fredhermannramandaniarivo7464

    Nice video, thank you. This is what I wanted ever since.
    In this architecture, is it possible to import one or more prisma models from one application to another application?
    For example: Application "Auth" with model "User" and Application "Blog" with model "Author", I import the User model into the Author model to provide a relationship.

    • @mariusespejo
      @mariusespejo  Před 2 měsíci

      You should be able to, turborepo supports having internal libraries specifically for code that is shared across applications.

  • @thang1324
    @thang1324 Před 2 měsíci

    Thank you for the content, Sir. Also, could you explain more about migrations in Nestjs monorepo? I'm using TypeOrm and I haven't figured out what is the best practice since when I build each app, Nestjs use webpack and bundles the codes into one file only.

  • @lardosian
    @lardosian Před 7 měsíci +1

    Do you also use something like NX and what would it bring to to the table, thanks!

    • @mariusespejo
      @mariusespejo  Před 7 měsíci +1

      Haven’t tried NX yet but have heard good things. I have personally tried turborepo however which is another alternative, I have a video on using that to create a nest + react monorepo if you’re interested in seeing what that looks like

    • @lardosian
      @lardosian Před 7 měsíci

      @@mariusespejo Thanks Marius.

  • @gadgetboyplaysmc
    @gadgetboyplaysmc Před 7 měsíci

    What terminal is that? (Also what icon set are you using on VSCode? Looks new and slick!

    • @kareemmahlees3597
      @kareemmahlees3597 Před 7 měsíci

      I think the terminal is Wrap.

    • @mariusespejo
      @mariusespejo  Před 7 měsíci +1

      Warp terminal in beginning. I was using Monokai Pro theme here, I think that comes with its own icons? I don’t really remember changing the icons manually

  • @luissarabia8436
    @luissarabia8436 Před 7 měsíci

    I'd like to see an example of docketing microservices into a monorepo, but each separate microservice in a different container, isn't that far-fetched or is it?

    • @mariusespejo
      @mariusespejo  Před 7 měsíci

      You just want multiple docker containers made off of a monorepo? Yeah I don’t see why not, it’s possible but it will have its challenges since we have a bunch of code shared

  • @SatryaNouvanda
    @SatryaNouvanda Před 7 měsíci

    is it possible in production we decide which app or more apps should be start first and in some condition triggers another app to start?

    • @mariusespejo
      @mariusespejo  Před 7 měsíci

      In the video I mentioned that you’d still need to individually use a command to start each app, so the logic or order of how that happens is ultimately up to you. Not sure what those conditions would look like for you but you definitely could write your own script to pull it off I imagine

  • @mehdiwow5388
    @mehdiwow5388 Před měsícem

    What is the name of ur icon and theme in ur vscodeM

  • @ViciuSRO
    @ViciuSRO Před 6 měsíci

    Hi! How do you build your shared library. Can you publish this lib in a private repo and install it in your apps and make use of it this way? Can you keep the code of this shared library in the same monorepo?

    • @mariusespejo
      @mariusespejo  Před 6 měsíci +1

      Good questions. You can build the shared library just like the apps using “nest build library-name”, however once you import the library into an app technically it should already become packaged with that app’s dependencies when that app is built so you might not need the extra build step. The intention here is to have the library share code within the same monorepo, almost like you have your own private npm, so yes on your last question that is the point (as also shown in this video)

  • @illia_mikhow
    @illia_mikhow Před 5 měsíci

    Great video! I am looking for a solution that will separate my REST API code with Background Workers Logic (CRON + Bull). I thought that running these functionalities in different apps (and on different threads) can boost performance. Do you think that this a good usecase with concept showed in the video?) Thanks for opinion and useful videos!

    • @mariusespejo
      @mariusespejo  Před 5 měsíci

      Yes! If your cron jobs are expensive it would be a good idea run those in their own server (or even server-less) but the big selling point here with monorepos would be the ability to share code. So for example if your rest api runs the same queries as your cron and they are separate “apps” then that code sharing is much easier in a monorepo.
      Alternatively for Nestjs specifically I know they have the ability to have dynamic modules, so another option for example is one app deployed to multiple servers but only one specific server is designated as the “worker” for cron jobs if that makes sense, e.g. you can use an env variable to enable a dynamic module which contains your scheduler

  • @veracsthedefiled
    @veracsthedefiled Před 7 měsíci

    Is it possible to include non-NestJS projects in this monorepo? For example, a react native project or ElectronJS project

    • @mariusespejo
      @mariusespejo  Před 7 měsíci

      This setup is specifically for Nest apps only, if you’re interested in adding other non-Nest project I recommend using turborepo or NX. I have a video on turborepo in the channel if you’re interested

    • @veracsthedefiled
      @veracsthedefiled Před 7 měsíci

      @@mariusespejo Thanks, but the problem with turborepo approach is NestJS server doesn't automatically restart when imported code from shared typescript project has changed, if I restart it manually it works (latest changes applied) but that's cumbersome, in your video its just React and NestJS without a shared project and so it doesn't solve this problem

    • @mariusespejo
      @mariusespejo  Před 7 měsíci +1

      I see, in that case NX might be good to try although I have personally haven’t had a chance to so not sure if it solves your problem

  • @andrejs0tube
    @andrejs0tube Před 6 měsíci

    Hi! How about share types in monorepo for frontend and nest?
    Great videos, Thanks!

    • @mariusespejo
      @mariusespejo  Před 6 měsíci

      In the channel I have a video of creating nest + react monorepo using turborepo, should allow you to share types. Also have a video on using ts-rest with nest, which creates a end-to-end type safety between your api and client. Check those out!

  • @Justdoit-oo2bp
    @Justdoit-oo2bp Před 3 měsíci

    Hı bro can you do a video about rabbitmq usage in nestjs ? I need it too much.i can not find a good video on youtube.

  • @VeeWebCode
    @VeeWebCode Před 5 měsíci

    I love you.........

  • @tamasmolnar4157
    @tamasmolnar4157 Před 2 měsíci

    In a real world scenario it is not so simple and easy.