All language subtitles for 032 Deploying Next.js Projects_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian Download
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:02,090 --> 00:00:05,090 Now, when it comes to deploying NextJS apps 2 00:00:05,090 --> 00:00:07,980 there are different hosting providers you can use 3 00:00:07,980 --> 00:00:09,420 and there are different ways 4 00:00:09,420 --> 00:00:11,910 of configuring your project as well. 5 00:00:11,910 --> 00:00:14,940 You can, for example, use environment variables. 6 00:00:14,940 --> 00:00:19,750 For example, to hold things like your database credentials. 7 00:00:19,750 --> 00:00:21,940 I'll not dive into that here. 8 00:00:21,940 --> 00:00:25,120 I do in my full next JS course, though. 9 00:00:25,120 --> 00:00:27,700 But for this example here we'll just keep 10 00:00:27,700 --> 00:00:30,540 the credentials stored here in this code 11 00:00:30,540 --> 00:00:34,330 and from a security perspective, this is fine by the way 12 00:00:34,330 --> 00:00:37,910 because this code will never end up on the client. 13 00:00:37,910 --> 00:00:39,880 It just might be unconvenient 14 00:00:39,880 --> 00:00:43,930 to use one and the same database and one and the same user 15 00:00:43,930 --> 00:00:46,210 for development and for production. 16 00:00:46,210 --> 00:00:48,210 But for this demo, this does not matter. 17 00:00:48,210 --> 00:00:50,620 So I'll stick to this approach here. 18 00:00:50,620 --> 00:00:52,630 And regarding the hosting provider 19 00:00:52,630 --> 00:00:54,545 I will use Vercel. 20 00:00:54,545 --> 00:00:58,700 Vercel is a great hosting provider for NextJS applications 21 00:00:58,700 --> 00:01:02,160 because the Vercel actually is a hosting provider 22 00:01:02,160 --> 00:01:05,670 by the same team that's developed NextJS. 23 00:01:05,670 --> 00:01:08,440 So it's really embracing NextJS 24 00:01:08,440 --> 00:01:12,990 and optimized for NextJS if you wanna put it like this. 25 00:01:12,990 --> 00:01:16,330 And deploying NextJS applications to Vercel 26 00:01:16,330 --> 00:01:19,393 is thankfully also extremely simple. 27 00:01:20,480 --> 00:01:23,900 Now what you'll need to do to start deploying 28 00:01:23,900 --> 00:01:28,300 is sign up with a Git repository provider, 29 00:01:28,300 --> 00:01:31,550 because with Vercel you will directly link 30 00:01:31,550 --> 00:01:33,700 your GitHub repository, 31 00:01:33,700 --> 00:01:36,480 which holds your source code, for example, 32 00:01:36,480 --> 00:01:40,240 to Vercel and they will then get your source code from 33 00:01:40,240 --> 00:01:42,963 that repository and deploy it for you. 34 00:01:43,820 --> 00:01:47,460 Therefore you need to use GitHub, GitLab, or Bitbucket, 35 00:01:47,460 --> 00:01:50,290 which are Git repository providers 36 00:01:50,290 --> 00:01:54,880 to put your code there before you can deploy it with Vercel. 37 00:01:54,880 --> 00:01:58,200 Now here I will use GitHub, which arguably is 38 00:01:58,200 --> 00:02:01,630 the biggest and most popular Git repository provider. 39 00:02:01,630 --> 00:02:04,573 And I already did log in with my account here. 40 00:02:05,520 --> 00:02:07,960 Once you did create an account and login, 41 00:02:07,960 --> 00:02:08,880 it's free, 42 00:02:08,880 --> 00:02:11,770 you can create a new repository 43 00:02:11,770 --> 00:02:14,520 and you can give this repository any name you want, 44 00:02:14,520 --> 00:02:18,950 like NextJS course demo or anything like this. 45 00:02:18,950 --> 00:02:20,690 You can also give it a description. 46 00:02:20,690 --> 00:02:24,060 And then chose whether it should be public or private. 47 00:02:24,060 --> 00:02:26,320 If it's public, everyone can see it. 48 00:02:26,320 --> 00:02:27,830 Everyone can see your code. 49 00:02:27,830 --> 00:02:32,320 If it's private only people you grant access to can view it. 50 00:02:32,320 --> 00:02:34,300 And I'll go with private here, 51 00:02:34,300 --> 00:02:36,620 but either of the options can be correct. 52 00:02:36,620 --> 00:02:40,130 It simply depends on which kind of project it is. 53 00:02:40,130 --> 00:02:43,323 If it's a open source project it will probably be public. 54 00:02:44,300 --> 00:02:47,543 So I'll go with private and create my repository. 55 00:02:48,490 --> 00:02:52,050 Once that is created, you need to push your code here. 56 00:02:52,050 --> 00:02:55,870 Now for that you need to install Git on your local system 57 00:02:55,870 --> 00:02:59,810 and you can git git-scm.com. 58 00:02:59,810 --> 00:03:02,220 It's available for all operating systems. 59 00:03:02,220 --> 00:03:04,230 You can download the installer from there 60 00:03:04,230 --> 00:03:07,863 and simply walk through it to install Git on your system. 61 00:03:08,850 --> 00:03:11,850 And once you installed get on your local system 62 00:03:11,850 --> 00:03:15,620 you can create a so-called commit in your project, 63 00:03:15,620 --> 00:03:17,600 a code snapshot, you could say. 64 00:03:17,600 --> 00:03:19,450 And then push that commit, 65 00:03:19,450 --> 00:03:23,130 that repository as a whole, actually, to GitHub 66 00:03:23,130 --> 00:03:27,000 to move your code with your code history to GitHub. 67 00:03:27,000 --> 00:03:30,040 Now, I won't turn this course into a Git course. 68 00:03:30,040 --> 00:03:32,400 If you wanna learn more about Git and GitHub 69 00:03:32,400 --> 00:03:35,230 we got a standalone course on that which you can take. 70 00:03:35,230 --> 00:03:37,860 Here I will assume that you have those Git basics 71 00:03:37,860 --> 00:03:40,420 and that you have Git installed now. 72 00:03:40,420 --> 00:03:42,030 And if you have it installed 73 00:03:42,030 --> 00:03:44,970 you can then go back into your local project, 74 00:03:44,970 --> 00:03:49,030 into your project folder and create a code snapshot, 75 00:03:49,030 --> 00:03:51,100 a commit as it's called. 76 00:03:51,100 --> 00:03:54,230 You do this by running git add dot 77 00:03:54,230 --> 00:03:56,920 and you can run this if you got Git installed 78 00:03:56,920 --> 00:04:00,160 and then git commit and then some message of your choice. 79 00:04:00,160 --> 00:04:03,090 For example, ready for deployment. 80 00:04:03,090 --> 00:04:06,000 Though typically you want to add commit messages 81 00:04:06,000 --> 00:04:08,233 that describe what you changed. 82 00:04:09,470 --> 00:04:13,920 But with that, I now created such a snapshot, such a commit 83 00:04:13,920 --> 00:04:15,970 and now we're ready for deployment. 84 00:04:15,970 --> 00:04:19,800 Now that means that now we need to push our code to GitHub. 85 00:04:19,800 --> 00:04:22,260 For this we can grab this URL here, 86 00:04:22,260 --> 00:04:25,370 which will point to the repository we created. 87 00:04:25,370 --> 00:04:30,370 And in our local project folder run git remote add origin 88 00:04:30,670 --> 00:04:33,123 and paste that URL in here. 89 00:04:34,250 --> 00:04:36,550 Now depending on whether you worked with Git 90 00:04:36,550 --> 00:04:38,310 and GitHub before or not, 91 00:04:38,310 --> 00:04:41,650 you might wanna add your GitHub username here 92 00:04:41,650 --> 00:04:44,310 in front of github.com. 93 00:04:44,310 --> 00:04:46,230 If you did work with GitHub before 94 00:04:46,230 --> 00:04:49,460 and push before you probably don't need to do that, 95 00:04:49,460 --> 00:04:51,840 but if you never pushed anything to GitHub 96 00:04:51,840 --> 00:04:53,290 adding this will ensure 97 00:04:53,290 --> 00:04:55,540 that you're prompted for your password 98 00:04:55,540 --> 00:04:58,830 and that you have a chance of entering your credentials, 99 00:04:58,830 --> 00:05:01,740 because of course you'll need to authenticate yourselves 100 00:05:01,740 --> 00:05:04,980 in order to successfully push to this repository. 101 00:05:04,980 --> 00:05:08,770 You can't just start pushing to some random repositories, 102 00:05:08,770 --> 00:05:10,400 which you don't own. 103 00:05:10,400 --> 00:05:14,750 So therefore here I will now add this origin here 104 00:05:14,750 --> 00:05:18,670 and then run git push -- all. 105 00:05:18,670 --> 00:05:21,410 And this will now push our code here. 106 00:05:21,410 --> 00:05:24,150 Now you might be prompted for your password here 107 00:05:24,150 --> 00:05:26,650 and you can then enter your GitHub password 108 00:05:26,650 --> 00:05:28,870 or you as a token 109 00:05:28,870 --> 00:05:30,120 for 110 00:05:30,120 --> 00:05:31,840 authentication 111 00:05:31,840 --> 00:05:33,810 For this to generate such a token 112 00:05:33,810 --> 00:05:36,730 you need to go to your GitHub settings 113 00:05:36,730 --> 00:05:40,560 and then there go to developer settings, 114 00:05:40,560 --> 00:05:42,483 personal access tokens, 115 00:05:43,430 --> 00:05:46,270 and generate a new token here. 116 00:05:46,270 --> 00:05:48,230 Once you confirm this with your password 117 00:05:48,230 --> 00:05:52,180 you can add some note here like NextJS deployment 118 00:05:52,180 --> 00:05:54,370 or a more general purpose. 119 00:05:54,370 --> 00:05:57,323 And then under scopes select repo, 120 00:05:58,300 --> 00:05:59,570 delete repo, 121 00:05:59,570 --> 00:06:01,020 and 122 00:06:01,020 --> 00:06:03,023 admin repo hook here, 123 00:06:04,410 --> 00:06:05,933 and then generate a token. 124 00:06:06,820 --> 00:06:09,280 And now you'll need to copy that token here, 125 00:06:09,280 --> 00:06:10,833 which is showing up here, 126 00:06:11,980 --> 00:06:15,670 and enter this as a password when you're prompted for it. 127 00:06:15,670 --> 00:06:18,820 Once you did all of that and you pushed successfully 128 00:06:18,820 --> 00:06:21,730 you should see your code in this repository, 129 00:06:21,730 --> 00:06:24,883 which you just created in the main branch. 130 00:06:25,770 --> 00:06:28,360 And now we can link this repository 131 00:06:28,360 --> 00:06:31,090 to Vercel to start deploying. 132 00:06:31,090 --> 00:06:32,370 Now, before we do that 133 00:06:32,370 --> 00:06:34,830 let me talk about building for production 134 00:06:34,830 --> 00:06:37,400 and what Vercel actually does. 135 00:06:37,400 --> 00:06:39,200 Vercel is a hosting provider, 136 00:06:39,200 --> 00:06:42,480 which you can not just use for NextJS. 137 00:06:42,480 --> 00:06:44,460 You can also use them for other projects, 138 00:06:44,460 --> 00:06:47,840 but which definitely is optimized for NextJS. 139 00:06:47,840 --> 00:06:50,630 So whilst you can host other things there as well 140 00:06:50,630 --> 00:06:52,000 and it might be optimized 141 00:06:52,000 --> 00:06:54,410 for those other types of projects as well. 142 00:06:54,410 --> 00:06:56,947 It is definitely optimized for NextJS. 143 00:06:57,880 --> 00:07:01,600 And that means that you can just connect Vercel 144 00:07:01,600 --> 00:07:03,870 to your GitHub repository 145 00:07:03,870 --> 00:07:07,270 and the Vercel will build and then deploy 146 00:07:07,270 --> 00:07:10,100 and start your project for you. 147 00:07:10,100 --> 00:07:13,280 So you don't need to run any built command on your own, 148 00:07:13,280 --> 00:07:15,590 Vercel we'll do that for you. 149 00:07:15,590 --> 00:07:18,800 Nonetheless, I wanna show you what Vercel does. 150 00:07:18,800 --> 00:07:21,770 And therefore I'm back in our local code here 151 00:07:21,770 --> 00:07:25,740 and there in package.json we see a couple of scripts, 152 00:07:25,740 --> 00:07:29,890 which are commands we can execute in this project. 153 00:07:29,890 --> 00:07:32,020 We worked a lot with the dev script 154 00:07:32,020 --> 00:07:34,410 to start this development server. 155 00:07:34,410 --> 00:07:35,570 And that is the script 156 00:07:35,570 --> 00:07:37,833 which we used during local development. 157 00:07:38,710 --> 00:07:41,070 But we can also run the build script 158 00:07:41,070 --> 00:07:43,720 to build our project for production. 159 00:07:43,720 --> 00:07:48,560 So to optimize all our code, minify it, and so on. 160 00:07:48,560 --> 00:07:52,720 And you wanna run this if you do deploy it on another host, 161 00:07:52,720 --> 00:07:55,470 which does not build the project for you. 162 00:07:55,470 --> 00:07:57,950 So we don't need to do it with Vercel, 163 00:07:57,950 --> 00:08:01,940 but you might need to do it forever hosting providers. 164 00:08:01,940 --> 00:08:04,200 And then once you run this command 165 00:08:04,200 --> 00:08:06,700 this will give you a .next folder, 166 00:08:06,700 --> 00:08:10,120 which contains some of these optimized files. 167 00:08:10,120 --> 00:08:12,220 For example, this thought .next folder 168 00:08:12,220 --> 00:08:16,230 will also contain all those pre-generated page files, 169 00:08:16,230 --> 00:08:19,400 those HTML files for your pages, 170 00:08:19,400 --> 00:08:21,060 like the starting page here, 171 00:08:21,060 --> 00:08:24,380 or the individual meetup detail pages. 172 00:08:24,380 --> 00:08:27,120 So this is what npm run build will do for you 173 00:08:27,120 --> 00:08:29,210 and Vercel execute this command 174 00:08:29,210 --> 00:08:32,230 on our behalf on their servers. 175 00:08:32,230 --> 00:08:34,250 So we don't need to do that. 176 00:08:34,250 --> 00:08:37,460 But if you would host your project on another server, 177 00:08:37,460 --> 00:08:39,890 which you manage yourself, for example, 178 00:08:39,890 --> 00:08:41,960 you need to run npm run build 179 00:08:41,960 --> 00:08:44,650 and there after with npm start 180 00:08:44,650 --> 00:08:47,420 you can start a production server. 181 00:08:47,420 --> 00:08:49,540 So now again, we have a running server, 182 00:08:49,540 --> 00:08:51,880 but this is now the production server, 183 00:08:51,880 --> 00:08:54,000 which you could start on a remote machine, 184 00:08:54,000 --> 00:08:55,760 which you administer yourself 185 00:08:55,760 --> 00:08:59,050 to run the server for your next application. 186 00:08:59,050 --> 00:09:01,770 And that server therefore should of course stay up 187 00:09:01,770 --> 00:09:03,440 and running on that machine 188 00:09:03,440 --> 00:09:06,860 to which you deployed your application as long as you want 189 00:09:06,860 --> 00:09:08,890 to expose it to the world. 190 00:09:08,890 --> 00:09:10,750 Though I work with it here though. 191 00:09:10,750 --> 00:09:12,770 Now all of that will be done by Vercel 192 00:09:12,770 --> 00:09:15,000 and therefore let's now go back to Vercel 193 00:09:15,000 --> 00:09:17,530 and continue with GitHub here. 194 00:09:17,530 --> 00:09:20,610 And now here we'll need to link GitHub to Vercel. 195 00:09:20,610 --> 00:09:22,130 Now you are then prompted 196 00:09:22,130 --> 00:09:24,370 to give Vercel certain permissions, 197 00:09:24,370 --> 00:09:26,580 give it access to your repositories, 198 00:09:26,580 --> 00:09:27,893 and I'll do that here. 199 00:09:29,360 --> 00:09:32,300 And once you did that, you can select that repository, 200 00:09:32,300 --> 00:09:34,750 which we created a couple of minutes ago here, 201 00:09:34,750 --> 00:09:36,670 and connect it to Vercel. 202 00:09:36,670 --> 00:09:39,410 So I'll click import here on that repository. 203 00:09:39,410 --> 00:09:41,800 Now we'll select this personal account here. 204 00:09:41,800 --> 00:09:44,940 You might be prompted to create an account here. 205 00:09:44,940 --> 00:09:47,210 And there you wanna choose the personal one, 206 00:09:47,210 --> 00:09:50,980 which is free to use or free to get started. 207 00:09:50,980 --> 00:09:53,340 Definitely check out their pricing pages 208 00:09:53,340 --> 00:09:56,190 to learn more about the different options you have there. 209 00:09:57,220 --> 00:09:59,090 And with that, we now can configure 210 00:09:59,090 --> 00:10:00,930 how our code should be pulled 211 00:10:00,930 --> 00:10:03,620 and how the project should be built. 212 00:10:03,620 --> 00:10:07,100 And all the defaults here typically should work for you. 213 00:10:07,100 --> 00:10:10,070 It detected that it's a NextJS project. 214 00:10:10,070 --> 00:10:12,880 The default build and output settings work for us 215 00:10:12,880 --> 00:10:15,510 And we could override environment variables here 216 00:10:15,510 --> 00:10:16,920 if we would be using any. 217 00:10:16,920 --> 00:10:19,993 But we aren't and hence, we can just click deploy. 218 00:10:21,170 --> 00:10:22,910 Now to ensure that it really works 219 00:10:22,910 --> 00:10:25,110 we'll also need to go to MongoDB Atlas 220 00:10:25,110 --> 00:10:27,120 and change something here. 221 00:10:27,120 --> 00:10:30,690 There under network access you will need to make sure 222 00:10:30,690 --> 00:10:32,913 that you allow access from anywhere. 223 00:10:33,910 --> 00:10:36,180 This ensures that the Vercel servers 224 00:10:36,180 --> 00:10:38,050 on which our application will run, 225 00:10:38,050 --> 00:10:41,051 will be able to connect to MongoDB. 226 00:10:41,051 --> 00:10:42,710 Otherwise this will fail 227 00:10:42,710 --> 00:10:45,730 and our data can't be loaded and stored. 228 00:10:45,730 --> 00:10:48,180 So we need to grant this access. 229 00:10:48,180 --> 00:10:50,430 We still, of course, use our credentials 230 00:10:50,430 --> 00:10:53,000 for actually establishing the connection, 231 00:10:53,000 --> 00:10:56,490 but we need to open up that global access to allow Vercel 232 00:10:56,490 --> 00:10:59,770 and its servers and our code running on their servers 233 00:10:59,770 --> 00:11:01,690 to connect to MongoDB. 234 00:11:01,690 --> 00:11:05,340 Now it can take a while until this operation is done. 235 00:11:05,340 --> 00:11:07,350 So let's wait for this. 236 00:11:07,350 --> 00:11:08,530 And once it's done, 237 00:11:08,530 --> 00:11:12,400 here, we actually see an error that connection failed 238 00:11:12,400 --> 00:11:16,450 because I just changed it after starting the deploy, 239 00:11:16,450 --> 00:11:20,080 but we can simply hit deploy again and start a new deploy, 240 00:11:20,080 --> 00:11:21,780 which should now succeed 241 00:11:21,780 --> 00:11:26,390 because now we did open up MongoDB for outside access. 242 00:11:26,390 --> 00:11:27,483 So let's now wait whether 243 00:11:27,483 --> 00:11:30,350 that now starts up successfully here. 244 00:11:30,350 --> 00:11:33,030 It definitely built our site successful here. 245 00:11:33,030 --> 00:11:34,440 That's good. 246 00:11:34,440 --> 00:11:36,810 And that is looking good. 247 00:11:36,810 --> 00:11:40,980 Now we can click visit and we see our site up 248 00:11:40,980 --> 00:11:44,370 and running on Vercel's servers here. 249 00:11:44,370 --> 00:11:46,740 We can also try adding a meetup here 250 00:11:47,600 --> 00:11:52,600 test street five, this is a test and see whether that works 251 00:11:54,617 --> 00:11:55,700 and it does. 252 00:11:55,700 --> 00:11:58,410 It might not show up immediately on this page 253 00:11:58,410 --> 00:12:01,120 because this page is statically generated 254 00:12:01,120 --> 00:12:02,980 and then only revalidated 255 00:12:02,980 --> 00:12:06,360 once every second for incoming requests 256 00:12:06,360 --> 00:12:08,870 and then it needs to be pre-generated again. 257 00:12:08,870 --> 00:12:11,980 So even after one second, it might not show up immediately, 258 00:12:11,980 --> 00:12:15,030 but eventually we see our new meetup here 259 00:12:15,030 --> 00:12:17,290 and we can't visit it here though. 260 00:12:17,290 --> 00:12:20,250 We get a 404 error here 261 00:12:20,250 --> 00:12:23,630 and that's actually an expected error at this point. 262 00:12:23,630 --> 00:12:24,993 What's the problem here? 20694

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.