Deploy a Node.js/Express.js Application to AWS in 11 minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello in this tutorial we're going to create and deploy a node.js and express.js application to aws elastic beanstalk so before we get started you need to have a few things number one you need an aws account you can get this just by going to aws.amazon.com and answering a few questions you should be able to create an account next you need to install git so this is available at get fcm.com super easy all you have to do is click this download button it automatically recognizes your operating system and for setup go to the documentation and i went to get going with git watch that four minute video and was ready to get started with git finally you need to install the ebcli so uh i'll put this link in the description you can also get this by just searching on aws eb cli install so you just have to run the single pip install command and set the environment variable one thing to note is here instead of python37 for me it was python38 it'll be whatever version of python you have or whatever the newest one is depending on if you just downloaded it okay once you have that we're ready to get started i'm gonna create a directory so i'll call it node.js project one um now i'm gonna navigate to that directory so no cd node.js project one and now i'm going to initialize the repository so that is with git init okay now i can open it up in visual studio code you can also open it up in whatever code editor you like just you won't be able to use the code doc command i think so okay that's gonna open it up for us okay now we create a new file called talk get big noir here we specify what files and folders are going to be excluded from our repository so we can include the node modules that's going to have all our packages we don't need that uh in our repository we're gonna ignore git ignore uh and we're gonna ignore dot elastic bean stock slash this is gonna be our configuration we can just ignore that okay now we're ready to get started so if we run the command eb init platform node.js and the region is going to be whatever region you entered when you created an aws account for me i'm in northern california so u.s west one you can also choose a different region than your account is um if you press enter right now it might ask you for your access key and your password what you can do is just go to your aws management console click on your account over here and then you can go to my security credentials uh go to access key and click on create new access key and that should generate for you i've already done that so i'm just going to enter this command it's going to take a few minutes or actually that was pretty quick okay so it created that and now if we go into our project we should see an elastic beanstalk folder and that has this config.yml and right now the environment's null and all that so now we're going to initialize the environment so to do that we're going to run eb create so here i'm going to say just a sample and here we name our environment i'm going to call it node.js project one usually it's the application so our application node.js project one and then env for environment that is going to take a few minutes i think to create you'll know that's done when it says successfully launched environment or if it says unsuccessfully and then you have to look a little bit at the docks for how to fix it but if you followed all the steps it should be successful okay next i'm going to create a folder for our configuration so that's going to be eb extensions and you you have to name it exactly like this dot eb extensions okay here i'm going to create a new file called and it has to be called node command config this is going to be our node command here you have to spell everything exactly right what up to what i'm doing so it's a little bit confusing this is where you'll probably make the most mistakes but it's only like three lines so it should be okay option underscore settings colon aws elastic being stock first time i did this i actually spelled it being talk and i was so confused about why it wasn't working and then i was like oh it's spelled bean talk okay bean stock container colon container colon node js colon node command npm start okay we're good for that now we can create our express or node.js application so i'm going to say npm init package name i can keep that uh entry point i'll change it to app.js um i'll just press enter for everything else that's okay and this should have generated a package.json file over here now we have the npm start command so we have to specify the start script and for start that's just going to be node dot and you could also put node dot js but since my main is app.js i can just say no dot here i'm going to install express and before i do that i'm just going to make sure my git ignore file has the node modules excluded okay i'll install express and i think it's default installed when you create a node.js project anyway but still if it is a lower version this will be the most recent version it will just upgrade it if it's already there and this created our package.log packagelock.json and our known modules folder which you can see is faded because our getignore excludes it and you notice it says untracked that's because we haven't committed it to the repository yet we'll do that after we finish creating our app.js file so app.js here i'll just create a simple express app so const express is require express i'll say app is express app.get at the base url that's going to give us a callback function so the request object the response object and we'll say we'll send as a response maybe this is my first node.js project and a smiley face emoticon now here's where it's a little bit different instead of saying app lesson 3000 or another port you have to say app.listen app.listenprocess.environment.port or 3000 and the reason for this is elastic beanstalk is going to give us a default port that it wants to use and so we'll use that and if it doesn't like if we're just testing it or running it locally then we'll just use 3000. okay now we're ready to deploy it so i'm going to say get add top okay and i'll say git commit the message is going to be first express app okay and it added all our files now we're ready to deploy it so what we do is run eb deploy and our environment name so for us that's node.js project 1 environment and if you don't remember you can go to elasticbeans.config.yml and then you can just check the environment so it's no js project one environment that's going to take a few minutes so when that's done it'll say environment update completed successfully but great now we can run eb open [Music] oh um it doesn't have a default environment so what we can use what we can do is we can specify the environment name or we can just say ebu's node.js project one [Music] environment okay now we can say eb open [Music] okay that opens and there we go we have our message this is my first node.js project now what you can actually do is if you go to aws go to elastic beanstalk environments node.js project 1 env so this is the one that we just deployed we can check the application versions here first express app that's the one we just did and so now every time you want to update it you can just do git add up and then git commit dash m and the message so i hope you enjoyed this tutorial and stay tuned for more tutorials on coding thanks bye
Info
Channel: Siddhartha Chatterjee
Views: 1,745
Rating: 4.818182 out of 5
Keywords: aws, nodejs, expressjs, deploy to aws, node, express, elastic beanstalk, deploy nodejs app to aws, deploy express app to aws
Id: 0oIcGPK8mQE
Channel Id: undefined
Length: 11min 47sec (707 seconds)
Published: Sat Oct 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.