Fireship · @fireship

Nx Quickstart - How to Scale a JavaScript Project

Uploaded June 4, 2019 · Length 9:40

Nx Quickstart - How to Scale a JavaScript Project

Summary

Learn how to use Nx to simplify project organization, share code, and scale a JavaScript project with multiple front-end applications and a back-end.

  • nx
  • javascript
  • project organization
  • code sharing
  • mono repo
  • angular
  • react
  • typescript

Transcript preview

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

  1. 0:00

    one of the biggest challenges of

  2. 0:01

    building a full stack web application is

  3. 0:03

    managing complexity if you're building a

  4. 0:05

    serious product you likely have multiple

  5. 0:07

    front-end applications that communicate

  6. 0:09

    with a back-end that share interfaces

  7. 0:10

    with multiple team members that need to

  8. 0:12

    collaborate efficiently today we're

  9. 0:14

    going to look at NX from Narwhal a tool

  10. 0:16

    that can dramatically simplify the way

  11. 0:17

    you organize tests and share code

  12. 0:19

    between multiple JavaScript applications

  13. 0:21

    if you're new to the channel like and

  14. 0:22

    subscribe and you can find the full

  15. 0:23

    tutorial on NX dev the tool itself is

  16. 0:26

    based on the best practices developed at

  17. 0:28

    Google to scale thousands of

  18. 0:30

    applications across thousands of

  19. 0:31

    developers in a single mono repo but you

  20. 0:34

    don't need to be operating at Google

  21. 0:35

    scale to see the benefits of NX it can

  22. 0:37

    be a very powerful tool for projects of

  23. 0:39

    all sizes and not just angular but full

  24. 0:41

    stack JavaScript in general so why do

  25. 0:43

    you big companies like Google Microsoft

  26. 0:44

    and Facebook like to manage their code

  27. 0:46

    in mono repos or in other words use a

  28. 0:48

    single git repository to manage multiple

  29. 0:50

    apps and libraries the simple answer is

  30. 0:52

    that this approach helps manage

  31. 0:54

    complexity by applying best practices

  32. 0:56

    organization-wide this delivers

  33. 0:58

    consistency and predictability in your

  34. 0:59

    code while also maximizing the ability

  35. 1:01

    to share code between projects but you

  36. 1:04

    can't just put all of your code in a

  37. 1:05

    single repo and expect to reap the

  38. 1:07

    benefits you need the right tool in

  39. 1:08

    place to test build and deploy your apps

  40. 1:10

    at scale and that's where NX comes in

  41. 1:12

    over the next 10 minutes we'll look at

  42. 1:14

    how complexity can grow very quickly in

  43. 1:15

    a full stack project we'll build two

  44. 1:17

    front-end applications one with angular

  45. 1:19

    and one with react and then a shared

  46. 1:21

    back-end with nest on top of that we'll

  47. 1:23

    add multiple shared libraries that can

  48. 1:25

    be used by all three of these apps let's

  49. 1:27

    go ahead and create a new NX workspace

  50. 1:28

    to see how it can help us manage a

  51. 1:30

    project like this from the command-line

  52. 1:32

    run npx create NX workspace followed by

  53. 1:35

    your organization or product name this

  54. 1:38

    will give us an empty workspace and

  55. 1:39

    we'll be writing most of our code in the

  56. 1:41

    apps and Lidz directories right out of

  57. 1:43

    the gate NX is going to help you

  58. 1:44

    separate your shared code from your

  59. 1:46

    application code for example you might

  60. 1:48

    have two front end applications one for

  61. 1:50

    your customers and one for your

  62. 1:51

    employees those apps would live in the

  63. 1:53

    apps directory but they might share

  64. 1:55

    common UI elements that would go in the

  65. 1:56

    libs directory so this works really well

  66. 1:58

    when you have a design system where you