1
00:00:03,000 --> 00:00:05,085
In this section we'll look at

2
00:00:05,085 --> 00:00:08,536
how we can deploy our Next.js app to production.

3
00:00:08,536 --> 00:00:11,412
And there are a few ways we can do that.

4
00:00:12,055 --> 00:00:13,983
One factor to consider is

5
00:00:13,983 --> 00:00:16,758
if we need all the Next.js features,

6
00:00:17,335 --> 00:00:20,088
or if we can export our Next.js app

7
00:00:20,088 --> 00:00:21,661
as a static website.

8
00:00:21,661 --> 00:00:24,729
All the Next.js features we used so far

9
00:00:24,729 --> 00:00:28,897
are compatible with exporting our website statically,

10
00:00:28,897 --> 00:00:31,021
so for our Blog application

11
00:00:31,021 --> 00:00:33,852
all the options are available to us.

12
00:00:33,852 --> 00:00:37,627
But if we use some of the more advanced features

13
00:00:37,627 --> 00:00:41,560
that we'll cover in the second part of the course,

14
00:00:41,560 --> 00:00:43,290
things like API routes

15
00:00:43,290 --> 00:00:46,043
or Incremental Static Regeneration,

16
00:00:46,043 --> 00:00:50,133
then we cannot create a statically exported website,

17
00:00:50,133 --> 00:00:54,301
we'll need to run it as a fully-featured Next.js app.

18
00:00:55,667 --> 00:00:57,283
In any case, the simplest way

19
00:00:57,283 --> 00:00:59,289
to run our application in production

20
00:00:59,844 --> 00:01:01,985
is to deploy it to a platform

21
00:01:01,985 --> 00:01:04,717
that supports Next.js out of the box.

22
00:01:05,290 --> 00:01:07,926
Vercel is the company that develops

23
00:01:07,926 --> 00:01:09,583
the Next.js framework,

24
00:01:09,583 --> 00:01:12,218
and it offers a serverless platform

25
00:01:12,218 --> 00:01:15,231
where we can easily deploy our projects.

26
00:01:15,231 --> 00:01:18,393
It's not the only platform that does that,

27
00:01:18,393 --> 00:01:21,556
Netlify also supports Next.js deployments.

28
00:01:22,432 --> 00:01:24,985
Now, if we want to run our application

29
00:01:24,985 --> 00:01:27,605
on our own servers we can also do that.

30
00:01:27,605 --> 00:01:30,964
In fact, we've already seen how that works locally

31
00:01:30,964 --> 00:01:33,584
when we ran our Blog in production mode

32
00:01:33,584 --> 00:01:35,599
with the "next start" command.

33
00:01:36,367 --> 00:01:38,661
All we need is basically a server

34
00:01:38,661 --> 00:01:40,260
with Node.js installed.

35
00:01:40,829 --> 00:01:43,370
This could be a server running in the cloud,

36
00:01:43,870 --> 00:01:46,413
like in Amazon EC2, Google Cloud,

37
00:01:46,413 --> 00:01:49,341
or any other cloud computing provider,

38
00:01:49,918 --> 00:01:52,197
or it could even be on hardware that

39
00:01:52,197 --> 00:01:53,399
we keep on premise.

40
00:01:53,962 --> 00:01:57,060
Even though it's usually more convenient

41
00:01:57,060 --> 00:02:00,545
to rent some servers in the cloud these days.

42
00:02:00,545 --> 00:02:03,255
Either way, the downside of running

43
00:02:03,255 --> 00:02:05,113
your own Next.js servers

44
00:02:05,113 --> 00:02:08,211
is that you need to set up the machines,

45
00:02:08,211 --> 00:02:10,997
maintain them, keep them up to date,

46
00:02:10,997 --> 00:02:14,638
think about how to scale if your traffic grows,

47
00:02:14,638 --> 00:02:15,412
and so on.

48
00:02:15,412 --> 00:02:17,580
While a platform like Vercel

49
00:02:17,580 --> 00:02:19,671
is a fully managed service.

50
00:02:19,671 --> 00:02:21,994
So these options are available

51
00:02:21,994 --> 00:02:24,240
for all Next.js applications.

52
00:02:24,240 --> 00:02:27,337
But, as I mentioned, if we don't use any

53
00:02:27,337 --> 00:02:30,202
of the more advanced Next.js features

54
00:02:30,202 --> 00:02:32,835
we can also export our application

55
00:02:32,835 --> 00:02:34,384
as a static website.

56
00:02:36,045 --> 00:02:38,088
And this means we can deploy it

57
00:02:38,088 --> 00:02:40,460
to pretty much any hosting platform.

58
00:02:41,025 --> 00:02:42,938
We can upload it anywhere

59
00:02:42,938 --> 00:02:45,234
that can host static websites,

60
00:02:45,234 --> 00:02:47,758
like Firebase Hosting, Amazon S3,

61
00:02:47,758 --> 00:02:49,977
or any of the dozens of other

62
00:02:49,977 --> 00:02:52,884
hosting solutions available out there.

63
00:02:53,690 --> 00:02:56,716
Or, again, we could run it on our servers,

64
00:02:56,716 --> 00:03:00,030
but in this case, since it's a static website,

65
00:03:00,030 --> 00:03:02,624
we don't need a server with Node.js,

66
00:03:02,624 --> 00:03:05,146
we can run any standard web server,

67
00:03:05,146 --> 00:03:06,587
like Nginx or Caddy,

68
00:03:06,587 --> 00:03:09,108
or some other open source software.

69
00:03:09,108 --> 00:03:11,414
Now, in the rest of this section

70
00:03:11,414 --> 00:03:14,295
I'll show you an example for each one of

71
00:03:14,295 --> 00:03:17,177
the four main options we have available.

72
00:03:18,253 --> 00:03:20,920
We'll start by deploying to Vercel,

73
00:03:20,920 --> 00:03:24,424
which as I mentioned is the simplest solution.

74
00:03:24,424 --> 00:03:28,461
It's fully managed and supports all Next.js features.

75
00:03:29,113 --> 00:03:32,390
Then we'll see how to statically export our website

76
00:03:32,890 --> 00:03:34,627
and host it on Netlify,

77
00:03:34,627 --> 00:03:37,570
just as an example of the many possible

78
00:03:37,570 --> 00:03:39,458
static hosting solutions.

79
00:03:40,108 --> 00:03:43,488
Then I'll show you one way to run your own web server

80
00:03:43,988 --> 00:03:46,926
by installing Nginx on a virtual machine

81
00:03:46,926 --> 00:03:48,762
running in Digital Ocean.

82
00:03:49,335 --> 00:03:51,685
And finally we'll see how to set up

83
00:03:51,685 --> 00:03:53,229
our own Next.js server,

84
00:03:53,229 --> 00:03:54,571
which I left as last

85
00:03:54,571 --> 00:03:57,323
because it's also the most difficult one,

86
00:03:58,024 --> 00:04:00,881
but I'll show you how to install Node.js

87
00:04:00,881 --> 00:04:03,167
and run our Next.js application,

88
00:04:03,738 --> 00:04:06,279
again using a Digital Ocean server.

89
00:04:06,779 --> 00:04:10,104
Be aware that running your own servers requires

90
00:04:10,104 --> 00:04:12,932
some knowledge of system administration,

91
00:04:12,932 --> 00:04:15,408
so unless you have specific reasons

92
00:04:15,408 --> 00:04:16,539
to do otherwise,

93
00:04:16,539 --> 00:04:18,589
I strongly recommend choosing

94
00:04:18,589 --> 00:04:20,712
a hosted solution like Vercel,

95
00:04:20,712 --> 00:04:23,753
that in fact we'll cover in the next video.

