Fireship · @fireship

7 Ways to Deploy a Node.js App

Uploaded July 26, 2021 · Length 9:14

7 Ways to Deploy a Node.js App

Summary

7 ways to deploy a Node.js app, including using own hardware, Google Cloud Platform, and Kubernetes, with trade-offs between cost, complexity, and scalability.

  • node.js deployment
  • cloud computing
  • kubernetes
  • serverless architecture
  • google cloud platform
  • vm deployment
  • docker deployment

Transcript preview

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

  1. 0:00

    in this video we'll look at seven

  2. 0:02

    different ways to deploy

  3. 0:03

    a server side application i built this

  4. 0:05

    api with node.js

  5. 0:06

    and now i'm ready to share it with the

  6. 0:08

    world but one does not simply deploy an

  7. 0:10

    app to production

  8. 0:11

    there's all kinds of different ways to

  9. 0:13

    get the job done with trade-offs between

  10. 0:15

    cost complexity and scalability

  11. 0:17

    on the surface deployment seems like it

  12. 0:19

    should be easy we just need a computer

  13. 0:21

    to host the app which we connect to the

  14. 0:22

    internet so it can handle requests from

  15. 0:24

    all of our users

  16. 0:25

    but resources are limited and that means

  17. 0:27

    we need to synchronize many computers

  18. 0:29

    all over the world

  19. 0:30

    just to keep things running fast by the

  20. 0:31

    end of this video you'll be able to

  21. 0:33

    analyze the trade-offs like a cto to

  22. 0:35

    choose the best deployment strategy for

  23. 0:37

    your server side application

  24. 0:38

    if you're new here like and subscribe

  25. 0:40

    then let's jump right into it

  26. 0:42

    first of all let's look at some of the

  27. 0:43

    features in this node.js application

  28. 0:45

    it requires node 16 which is the current

  29. 0:48

    bleeding edge version and that means

  30. 0:49

    wherever we deploy

  31. 0:50

    needs to support that exact version of

  32. 0:52

    node it provides a basic rest api built

  33. 0:55

    with the express js framework nothing

  34. 0:57

    too special

  35. 0:58

    but we want these endpoints to have

  36. 0:59

    extremely fast response times

  37. 1:01

    one of the endpoints though creates a

  38. 1:03

    websocket connection with the client

  39. 1:05

    that means that the connection between

  40. 1:06

    the client and server needs to stay

  41. 1:08

    open for a long time that'll come into

  42. 1:10

    play later because not every deployment

  43. 1:12

    strategy

  44. 1:12

    supports long-lived connections like

  45. 1:14

    that now one other important feature of

  46. 1:16

    this server

  47. 1:17

    is that it's stateless that means it

  48. 1:18

    doesn't store any persistent data in

  49. 1:20

    memory or on the disk

  50. 1:22

    that's needed between different http

  51. 1:24

    requests anything related to the

  52. 1:26

    application state would be stored in a

  53. 1:27

    dedicated database

  54. 1:29

    now to run this app on our local machine

  55. 1:31

    we use the npm start command made

  56. 1:33

    available in the package

  57. 1:34

    json file now the question becomes how

  58. 1:36

    do we do the same thing for a computer

  59. 1:38

    that's accessible to the greater

  60. 1:40

    internet the first option

  61. 1:41

    is to use your own hardware you might

  62. 1:43

    have an old pc laying around or maybe

  63. 1:45

    you want to invest in your own server

  64. 1:47

    rack or you can even use a 100

  65. 1:48

    raspberry pi like i showed in this video

  66. 1:50

    this was actually a common way to deploy

  67. 1:52

    a web application 15

  68. 1:54

    years ago because back in those days the

  69. 1:56

    cloud didn't exist yet

  70. 1:57

    almost every startup today will use the

  71. 1:59

    cloud because it's convenient and