Host and Deploy a Node / Express app on AWS Lightsail (VPS) with a Custom Domain and SSL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
creating a simple api and hosting it on amazon light sale with a custom domain and ssl certification https all that jazz so let me show you what we're going to be making first here i have a simple express app on port 3000 once you go to it'll say welcome to my server this is the home page on port whatever and if you do slash whatever usually somebody's name will say hello name so we're going to run it and if we go to localhost 3000 and refresh this is what will show up and if we do slash jose we'll say hello jose so let's create a light cell instance this is just vps like uh digitalocean and all the other ones click on linux click on node you can enable automatic snapshots and you can uh create a ssh key i'm just going to connect using the web portal here through amazon and just choose the cheapest instance i don't recommend you know going crazy for your first one i'm going to name this x test api because that's really what it is create instance and this is going to take a few minutes be patient if you try to connect um using this button here that will pop up soon let me refresh it's going to be a little like command terminal icon here if you try to connect right away it will give you an error saying you won't be able to so i'll just come back when this is done there's a little icon if you click on it you'll get this an error occurred so just wait in the meantime though uh what you can do is go to networking create a static ip select your instance that you just created and you could just leave that as default click create this will give us a static ip that won't change that much in the future and just copy this and we can load up our instance once it's up at this ip to get a custom domain on your web server we're going to go to the instance and we're going to go to networking and we're going to go to guess not networking here and create dns zone and we're going to type in the name of the domain mine is open source me dot app i went to google domains and i just bought it on 12 dollars for a whole year type in open source me dot app here create dns zone we're going to add a record you're going to put an a record put at and then remember that ip from earlier it should automatically pop up here but it's a static ip add it here add another a record type in www and same ip click ok now in your domain hosting you're going to have to add the name servers that amazon provides you so we're going to copy the first one go to the domain click dns and then over here use custom name servers i'm going to add the first one the arrow and the second one save and if you haven't done so already you should publish this to your github repository doesn't have to be public but just make sure it's on github and i have it here if you guys want this code it'll be in the description as well so click on code and we're going to copy that link here so by now your light cell instance should be up and click the little terminal icon and it should connect you should see this if you type ls you can see the directories and we're going to go to htdocs so type in cd docs and just delete everything in there dash rf star and type in git clone and paste the link from the git repository and just sign into github i think this only asks you for the credentials if the repository is private that's going to take a minute to download oh that's pretty quick so if you type in ls we should see a folder called express testing and we're gonna go into it and then ls you'll see that there's no node modules folder that's because i have a git ignore to not add that to the get repository so we have to download that as well so we do vpn install and now if we do node index.js our app is running on localhost 3000 but it's not going to be localhost it's going to be our ip so let's test that out before we go any further and type in 3000 ah so it won't load because we don't uh have access to go there so go to our instance and go to networking and then add a rule for custom tcp type in 3000 give it about 10 seconds and it will load uh you can delete this later we still have to set up the port there it is welcome to my server this is the home page on port 3000 and if we do slash jose we'll say hello jose again backwards so now we got to add the uh custom domain so this link is going to be in the description we have to route all traffic on port 80 and port 443 to our port 3000 because that's where our express app is running so to do that uh you can click the link in the description but just copy this here and go to your light sale instance clear no let me close it just in case i have two terminals open yes i do i'm gonna end this and then vi to open it in paste then don't type a bunch of random letters press i and then copy this and just go back paste and then scroll up and you see this little directory here we're going to replace it with our app directory so i have it written down here it's in uh home slash bitnami htdocs express testing and replace this one as well and the port should already be 3000 so now press escape semicolon and then x and then exclamation mark to force save and then there should be another one as well so here's the directory and i'm going to do this again vi paste press i to insert copy this paste and then again replace this directory with your app directory again to escape press escape semicolon x exclamation mark to force okay and copy this line here to restart the apache server oops and we started apache so now if we type in node index.js it should show up at our local ip without having to put in port 3000 ta-da welcome to my server this is the home page on port 3000 and if we do slash whatever it'll say hello whatever so now google says our site's not secure so let's fix that really quick copy this command here and just open the terminal again i'm going to end the node server so control c i think it's also ctrl c on windows paste the command it's going to tell you to run it again so just give it a second press yes and then type it again now here you would put the domain that you purchased on google domains or godaddy or whatever so i have open source me dot app and then you're gonna put a space and you're gonna put www dot your domain again enter and yes yes no and then yes and it's going to ask you for an email address i'm just gonna put mine there and yes you agree there press enter to continue and now bitnami comes with something called forever and that's just going to run your app even if you exit the ssh terminal so type in forever start index.js okay so now if we close whoa what happened is it running am i going crazy um there we go so if you go to the domain now you should be all set and let me close the terminal should still be up and if you want to do another test you can open up postman and i'm going to type in slash can i zoom in on this no oh yes i can slash youtube tutorial you should say hello youtube tutorial we're gonna do a get request hello youtube tutorial so there you go and your site is secure encrypted and yeah leave a like if this helps because i had some trouble finding all the steps in one go any questions leave them down below
Info
Channel: Jose Valerio
Views: 7,553
Rating: undefined out of 5
Keywords: node, express, aws, lightsail, aws lightsail, custom domain, ssl, https, http, vps, host app on aws, api, server, how to deploy, how to host, ec2, SSL, SSL certificate, how to add
Id: rtshCulV2hk
Channel Id: undefined
Length: 11min 36sec (696 seconds)
Published: Tue Nov 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.