Deploy Node.js App On The Cloud (Google App Engine)

Posted on

Hello everyone..! Today we are going to learn about how you can deploy your applications to the cloud?  so you would get hands-on experience in this particular lab session, so the way you run this program is node and then the server or GS.

Now we have run our development server on this particular machine okay so, if you can reload this then you can see that application is running on this particular development machine.

So this is the application or the portfolio website which we are going to deploy on the cloud. Now you must be one thing what kind of cloud we are going to use to deploy this application.

We are going to use Google App Engine. Now it’s a service or a cloud application infrastructure provided by Google and I have used this service in the past.

And I think that it is a nice cloud which we can use to demonstrate to deploy our node.js based application. So, first of all, we have to create a new application in Google’s console.

So for that, we are going to press this button in case you are wondering the URL to this particular page and it is this. Now we are going to the console.

And then in the console, we are going to create a new application, hit create button. Alright, so we have configured our node.js cloud demo application and it is taking some time.

Once the application is ready on Google’s infrastructure, we can switch to that application. Let’s wait for that I think the application is ready and now we can switch to this particular application to deploy the application to this particular new F.

We have created on App Engine, we have to install the G cloud. G Cloud is a Google Cloud SDK provided by Google, which you can use to deploy your applications to App Engine.

The command which we can use to install Google flower copy this paste it and it will take some time it is going to us for some configuration settings just press Enter to leave the default setting as they are okay.

Now we have to run source – our C via the Google cloud has done the modification so your shell can actually find that g-cloud command. So, run this command and type which G cloud.

Now you can see the location of the installation of this g-cloud command. You can run this g-cloud command, ok the command is working fine now.

Since our application is a low GS based application, we have to look into the documentation of how we can host a node.js based application on App Engine.

To do that you have to check out this particular document provided by Google itself. So to do that we first have to create a new file with the name ‘f dot yml or ml’.

So we are going to do that in our project folder create a new file app dot ml ok and in that particular file we have to write these two commands or settings whatever you call them a runtime node.js and environment flex.

Now you don’t have to worry too much about these two particular settings, because these are the settings which actually tells Google Cloud like which kind of application you are trying to .

Now since this is a pass and way as we have discussed earlier that in the past. You don’t have to care about how the infrastructure is supposed to work.

It is up to the cloud provider so the cloud provider has provided us with these two settings in order to run the node.js based application. So save this file before defying the application.

Make sure you have this particular start command in your packaged or JSON, so this should be your package store JSON and this particular command should be there.

Because our node.js setup actually requires you to have this start command in your package dot JSON as I specified by this particular doc. Okay, maybe you want to read that as well.

Okay otherwise if the command is not there the App Engine will try to find this particular command which actually specified what command actually should run in order to run your application.

And when it does not find it, it is going to give you this particular error to avoid that make sure the start command is there in our case the file name is server dot yes.

So the command will be known space server door GS earlier, we were using this command directly to run our server now we have put that command into this script section of our package towards JSON.

And to run this command right NPM start, so this will run this particular command which you are running directly ok and your server is still up then we are going to run this particular G cloud F deploy command.

First of all, we have to do the sign in now it is going to ask for the authentication which I am going to give it just press on this allow button and just close this particular window.

Now run this g-cloud app deploy command again it is again complaining about something required is not correctly set to do, that we can do something like g-cloud in it press fun to reinitialize everything.

And this will set up the G cloud properly here is our application. Okay so press five now this will ensure that our G cloud F deploy command is actually pointing to the right project.

I did not do this step prior to running g-cloud app deploy commands so as to show you that these kinds of a step like the authentication step and this particular setup step is necessary before running those G cloud F deploy command in the documentation.

It was skipped but it is necessary in order to deploy your application to the cloud now I think we are ready let me clear this console. And now I think we are good to go g-cloud app deploy.

Alright and I think this time it will work. Now we have to choose the reason where our application will be deployed. So this will result in a lower latency setting or a higher resistance.

Your setting based on which seasons you actually select and from which user, actually you are accessing the application. So I am going to just opt for Asia South.

Now the application is being deployed to the cloud to this particular node.js cloud demo app. So our application is deployed now let’s try to visit our application using this browse command it is provided right here.

This will launch the browser and we are taken directly to our deployed application it says bad gateway. So let me just try to see like what actually went wrong and you can also see like how can you actually debug these sort of issues then cloud the shows are concerned bad gateway.

Let me see okay, the server should listen on 8080 port and our server is listening on 3000 port and I think I have ignored this line right here let me just try to fix that and redeploy the applications.

So it will take you several hits and tries before you can actually like, learn how to deploy your applications to the cloud properly and it is not a big issue when you are learning something.

It will actually go haywire from time to time and that is how you actually learn and that is how you actually become an expert in your field when you have seen all or most of the error which can come or which you can encounter, while deploying something that is how you actually become perfect in your art.

So let’s redeploy and it is again going to take some time so our application is ready. Let’s browse it again okay so now everything was, every setting is correct and our application is hosted on this particular URL.

Okay so that is how you deploy a node.js based application on Google App Engine and I think with this hands-on session you have learned about how pass clouds actually work.

How  you can deploy your application to a cloud-like App Engine and what are the sort of settings you have to do before creating or deploying a cloud-based application.

 

Leave a Reply

Your email address will not be published. Required fields are marked *