This setup has the best developer experience

Поділитися
Вставка
  • Опубліковано 5 жов 2024

КОМЕНТАРІ • 105

  • @iUmerFarooq
    @iUmerFarooq 6 місяців тому +2

    Upload more NestJs tutorials. And nest tips maybe in short 💚
    Thank you very much for your time and effort 😊

    • @mariusespejo
      @mariusespejo  6 місяців тому +1

      I definitely hope to produce more, just need to find the time 😄

  • @gosnooky
    @gosnooky 7 місяців тому +3

    If the monorepo route isn't for you, or you have an existing stack and converting to a monorepo isn't practical, you can always create a separate npm scoped library that holds your contracts and you import the package into each project. In other words, an SDK.

  • @maulik13
    @maulik13 6 місяців тому

    Very high quality content! You have a very good way to take the viewer through the problem and how it is solved in the selected stack. Subscribed!

    • @mariusespejo
      @mariusespejo  6 місяців тому

      Thank you! I appreciate your comment 🙏

  • @mbex71
    @mbex71 7 місяців тому +1

    Good timing,, I'm doing research on this :D

  • @jhondellandal560
    @jhondellandal560 6 місяців тому +1

    Amazing work, man. If I may request, could you possibly create a video on how to deploy an app like that on an on-prem server and cloud server?

    • @jhondellandal560
      @jhondellandal560 5 місяців тому

      Definitely a +1 on this pretty please

    • @mariusespejo
      @mariusespejo  5 місяців тому

      Yeah I’d like to cover deployments in general at some point, but in general: The end result of this setup is really just a single Nest app. You would deploy it just like any other node app.

  • @permanar_
    @permanar_ 7 місяців тому +3

    Been waited for your new video buddy! It's always good to see you back.

    • @mariusespejo
      @mariusespejo  7 місяців тому +2

      Thanks! I’m looking to produce more consistently, it’s been a struggle haha

  • @4ware
    @4ware 7 місяців тому +8

    Is'nt that what trpc is supposed to do?

    • @mariusespejo
      @mariusespejo  7 місяців тому +4

      In terms of solving type-safety yes it’s one of the solutions although ts-rest takes a slightly different approach, e.g. it allows you to design your API as you would normally with REST. If I were using NextJS here I’d probably consider trpc however for NestJS ts-rest has a much better first class support for it. Also trpc defines the API implementation as the contract whereas ts-rest keeps it separate. There are some benefits to that.
      ts-rest.com/docs/comparisons/rpc-comparison

    • @FunctionGermany
      @FunctionGermany 7 місяців тому +2

      trpc does it better than a neutral contract. with trpc your "source of truth" is the backend and you only need to match the frontend to adhere to it. with this setup the "source of truth" is external to both frontend and backend and any change to the contract requires changes in 2 spaces, not just 1.

    • @mariusespejo
      @mariusespejo  7 місяців тому

      Like I said, it’s just a different approach with its own tradeoffs. There is no black and white “better” for every situation, e.g. from the link I posted above they talk about a good example:
      “One example of this is with NX, in NX you can rebuild only "affected" packages, however, if you export your contract (e.g. tRPC) from the backend, your front end will need to be rebuilt as well. ts-rest negates this issue by allowing (in NX) for a library for the API contract to be created, this then means the only case in which the front and backend need to be rebuilt is when the contract changes.”
      Do understand that I am personally not saying either one is better, just that in this specific setup ts-rest has much better direct support for nestjs (that I’ve seen, I could also be wrong). Both are great tools.

    • @maulik13
      @maulik13 6 місяців тому

      Contract first is also a valid approach which both client and server must adhere to. And in this case neither backend or frontend would own it. In the non-node world it’s not uncommon to do it. One advantage here is that clients can use mock data on contracts to already start testing without waiting for the backend implementation to be done.

  • @hasst9261
    @hasst9261 5 місяців тому

    I am really interested watching your videos. Keep it up!

    • @mariusespejo
      @mariusespejo  5 місяців тому +1

      thanks, glad you’re finding the channel useful!

    • @hasst9261
      @hasst9261 5 місяців тому

      @@mariusespejo I am watching the all videos on the channel!

  • @shakapaker
    @shakapaker 7 місяців тому +1

    so basically it's review on how to use ts-rest, nice video like your quality that you highlight things and nice voice

    • @mariusespejo
      @mariusespejo  7 місяців тому +1

      Yes but in combination with making it work with turborepo, a couple folks in the comments were asking to see that example. Thanks for stopping by!

  • @ernestogimeno646
    @ernestogimeno646 6 місяців тому +1

    Thanks for this video! Do you have an example/hints on how to dockerize this app to deploy using the docker image?

  • @sushantrajbanshi4508
    @sushantrajbanshi4508 7 місяців тому +2

    Could you please share the Github repo for this awesome setup, please ? 🙏

  • @csabapadar9978
    @csabapadar9978 7 місяців тому

    Thank you, interesting concept. I really like this monorepo approach. I belive we can achive something similar with OpenAPI as a contract and we can generate the models / api client. It would be nice to have some generator, which would give us the controllers with DTO validation already.

    • @mariusespejo
      @mariusespejo  7 місяців тому

      You totally can do that, but writing the contract in Typescript provides the best experience in my opinion vs writing OpenAPI spec by hand, there is no codegen necessary because we’re already writing in TS to begin with. Btw if swagger docs is the requirement, you can also generate openAPI from the ts-rest contract.

    • @johnisutsa1641
      @johnisutsa1641 7 місяців тому

      @@mariusespejo
      How can one generate openAPI swagger docs from the ts-rest contract? And will it be accessible from the /docs route?
      Thank you for the awesome video.

    • @mariusespejo
      @mariusespejo  7 місяців тому

      @johnisutsa1641 ts-rest has first-class support for it, you can see usage and examples for Nest and express below. And yes, it’s up to you which path you host it on
      ts-rest.com/docs/open-api

  • @wshark1948
    @wshark1948 Місяць тому

    pay attention that the manual for turborepo 1.x but if you install it now you will get by default turborepo 2.x and it has many breaking changes.

  • @archip8021
    @archip8021 7 місяців тому

    Love this stack. Good vid!

  • @abdirahmann
    @abdirahmann 7 місяців тому +2

    how can i combine multiple `s.router` objects?

    • @mariusespejo
      @mariusespejo  7 місяців тому +1

      Are you talking about the contract routers? You just nest them inside another one, so like you need a root router with keys to other nested routers if that makes sense

    • @abdirahmann
      @abdirahmann 7 місяців тому +1

      @@mariusespejo thanks, i just figured it out the other day.

  • @khantsithuphyo5484
    @khantsithuphyo5484 6 місяців тому

    Make full project tutorial for movie streaming api,food delivery,etc...

  • @Ramtinss
    @Ramtinss 7 місяців тому

    Great video.
    I'm interested to know what application are you using for drawing on canvas and writing document in the same place? I've been looking for something like this!

    • @mariusespejo
      @mariusespejo  7 місяців тому

      This was eraser.io I was actually trying it for the first time, check it out!

  • @nikhilgoyal007
    @nikhilgoyal007 3 місяці тому

    thank you! does ts-rest set up work with angular too ? Any guidance / link etc. would be super appreciated! thanks again. (I did not not see angular support in the docs but google AI says it is possible so was hoping to get your take / input)

    • @mariusespejo
      @mariusespejo  3 місяці тому

      The base client is based on Fetch API so it should be agnostic to any client

  • @clagccs
    @clagccs Місяць тому

    Hi! A question: is ts-rest full compatible with every NestJS functionality like pipes,guard,middlewares,interceptors? did you find any problem using Ts-Rest with NestJS? thank you!...

    • @mariusespejo
      @mariusespejo  Місяць тому

      They definitely should be on the single handler approach, since that’s a 1:1 mapping to regular controllers. Multi-handler might make things more complicated if you need to have those decorators at the method level. But other than that the only thing they call out in docs as not supported is version and global prefixes

  • @vahidnajafi756
    @vahidnajafi756 3 місяці тому

    Great video, thanks! How about input validation and swagger? Is it possible to implement them?

    • @mariusespejo
      @mariusespejo  3 місяці тому

      Yes you can generate openapi document from the contract, and nest can generate swagger docs off of that. And yes input validation is also supported

  • @wshark1948
    @wshark1948 Місяць тому

    packages/api-client should be named packages/api-contracts? Otherwise it gives an error

  • @danyakomik9414
    @danyakomik9414 4 місяці тому

    Is my assumption correct that for large applications, using a monorepo might not be the best choice due to potential coupling issues? For instance, if we decide to create a mobile application, we might face challenges with a monorepo setup. Similarly, if we want to split our server into microservices, having a monorepo could complicate things. On the other hand, is it true that a monorepo setup is more suitable for relatively small projects?

    • @mariusespejo
      @mariusespejo  4 місяці тому +1

      I think that it depends on your overall pipeline and deployment infrastructure. Fun fact for example, I believe google stores all of their code in a monorepo. Personally I would think of monorepos in a scenario where code sharing is beneficial, but like with everything it has pros and cons, and you need to pick based on which tradeoffs are okay with you. A native mobile app for example I don’t really see benefiting much from a monorepo where the other apps in the repo are in totally different languages and technologies.

  • @AlessioCollura
    @AlessioCollura 6 місяців тому

    I was just searching for a tutorial like this. I have one question. You are not using DTOs because you set a lot of constrains in the controller with the contracts, but in the communication between controllers and services or services and services you still need them. I guess. There's a way to directly derivate a DTO from a contract?

    • @AlessioCollura
      @AlessioCollura 6 місяців тому

      Now that I think more about it, can it be used to validate input on the frontend and generate error messages? Like "this field is required"?

    • @mariusespejo
      @mariusespejo  6 місяців тому +1

      The “library” in this video where we store the contract can also export other things, e.g. you can export the zod schemas that you create or you can export the type inferred from those schemas. That basically gives you the “shape” of your DTOs that you can pass around between services. And yes technically you can also import zod schemas on the frontend and use it for validation. E.g. in react you can use it with react-hook-form which has support for zod

  • @ReggieStylezHD
    @ReggieStylezHD 7 місяців тому

    Hey great vid! Do you have a video on how to use nestjs serve static with this setup?

    • @mariusespejo
      @mariusespejo  7 місяців тому +1

      Thanks! I covered it in an on older turborepo setup vid, take a look here:
      ua-cam.com/video/nY0R7pslbCI/v-deo.html

  • @davidodun608
    @davidodun608 7 місяців тому

    Please can you do a tutorial of combining nextjs and nestjs

    • @mariusespejo
      @mariusespejo  7 місяців тому

      It’s basically the same idea, but now you deploy with two servers. What are you looking for exactly?

  • @AhmedElBanna
    @AhmedElBanna 6 місяців тому

    What is the tool you use for diagrams in this video please

    • @mariusespejo
      @mariusespejo  6 місяців тому +1

      Eraser.io it’s pretty cool!

  • @milos018
    @milos018 7 місяців тому

    Nuxt 3 is ruling the end-to-end type-safety, no extra packages needed, just saying it's worth checking out...

    • @mariusespejo
      @mariusespejo  7 місяців тому

      Are you saying nuxt can create type-safe APIs on it’s own? I couldn’t find anything with a quick doc/google search but I’m not as familiar with it. I do know with NextJS server components also solves the problem since you can make backend calls right in component code

  • @zeroxdeveloper
    @zeroxdeveloper 5 місяців тому

    How do you handle cookies on the server with this setup, the ts-rest headers don't seem to work as intended, and also when you add the monorepo internal package to the nestjs' dependencies it messes up the transpiling and adds other folders from the root of the monorepo to the dist folder. I did some hacky stuff to go around it but i'd love to know if there are optimal ways of handling both of these issues

  • @sabirkhan6898
    @sabirkhan6898 6 місяців тому +1

    First of all thank you for content of such quality.
    Could you also share the GitHub repository? I'm encountering an issue when attempting to import the api-contract package into the Nest server. I'm receiving the following error message: "Cannot find module 'api-contract' or its corresponding type declarations." Importing with a relative path resolves the issue: "import { contract } from './../../../../packages/api-contract/dist';". Interestingly, importing in the Vite project functions correctly. I've added the dependency to both projects' package.json files.

    • @wshark1948
      @wshark1948 Місяць тому

      I have now the same issue, have you resolved it? But for me it doesn't work not for app, neither for client

  • @agoranaosei
    @agoranaosei 3 місяці тому

    Have you encountered any errors when importing the react mui library to the frontend project? It seems it does not play well with the rollup commonjs plugin

    • @mariusespejo
      @mariusespejo  3 місяці тому

      Sorry I haven’t used mui

    • @agoranaosei
      @agoranaosei 3 місяці тому

      @@mariusespejo Hey sure no problem. For anyone having issues with MUI what worked for me was to exclude the node_modules folder in the rollup commonjs plugin like this: commonjs({ exclude: [/node_modules/] })

  • @MrChrisk8er
    @MrChrisk8er 4 місяці тому

    what if working as a team front-end and back-end, and the front-end cannot be allowed to access the back-end source code?

    • @mariusespejo
      @mariusespejo  4 місяці тому +1

      Monorepo is only for the benefit of having the code in the same place, sounds like you have a scenario where you probably shouldn’t use it

    • @MrChrisk8er
      @MrChrisk8er 4 місяці тому

      @@mariusespejo I see... Thanks man..

  • @chambaderaphael8946
    @chambaderaphael8946 7 місяців тому

    Hmmm... I think I prefer a monorepo + nestjs graphql + codegen urql to share typescript type

    • @mariusespejo
      @mariusespejo  7 місяців тому

      Yeah not a bad approach, graphql has its own pros/cons

  • @Justdoit-oo2bp
    @Justdoit-oo2bp 7 місяців тому

    Hey dude,ypu are perfect in nestjs.can you do a microservices tutorial by nestjs?

    • @mariusespejo
      @mariusespejo  7 місяців тому

      Definitely on my todo list

    • @Justdoit-oo2bp
      @Justdoit-oo2bp 6 місяців тому

      @@mariusespejo i am waiting for it dude.

  • @iUmerFarooq
    @iUmerFarooq 6 місяців тому

    Create something like industrial projects in nestjs how it is use in industry 🙃

  • @ayushshende4290
    @ayushshende4290 7 місяців тому

    How should be the monorepo setup if I want to make a server side rendered web app so nextjs with nestjs(using both these tech together does this make sense)? What are the pros and cons of using ts-rest over something like graphql, trpc ?

    • @mariusespejo
      @mariusespejo  7 місяців тому +1

      If you decide to use NeXtjs I would recommend you first try to see if you can get away with just doing it all in that one application. Utilize making direct backend requests (e.g. database calls) in Server Components within the new App Router. If you find that you need a much more sophisticated backend, NeStJS will provide you with a lot more flexibility and yes you can still follow this exact setup. It just would mean that in your deployment strategy you will have to think about having two applications to run.
      Your second question I think honestly would be best explained in another video but if I can think of a couple key points:
      Ts-rest and trpc are alternatives to each other. Ts-rest focuses on REST (meaning any client can still make requests the traditional way even without an api client) and tRpc is very much rpc-like (hence why both are named this way). Ts-rest keeps the contract as an external source of truth, whereas with trpc the API implementation itself is the source of truth. There are pros/cons to these approaches but hard to get into in a comment here.
      GraphQL I feel like is an entirely different beast. Think of it more like a complete alternative to REST, and that comparison alone is a pretty loaded topic. It does not however solve type-safety like ts-rest and trpc does because it defines the API schema in an entirely different language. So the only way it could help with typescript is via auto generated types. You’ll notice that ts-rest for example we didn’t have to generate anything, it’s already in typescript.
      Anyways hope that gets you some high-level differences, I’ll think about covering this in a follow up video

  • @levelupprog
    @levelupprog 7 місяців тому

    Hi @MariusEspejo , thanks for the video ,i really enjoy this setup , i have been trying to implement it in my own project and have trouble setting cookie headers , usually i would set it with response.setHeader, do you have any idea on how to achieve the same outcome using ts-rest ?

    • @mariusespejo
      @mariusespejo  7 місяців тому

      As far as I know in ts-rest contracts only request headers can be defined upfront, but I don’t see any reason for it to affect response headers.

    • @levelupprog
      @levelupprog 6 місяців тому

      @@mariusespejo Thanks for your response :) , In the end i've found a solution so we need to pass the passtrough option to true in the Res anotation for tsHandler to maintain control over the response handling.
      @Res({passtrough: true}) response
      Thanks again for your content and taking the time to answer my comment. Keep it up :D

    • @mariusespejo
      @mariusespejo  6 місяців тому

      Nice good to know!

  • @danijelprskalo3675
    @danijelprskalo3675 7 місяців тому

    Hi,Can you still use all Nest features (Like Guards etc.)or is there some limitation there?

    • @mariusespejo
      @mariusespejo  7 місяців тому +1

      Good question, ts-rest also supports “single handler approach” meaning if you want to have individual controller methods for each route you can still do that. The effectively means you can still individually add extra decorators such as guards. Also any global guard should still work I believe
      ts-rest.com/docs/nest/#single-handler-approach---easy-migration-and-flexibility-%EF%B8%8F

  • @FabuBrik
    @FabuBrik 7 місяців тому

    How are you going about deploying this stack? Nextjs + trpc has been so simple with vercel.

    • @mariusespejo
      @mariusespejo  7 місяців тому +2

      I only briefly mentioned it in the video but since the React client here is a SPA, you can actually have the Nest server statically serve it in production so that you only have one server. In that scenario, it’s just as easy. Deploy it anywhere you can deploy a node app.
      Btw it’s worth mentioning that NextJS with the app router and server components already solves problems with lack of type-safety, you might not even need trpc unless you have route handlers. Anyways NextJS in general is the alternative to this whole thing, however NeStjs opens you up to a much more mature API framework with lots of possibilities.

    • @FabuBrik
      @FabuBrik 7 місяців тому

      @@mariusespejo thanks for the reply. I definitely agree Nest is more robust.

  • @danijelprskalo3675
    @danijelprskalo3675 7 місяців тому

    Hi, can you elaborate/give advice how would one go about hosting this setup but insted of react its nextjs with nestjs,thanks! Not much experience with hosting in general

    • @mariusespejo
      @mariusespejo  7 місяців тому

      I would recommend learning about hosting nodejs apps and what that generally requires and what different options there are. There is no one way to do it, the answer is always “it depends”, specifically on your requirements. It’s not really easy to explain in a comment because you have so many options depending on what balance of complexity vs cost you want. For example you can host on VMs on the cloud and configure everything yourself, you could do a containerized strategy like with docker, you could go serverless… lots of different platforms which allow you to do these things
      With a nest + next setup you effectively have two apps to deploy… so you want to decide do you want to run both in one instance of a machine? Do you want them separate (e.g. so each one can scale on their own)?
      Sorry not really giving you a solid answer here but hopefully that gives you some starting points. Will think about a video covering various deployment options

  • @tafaxtra
    @tafaxtra 7 місяців тому

    How do you implement core nestjs functionalities like UseGuards for specific routes in this case?

    • @mariusespejo
      @mariusespejo  7 місяців тому

      So in this video I showed ts-rest’s “multi-handler” approach for maximum type-safety, but they do also allow “single-handler” approach which would bring you back to traditional single controller method per route, which should allow you to add any other decorator that you need for the method. Although I haven’t tried that myself specifically with guards

  • @InventoryGeneric
    @InventoryGeneric 7 місяців тому

    Thanks for the tutorial. I'm getting an error on the 'async handler()' part of the API implementation "The inferred type of 'handler' cannot be named without a reference to '.pnpm/@ts-rest+core@3.33.0_zod@3.22.4/node_modules/@ts-rest/core'. This is likely not portable. A type annotation is necessary."
    Have you encountered this issue or do you know how to resolve it?

    • @mariusespejo
      @mariusespejo  7 місяців тому +1

      Not familiar with that error but it might be specific to pnpm monorepos, you might need a slightly different tsconfig setup than mine
      Take a look through this thread: github.com/microsoft/TypeScript/issues/42873#issuecomment-906308997

    • @InventoryGeneric
      @InventoryGeneric 7 місяців тому

      @@mariusespejo thanks for your reply, that thread was really helpful!!

  • @danijelprskalo3675
    @danijelprskalo3675 7 місяців тому

    Do you have experience with next.js instead of react? I followed but used next.js,works also but now thinking about hosting,also can't get react query to work on server side in next..any opinion or experience?

    • @mariusespejo
      @mariusespejo  7 місяців тому +1

      I do use Next in some current projects. Honestly if you are using NeXt, try to see how far you can get with using just Next on its own. If you utilize Server Components in the new app router, you’ve already got type-safety right there. No need for actual api routes. If you do end up needing a more sophisticated backend and need to introduce a second application (NeSt in this case) then yes this setup totally still works, it just means that your deployment strategy will require spinning up two servers. Regarding your question on using react-query, two things: 1.) you DON’T have to. Ts-rest can also create a barebones client which just utilizes fetch under the hood, so you can use that in Server Components. 2.) If you do decide to use react-query in NeXt, you will have to do it in “use client” components. So yes it can still work and is still useful in a lot of situations

    • @danijelprskalo3675
      @danijelprskalo3675 7 місяців тому

      ​@@mariusespejothanks,much appreciated!

  • @chudchadanstud
    @chudchadanstud 7 місяців тому

    How do you achieve type safety?
    You use a typed language like Rust, C++ or Go

    • @mariusespejo
      @mariusespejo  7 місяців тому +1

      Yeah I think you missed the point of the video but thanks for commenting for the algorithms 👍🏼

    • @fcnealvillangca7943
      @fcnealvillangca7943 7 місяців тому

      I don't think it will work in with other stack except node JS. this video is nice to get updated with new tech but it doesn't guaranteed to be useful in any situation. esp. if you're not using TS in backend.

    • @mariusespejo
      @mariusespejo  7 місяців тому

      Nothing is guaranteed to be useful in every situation. The point here was to have end-to-end type-safety across the entire stack. Most modern web clients are written in typescript. If your backend isn’t also in TS, it means that you would have to generate TS-compatible types to pull it off which is not great.

  • @Shaiky-k9y
    @Shaiky-k9y Місяць тому

    can i get your mai id

  • @assaffendell3640
    @assaffendell3640 2 місяці тому

    Love your content! How can I combine the types from the api-client package with a mongoDB + mongoose model?