NestJS Config Module: Using environment variables

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 30

  • @AhmedMansour-tg5ez
    @AhmedMansour-tg5ez 16 днів тому

    A dense, yet fruitful video
    didn't know .env and config can do all fo that
    Thank You Vahid

    • @SakuraDev
      @SakuraDev  15 днів тому

      Thanks for watching, I'm glad you found it helpful!

  • @Mahadev-x7u
    @Mahadev-x7u 6 місяців тому +1

    The Best course of Nest js 💯 thank you 🔥

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

      Thank you so much for your support ❤️🙏

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

    very nice bro, thnaks(دمت گرم)❤❤❤❤❤❤

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

    Nice Video!!

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

      Thank you! I’m glad you liked it. More videos are coming soon, so stay tuned! 👍😊

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

    great one

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

      My pleasure! 😊

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

    which theme are you using?

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

    after adding env variables. our seed functionality is broken

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

      Hi, what is the error?

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

    What about type safe env (would love to see autocompletion intellisense to my env)

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

      It can easily be done with joi package. I will create an extra episode for this. But at end of course. For now we just turn out focus on authentication

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

      @@SakuraDev can it be done with Zod?

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

      @@robertz7329 I should test it. It would be great if we could do it with zod

  • @aawave
    @aawave 18 днів тому

    I come from another language/framework. Some solutions you apply seem strange to me:
    1. It seems hard to believe that such a basic feature as .env file support requires so much setup in NestJS. Is this the general way to do it, or is this applicable for your specific use case in your specific project? What is the basis that is generally enough for production level NestJS applications?
    2. Why don't you use ConfigService? Your approach without ConfigService leads to manual type conversion, which does not seem to be a good practice.
    3. Why would you disable TypeORM synchronize in prod, but enable it in dev? Won't this hide incorrect migrations and lead to bugs in stage/prod?

    • @SakuraDev
      @SakuraDev  16 днів тому

      Thank you for your detailed questions! 😊 Let me address each point:

    • @SakuraDev
      @SakuraDev  16 днів тому

      1- .env Setup in NestJS:
      Great observation! While .env support can feel more straightforward in some frameworks, NestJS intentionally separates concerns to align with its modular architecture. Using the @nestjs/config package for .env management is considered the standard way in NestJS, providing flexibility and scalability for larger applications. While it may seem like more setup initially, this approach ensures you can easily manage configurations across modules, which is particularly helpful for production-grade applications.

    • @SakuraDev
      @SakuraDev  16 днів тому

      2- ConfigService Usage:
      You’re absolutely right about the benefits of ConfigService-it abstracts away manual parsing and type conversion, making configuration handling cleaner and more robust. In this project, I chose a more direct approach to show how the system works at a lower level, but I agree that using ConfigService is a better practice for production. I'll make a note to cover this in future videos to highlight the advantages!

    • @SakuraDev
      @SakuraDev  16 днів тому

      3- TypeORM Synchronize:
      Enabling synchronize in development is helpful because it simplifies schema updates during active development. However, in production, it’s best to disable this and rely on proper migrations to ensure controlled and predictable database changes. You're correct that failing to test migrations thoroughly in a staging environment can lead to bugs in production. Best practice is to rigorously test migrations in a staging environment before deployment.

    • @SakuraDev
      @SakuraDev  16 днів тому

      By the way, if you enjoy learning and want to dive deeper into computer science topics made simple, I run another channel where I summarize key concepts from CS books. I would be very glad if you subscribe to my new channel: ua-cam.com/channels/ZYhXrFwhFUOXuSQNgfk-Sw.html

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

    Why this.configService.get("dbconfig.env.type) is not type safe and there is not autocompletion intellisense? It is just a string.

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

      Well, the config service does not have type safety out of the box. We need to use third party packages to add type safety

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

      ​@@SakuraDev I will keep this in mind. Thank you :)

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

      @@FejkMarcin1212 🙏🙏👋