Node.js & Express From Scratch [FINAL] - Deploying Our App
Key Takeaways
In this video, Brad Traversy teaches how to deploy a Node.js and Express application to Digital Ocean, covering the installation of a Node process manager and connecting a domain name.
Full Transcript
all right guys so uh in this video what I want to try to do is deploy the application that we've been building now I haven't done anything uh to kind of prepare for this so I'm just giving you a heads up that um we we may run into some issues and um you know have some hiccups but I think it's good to to kind of show the whole process from scratch because I mean that's how it is in the in the real world you know you're going to run into issues you're going to you're going to have to learn things as you go and I think it's better to do it this way than to have it all you know a cookie cutter template of of how it would look in a perfect world uh because it's definitely not a perfect world when you're a developer or a programmer so we're going to be using digital ocean I would definitely suggest digital ocean for pretty much any kind of um application node.js Express uh python PHP pretty much anything it's they're a really great company um and they're really cheap when you if you compare them to other uh VT uh vpss they're very cheap so uh I have an account already so I'm going to log in here uh let's see what did I do Tech Guy info and password so once you oh I have two Factor authentication enabled so I just got to check my my uh text message real quick all right so let's see C8 c834 all right and this is just a test account I don't have any production sites or anything on this you can see I don't have any droplets so if you've never worked with digital lotion they have droplets and a droplet is basically just a VPS it's a uh it's a virtual server and you have full access to it you can log in through the shell and you can run any commands you want you can install whatever you want just like we did on our local machine okay uh so what we're going to do is create a new droplet and there's a couple different Linux distributions you can choose we're going to stick with the bu to and as far as the payment goes you can add funds to your account and then you can purchase packages with those funds all right so let's say we want the lowest one which is $5 a month this is more than enough for testing and prototyping if you're running a production application you may want to add some more resources and go a little higher um so let's go down here and we want to add an SSH key because you want to be able to to uh to secure your account and I would suggest sshing into it instead of using a username and password and you can actually disable uh login functionality so that only your machine can tunnel into your SSH so let's say new SSH key now to generate it since we're in Windows it's a little more difficult what we're going to do is download a tool called putty okay so there's actually two programs we need one is putty that's used to connect through SSH and then putty gen is used to uh generate a an SSH key so let's go ahead and click you can download putty here and we want to grab let's see I'm on windows 64bit so I'm going to grab that and then I'm also going to grab where is it puty genexe 64bit okay so we're going to get both of those and then I'm just going to move those let's go ahead and cut and we'll put them in the C drive and I'm just going to create a new folder called putty okay we'll paste that in there these aren't installers these are the actual programs so let's open up putty Jen first all right and what we want to do here is Click generate and it says move the mouse around here to generate and then this is our key right here so we want to grab from the beginning all the way to the end make sure you get the whole thing and let's go ahead and copy that and then we'll paste it in here and you see we get a little green checkm Mark and then we can name it I'm just going to call this public key one all right and then let's go back to putty gen and what we want to do here is save the key so let's say save public key and I'll just save it to documents so we'll call this public uh let's say public dot key and then we also want to save the private key all right now you can put a pass phrase if you want um but I'm just going to leave it blank and I'll click yes and then let's say uh private key one and then this is going to have a PPK extension so let's see save that and we should be all set with this program so let's close that up let's continue on with this and then we'll open up putty and we'll connect so for a host name you can pick whatever you want I'm just going to leave the default and then let's just click create and now it's going to go ahead and set up our server our droplet and now it's all set so you can see we have an IP address and if we click on that we can go to basically our dashboard for the droplet and we can have we have graphs which aren't available just yet but they will um access we can actually launch a console here if we wanted to but we're not going to do that we're going to use our machines console uh let's see Power you can power it down you can upgrade if you want if you want to pay more and get more uh resources backups snapshots if you want to destroy it you can just go ahead and click on Destroy destroy and that'll wipe it clean so what we want to do now is connect so we're going to open up putty exe and if you're on Mac or Linux you can just use the SSH command uh and there's ways to use it on Windows too but uh we're just going to use putty so let's grab the IP address here let's copy that actually and paste that in now we need to use our our key that we generated so we're going to go down to data and let's see we're going to use for auto login username we'll say root and then go down to SSH and off and then what we want to do is upload the private key that we created so let's click browse and we want private key one and then let's go back up to session and we're going to save this so right here let's just say I'll just say do1 for digital ocean 1 and save and now when we come here we can easily load it up all right so let's click on open and it's going to give us this um this uh box the first time we connect we're just going to say yes and now we're in you see we didn't even have to put in a password because we used the SSH key so now we can use this just like we would on our local machine and we can install stuff and um you know set everything up so it's going to be a little different because I was using Windows on my client machine so uh you know installing mongodb and stuff is a little different let me just make this bigger uh let's see what can I make this bigger change settings appearance uh let's see change the font and let's choose 24 that should be good there we go oh that's yeah that's fine at least I don't have to worry about you guys not seeing it so let's see first thing we're going to do here is install node.js so installing node.js on auntu is pretty easy if we go down to uh let's see is this it yeah right here so we want to run this curl command because by default a uh it's not in the repository so let's grab this and we'll just paste that in here and we'll run that that'll make it so that we can then run apt get install nodejs so we'll copy that actually we should probably do a pseudo app get update first all right and then we're just going to paste this in to install node and now if we say node DV you can see node is now installed as well as npm so next thing we're going to do is install mongodb so let's say mongod DB install a bun to okay so uh let's see first thing we're going to do is import public Key by using the pack package management system so we want to grab this right here I'll just click copy and let's paste that in and run it all right and then we need to create a list file for mongod DB so we're going to do um we're on a bunto 16 so let's grab this right here and and then uh we already let's do yeah let's just run an update again so pseudo apt get update and then we're just going to run this we can now install it with apt get all right and then to start it we can run this command start the service paste that in and now should be running if you wanted to stop it you could just go down you can run this right uh right here okay pseudo service mongod D stop and you can also restart so now that that's installed let's go ahead and clone the repository so let's go to GitHub and let's see um I'm not going to sign in I don't need to uh let's just search for me uh oh wait this is searching repositories let's search users and look someone actually created an account with my name so let's go here and it should be right here node KB all right so we just want to basically clone this project so up here it says clone let's grab this okay now git should be installed uh get okay so let's go ahead and run get clone and then we're just going to paste that in all right so if we look at our directory structure now we're in the home uh home directory we have node KB all right are we in the home directory yeah we should should be so what we'll do now is CD into node KB not JB and then from here let's run uh actually let's install nodon as well might as well so npm install DG nodemon Okay so now let's try to run it uh you know what we have to run we have to run npm install to actually create um install all the dependencies so let's do that so this will look at the package.json file and install everything in it so that includes Mongoose it includes pug uh what else do we use express messages all that stuff all right so now that that's done let's try and run nodemon and it's started so let's grab our IP address go over here paste that in we want to go to Port 3000 and there it is there's our application so if we want to test things out let's register let's say Brad at gmail username submit okay we're registered let's try logging in and there we go let's add an article submit article added so our our application is now live on the internet now we want to do a couple things so one we don't want to have to have this running in order to go to our website so what we can do is we can start it as a service so there's a few different uh ways that we can do that one is by using something called pm2 so this is the process manager for node.js and we're going to use this and we should just be able to do pm2 start and then whatever our entry file is and it'll run it in the background all right so let's go ahead and do a controll c and stop this and then we're going to do npm install pm2 DG we want to install it globally all right once we do that we should be able to start it up okay so let's do pm2 start app .js okay so now it should be running in the background so it should still work if we go over to here and refresh and it's still running good so another thing we you'd probably want is to not run it on a port like this 3000 Now the default port for HTTP is Port 80 but by default if we were to change the port number to 80 it's not going to work but we can actually install uh a package called libcap 2-bin and that'll allow us to run it on Port 80 let me just search for that lib cap 2-bin and uh let's see I guess there's not implements the user space interfaces all right so it's not really not really a good description of it but we're going to install that first we're going to stop our application and we can do that with pm2 stop app.js and then let's go ahead and say pseudo uh pseudo appt get install and it's lib 2-bin all right so now that we have that installed we have to run a command let me see if I can find that uh there's a few ways to do this to uh to to get it to run without having to go to a certain Port where the heck is the package all right you know what I'm just going to copy it and paste it in and you guys can can copy it all right so it's pseudo set cap and then you have this cap net buy service equals plus EP and then readlink DF and by the way these are back ticks not quotes okay make sure you put those in and then which node so let's run that and then let's start the actually we need to edit the application because we set Port 3000 we just want to go in and we want to change it to uh Port 80 so just for Simplicity I'm going to use Nano which is a uh ter based text editor and we're going to edit app.js all right so let's just change go down to the bottom and right here where we put 3,000 we're going to change that to 80 and we'll say server started on Port 80 okay then we're going to do contr X yes to save or Y and then enter so now let's go ahead and start the application again so we'll say pm2 start app.js and now let's go to just the IP address not the port and there we go all right so last thing that you'd probably want to do is you want to use a domain name not an IP address and if we go to digital ocean and we go to to uh let's see networking and we want to add a domain now I actually have a domain pointed to digital ocean already let me just show you how to do that I use I'm using enom Central but you can do this from whoever uh hosts your domain name or the registar uh let's see I'm going to just log in here I think this is my account not sure no maybe it's tech i1 there we go all right so let's see registered domains I have I think it's Cod learner yeah right here Cod learner. net so you basically want to go to your domain registra and you want to edit the DNS records or the name servers so in this case with enom I would choose this DNS server settings and then you want to add three name servers ns1 digital ocean.com ns2 and ns3 and save it and it might take a little while for the domain to propagate but once it does you can come over here and you can say add domain and say Cod learner. net or obviously your own domain name and we're going to add a couple records here so we want a uh a record so right here in host name we're going to just say at and over here we're going to choose our droplet I only have one but if you have multiple they'll they'll all show up so we're going to do that say create record and then we also need to add a c name and in here let's say www because we want both versions of the domain just uh Cod learner. net and and www. cod. we want those to point to the host so at is just representative of of our post of our uh IP address so let's go ahead and click create record and we should be all set so now let's go to Cod learner. net and there's our application okay we should be able to log in there we go so we now have a live node.js and express application now there's other um Provisions that you should set up if this was a production server you want you want to add better security you shouldn't be even logging in as the root user so create a new user um and you might have to add the SSH key for that user as well um I actually have a video that goes a little more in depth on this process uh I forget exactly what it's called it's like deploy node to digital Ocean or something like that all right so hopefully you guys enjoyed this um I might add some more functionality to this I'm not sure I know that a couple people asked for file uploading so that's something I might look into but I did want to just get a deployment video out for now before I start to move on to other stuff and like I said in the first video uh laravel is coming I know a lot of you guys are asking for that so that will be out soon and that's it thanks for watching also guys uh if you can if you have a Twitter account go ahead and follow me uh twitter.com trvy media I'm trying to uh to get I I mean I've kind of neglected the account but I'm trying to get more followers because I want to be able to post you know updates about what's coming up and and all that so if you guys can just you know subscribe on Twitter um and you know that would be that would be helpful so thanks for watching guys I I will see you in the next video
Original Description
In this final video [FOR NOW], we will deploy our Node.js and Express application to Digital Ocean. We will install a Node process manager and even connect a domain name
2 FREE MONTHS OF DIGITAL OCEAN:
https://m.do.co/c/5424d440c63a
CODE: Full code for this series
https://github.com/bradtraversy/nodekb
COURSE: Full course this project is based on
http://www.traversymedia.com/course/p...
SUPPORT: We spend massive amounts of time creating these free videos, please donate to show your support:
http://www.paypal.me/traversymedia
http://www.patreon.com/traversymedia
FOLLOW TRAVERSY MEDIA:
http://www.facebook.com/traversymedia
http://www.twitter.com/traversymedia
http://www.linkedin.com/bradtraversy
Playlist
Uploads from Traversy Media · Traversy Media · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Changing Your DNS/Nameservers
Traversy Media
Create a MySQL database in cPanel
Traversy Media
Install & Uninstall Joomla Extensions
Traversy Media
Adding and linking an article in Joomla
Traversy Media
Create a Joomla Blog
Traversy Media
Import & Export A MySQL Database
Traversy Media
Use A Custom Font On Your Website Using CSS
Traversy Media
Connect Joomla Site With Dreamweaver
Traversy Media
Remove Phoca Gallery 3.2.3 Footer Text
Traversy Media
Drupal 7 Security Update 7.19 to 7.20
Traversy Media
Add An Addon Domain In Cpanel
Traversy Media
Pull A Heroku Rails App and Database
Traversy Media
Create a Custom Joomla 2.5 Module - Part 1
Traversy Media
Create a Custom Joomla 2.5 Module - Part 2
Traversy Media
Create a Custom Joomla 2.5 Module - Part 3
Traversy Media
Joomla SEO Tutorial - sh404sef Configuration
Traversy Media
Font Dragr
Traversy Media
Convert an HTML Template to Joomla 2.5/3.0 - Part One
Traversy Media
Convert an HTML Template to Joomla 2.5/3.0 - Part Two
Traversy Media
Rockettheme Rocketlauncher Joomla Site in Under 10 Minutes
Traversy Media
JQuery FAQ Slider Tutorial
Traversy Media
301 Redirect With htaccess File
Traversy Media
Convert HTML to Wordpress Theme - Part 1
Traversy Media
Convert HTML to Wordpress Theme - Part 2
Traversy Media
Easy JQuery Widgets
Traversy Media
Codeigniter App Part 1 - Creating the Database
Traversy Media
Codeigniter App Part 2 - Installation and Configuration
Traversy Media
Codeigniter App Part 6 - Login/Register System
Traversy Media
Codeigniter App Part 7 - Models List CRUD
Traversy Media
Codeigniter App Part 8 - Models Task CRUD
Traversy Media
Node.js Part 1 - Install NodeJS on Windows
Traversy Media
Node.js Part 3 - Building a Static Page Server
Traversy Media
Node.js Part 4 - NPM
Traversy Media
Node.js Part 2 - Install MongoDB in Windows
Traversy Media
Create a Joomla Quickstart with Custom Sample Data
Traversy Media
Install MongoDB in Ubuntu
Traversy Media
HTML5 Web Storage
Traversy Media
Create a Joomla Bootstrap Template From Scratch
Traversy Media
Ubuntu Server 14.04 Setup Part 1 - Installation
Traversy Media
Ubuntu Server 14.04 Setup Part 3 - Set Static IP
Traversy Media
Create A Wordpress Widget - Part 1
Traversy Media
Create A Wordpress Widget - Part 2
Traversy Media
Create A Wordpress Widget - Part 3
Traversy Media
Create A Wordpress Widget - Part 4
Traversy Media
Get Started With Sass on Windows
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 1
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 6
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 4
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 5
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 3
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 2
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 7
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 10
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 8
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 11
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 9
Traversy Media
Build An Audio Player Using HTML5 & jQuery - Part 1
Traversy Media
Build An Audio Player Using HTML5 & jQuery - Part 2
Traversy Media
Youtube Data API v3 & jQuery To List Channel Videos
Traversy Media
Using Bootstrap With Ruby on Rails
Traversy Media
More on: Systems Design Basics
View skill →Related Reads
📰
📰
📰
📰
Phone Verification Login SMS OTP: Backend Resend Countdown Example for US and EU
Dev.to · ottoneumann8425
I Built a 10 MB GPU-Accelerated Terminal in Rust + Metal
Dev.to · Alex
Golang vs. Java: Picking Your Backend Champion in 2026
Medium · JavaScript
The Real Production Question: What Is Your Concurrency Model with FastAPI?
Medium · Python
🎓
Tutor Explanation
DeepCamp AI