Deploy a Node.js app to Ubuntu Server

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey I'm Alexa it came to my attention that Heroku is doing away with their free plans which is really sad because I use Heroku to host my personal website following this announcement I've decided to migrate to vulture and actually invest in a real virtual private server in this video I'll show you how to deploy a node.js app to Ubuntu server on vulture using nginx certbot and pm2 also credit to Haley codes for this blog post that walks you through the command step by step you should definitely use her link to sign up for vulture which I'll leave in the description first go to the vulture website and create an account it's going to ask you to put in your billing information and such but I'm just going to log in you're gonna go to your dashboard in the products section you can click this plus signs and it says deploy new servers so do that you're going to select Cloud compute uh regular performance and choose the location closest to you also you want to select Ubuntu 22.04 so you can use the same installation commands as me and if newer versions or distributions are available you can choose those just know some commands may be different and you may have to research you can choose the cheapest server size and you can disable backups and disable enable IPv6 and you're going to enter a hostname for your server I'm just going to call my personal website and you're going to deploy that so now it's going to be installing all of our stuff on the server and it'll take a few minutes so I'm Gonna Leave it to do its thing all right it looks like our server is now running so let's click on it and we're going to copy this IP address we're gonna go and open Terminal or terminal if you're on Mac or download a command line that supports SSH like putty on Windows and you're going to enter the command SSH root at and then paste that IP address from the server instance and you're going to press enter and it's going to say connection refuse because my server is apparently still installing things so if you run into this problem just wait a few minutes and uh that should work all right it looks like it's working now and um we want to continue connecting so say yes and then you're going to want to copy and paste the password from your vulture dashboard or whatever virtual hosting platform you're using so copy that password and just paste it into your terminal and press enter and now you should be inside of your server now that we are connected to our server via SSH we can start installing the tools we need to host our node app so we're gonna run sudo apt-get update I'm just going to update all of the package information on our server and then we're gonna run sudo apt get install nginx engine X is going to intercept requests made made to the server then talk to our node.js app about what response to send back I'm gonna just say yes and we're going to change some of the default oh also if you see this pop-up just press enter and then press Tab and then enter sometimes it comes up when we run commands but um next we'll change some of the default firewall configurations on Ubuntu servers so that nginx can work properly and we can SSH back into the server so let's say sudo u f w allow engine x h e p and we'll say sudo u f w allow open SSH and sudo u w enable then let's run system STL status nginx and this command should give us somewhere something that says active running so we have that here and that's how we know it worked and we're just going to run the command sudo system STL restart nginx all right so that's gonna make sure all of our nginx rules saved now what we want to do is install serpot and this will set up the SSL certificate to our site so we can get nice https sites with that have that secure lock on Google and that's good so say pseudo apt install certbot python three dash certbot dash engine X so yes and then what we're gonna have to do is open the again just press Tab and enter we're gonna open a file in engine X config file in slash ETC engine X sites available and then default so this is just a file and you can scroll down to the server name attribute here and we're going to replace this with the underscore with your domain name.com so Alexa oops I'm in all caps Alexa fazio.dev and then www dot Alexa fazio.com all right oh and um sorry to exit that file you just press Ctrl X to exit and then it'll prompt you if you want to save and you'll say yes and then press you'll say Y and then press enter then what we want to do is verify that the file is just all right and we can say in sudo nginx Dash t and it's saying the syntax is okay test is successful and we'll say pseudo system STL reload Gen X all right now let's modify some rules oops I spelled that wrong and one more apparently that was invalid syntax uh I accidentally put u f w twice yeah all right okay now you can go into your domain registrar and go to the name server section I'm using Google domain so I'm going to click my domain name and go to DNS and then you can go to default name servers and you're just going to add two records so you'll click manage custom records and then you'll type the hostname so for this you'll leave it blank but sometimes you have to put an at symbol and this is the a name record so you'll select a leave TTL whatever it is and you can put in the IP address of your vulture server instance which is what we copied for that SSH command and you also want to put a cname record just so you get that www.sub domain so say ww and then cname and then you're gonna put your domain name with a DOT at the end and you can save that and then what you want to do is go back to terminal and we are going to run the command sudo certbot Dash Dash nginx and then Dash B and then your domain name so Alexa fazio.dev Dash D and then the domain name with the www dot at the front press enter and um you can enter your email if you want all the other stuff I would say yes and then yes so now it's going to take some time to request a SSL certificate for you and it's going to say no for me because I actually already have an SSL for this website but um yeah if it doesn't work for you then just re-run the command and it should work just fine but you're gonna go and now install node so you can type CD to just make sure you're in the root directory and then you're going to run this command all these commands will be in the blog post in the description it's this command is curl and then we're just getting the node source so we'll do that and then we'll say sudo bash node Source underscore setup.sh all right then we'll run sudo app dash get install node.js say yes press enter press tab enter and we'll do sudo apt get install build Dash essential okay so now what you want to do is clone your GitHub repository with all your code so I have this GitHub repository with my portfolio so I'm gonna go and click the code button and clone by https copy that and let's go back to terminal we'll say get clone and then just paste that URL whatever it is press enter and now we'll CD into that folder and now what you want to do is make sure you install all the dependencies for your app so if you're using npm that would be npm install or if you're using like yarn or something um oops I guess we don't have npm installed so we'll just say apt install npm yes and that should install apparently npm is not installed with this specific node .js we installed but it usually does come with it I don't know why it didn't for some reason but it shouldn't be too much trouble to install it press enter and then tab enter okay and then we'll do npm install hopefully this works and it looks like it's installing all of our dependencies for a project which is good all right now let's do npm start just to make sure our app is actually running and boom our app's up also one thing to note is if you have a DOT EnV file you're gonna have to create that dot EnV file inside of this server and you can do that by just doing nano.env and then putting all your environment variables into that file but um I'm not going to do that right now oops it looks like we got an error because it we don't have that.env file set up it doesn't know where to put our mongodb stuff anyway we're going to install pm2 which is used to keep our app running so it doesn't crash when we have errors like this so we'll say sudo npm install Dash gpm2 that's going to make it a global installation all right now let's run pm2 start and then the name of your app.js file or whatever file you use in your server that sort of starts the server it's usually app.js or server.js or index.js so mine is app.js and um looks like it started and then we'll do pm2 startup system d all right and the Alaska command should give you an output that you can copy and run something like path all right so knowledge changed something in the nginx config file again so we'll say sudo Nano slash DTC slash 2x slash sites available and then default we're going to scroll down to the location and here we're going to change some things so you can delete this line that says try files and we're gonna go and say proxy underscore ass and then http and then after that we're going to add a few other things I'm just going to copy them in so you don't have to watch me painfully type this stuff but all of this again will be in the description indent this all right and the localhost 3000 that will depend which Port you're serving on for your website in your code usually you serve on for 3000 though now let's do Ctrl X and then press y to save and then press enter and then you're going to do sudo engine x dash T and it's gonna say it looks okay or it's gonna say it's not and then you'll have to go back and check then we'll do pseudo system STL restart nginx all right so our app should be working right now um you can go ahead to your domain and check if it's working and in order to make changes to your app let's say you have new features on your app you're going to want to upload those features to GitHub push them to get and then from the server you want to use the command git pull and it'll pull down all those server changes and then you're gonna want to type the command pm to restart and then the name of your app so that would be app.js I'm pretty sure and that'll restart your app with those new changes that is how you run a node.js app on vulture using a new Ubuntu Server hopefully you enjoyed this video If You did leave a like and if you want more content subscribe I'll see you guys in the next video
Info
Channel: Robotic Nation
Views: 6,865
Rating: undefined out of 5
Keywords:
Id: SPeQJ-fINoU
Channel Id: undefined
Length: 17min 4sec (1024 seconds)
Published: Mon Oct 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.