Fireship · @fireship

NestJS in 100 Seconds

Uploaded July 30, 2021 · Length 2:21

NestJS in 100 Seconds

Summary

NestJS framework for building scalable server-side applications with TypeScript.

  • nestjs
  • typescript
  • nodejs
  • server-side
  • framework
  • scalability

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    nest js is a node.js framework for

  2. 0:02

    building scalable server-side

  3. 0:04

    applications with typescript it provides

  4. 0:06

    a suite of tools that leverage either

  5. 0:08

    fastify or express to facilitate

  6. 0:10

    rapid development and predictable

  7. 0:12

    readable code it supports rest and

  8. 0:14

    graphql apis out of the box or you might

  9. 0:16

    use it to build a full stack application

  10. 0:19

    using the model view controller pattern

  11. 0:21

    similar to frameworks like laravel

  12. 0:23

    or ruby on rails and it contains a ton

  13. 0:25

    of built-in modules to work with

  14. 0:26

    databases

  15. 0:27

    handle security implement streaming and

  16. 0:29

    anything else you can imagine doing in a

  17. 0:31

    server side application

  18. 0:32

    nest has its own very powerful command

  19. 0:34

    line tool and you can scaffold out a new

  20. 0:36

    project with the nest

  21. 0:37

    new command that provides a code base

  22. 0:39

    pre-configured with jest for testing and

  23. 0:41

    set up with typescript to help us write

  24. 0:43

    more readable and reliable code in the

  25. 0:45

    source directory you'll notice a

  26. 0:46

    controller which is a fundamental

  27. 0:48

    building block of the framework

  28. 0:49

    it's responsible for handling incoming

  29. 0:51

    http requests

  30. 0:52

    and returning responses back to the

  31. 0:54

    client to implement a controller simply

  32. 0:56

    add the controller decorator

  33. 0:58

    to a class then inside the class you can

  34. 1:00

    implement methods

  35. 1:01

    and decorate them with http verbs like

  36. 1:03

    git

  37. 1:04

    post patch put etc by default this will

  38. 1:07

    create an http endpoint on the root url

  39. 1:09

    but you can pass a string to the

  40. 1:11

    decorator to

  41. 1:12

    change the route or implement dynamic

  42. 1:14

    route parameters in addition

  43. 1:15

    nest provides other decorators to

  44. 1:17

    control things like the status code and

  45. 1:19

    headers then

  46. 1:20

    in the method itself parameter

  47. 1:21

    decorators can be used to access the

  48. 1:23

    request parameters or body

  49. 1:25

    and finally the return value from the

  50. 1:27

    method is the response body

  51. 1:28

    that gets sent back down to the client

  52. 1:30

    what's awesome about nest

  53. 1:32

    is that you can use the cli to

  54. 1:33

    automatically generate more controllers

  55. 1:35

    to keep your code organized as it grows

  56. 1:37

    in complexity

  57. 1:38

    but there's more to nest than just

  58. 1:39

    controllers a provider is a class that

  59. 1:42

    contains shared logic throughout the

  60. 1:43

    entire application

  61. 1:44

    and can be injected as a dependency

  62. 1:46

    where needed any class with the

  63. 1:48

    injectable decorator can be injected in

  64. 1:49

    the constructor of another class

  65. 1:51

    for example a provider can be

  66. 1:53

    implemented as a guard to handle

  67. 1:55

    role-based user authentication

  68. 1:56

    or it might be implemented as a pipe to

  69. 1:59

    efficiently validate and transform