Deploy NodeJS Application within 5 minutes
Tags: node, devops, beginners, webdev
Published: 2021-11-04 14:13:17

Now a days a lots of people are working on a side projects or the PoC(proof of concept) to showcase their work with rest of the world. For showing your work to rest of the world it required a deployment cost and also the person should have a knowledge regarding the deploying their apps to some server. Looking a bit weird 😟, right? Here I have come up with the quick solution for you guys. How we can deploy our NodeJs application within 5 minutes using App Engine. 

Google App Engine is a cloud computing platform as a service for developing and hosting web applications in Google-managed data centers. App Engine offers automatic scaling for web applications—as the number of requests increases for an application, App Engine automatically allocates more resources for the web application to handle the additional demand.

Google App Engine primarily supports Go, PHP, Java, Python, Node.js, .NET, and Ruby applications, although it can also support other languages via "custom runtimes". Here we are going to use the Standard environment provide some free quota which can be enough for showing our work to the world.🤙

## Step 1 ##
> First step is to create your own NodeJS project that you wanted to deploy using App Engine

Here is link of the sample boiler plate code for the NodeJS application. [Link](https://github.com/freeCodeCamp/boilerplate-npm/)

You can clone (hint: git clone <repo URL>) this repo in your local and our step 1 is done 👏.

## Step 2 ##
> We need to create a GCP project to deploy our Node application. 

1. Go to https://console.cloud.google.com/cloud-resource-manager
2. Click on the create new project
3. Provide Project name and location
4. Click on the Create button. 

*Note: Make sure you have enabled the Cloud Build API and Enabled the Billing for your GCP project*

You probably see that new project will be created. Congratulations 👏 you have passed the 2nd stage 💪. To be honest you nailed it.😄.

## Step 3 ##
> Download Cloud SDK installer & setup our GCP project in local

Follow the steps mention in the official document of the Google. 
[Link](https://cloud.google.com/sdk/docs/quickstart)

Once you have downloaded the Cloud SDK then go to the location of your repository.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibtmt5u0uvdggmkr930l.png)

> 1: Run the command: gcloud init
You probably see the below screen. (You may have some less options which I have in the below screenshot)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnctgd3h8b59mmq4ucmj.png)
 
> 2: Select Create a new configuration option. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2c25qsojj5w2m5i3e79.png)
 
> 3: Copy Project ID from GCP Console.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7t98mgojpo0jjtp795u.jpg)
 
> 4: Provide that project ID in Command prompt. 
Probably you'll see the below screen. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/daqiwdelod4s3euxbgcr.png)

> 5: Login with your Google Account 

After that, Select Login with the new account option. So You'll be redirect to the new browser window for login. Login using the same account in which you have created your GCP project. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vh7bywifkj4ng4ux7uc5.png)

> 6: Select the project ID

Select the option for your project id. You'll see the success message in the CMD.

Congratulations guys, You just completed almost 80% 👍

## Step 4 ##
> Create app.yaml file

Create new file at the root level of the project structure.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vjcguwki4k6iniyhfp7v.png)
 
Add below code snippet in your app.yaml file
```
runtime: nodejs16
```
for more info regarding the app.yaml file, please have a look [here](https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml) 

## Step 5 ##
> Run Deploy Application Command

Run Below command to deploy your application in APP Engine
> gcloud app deploy
> Select the region of your APP Engine deployment

You'll see the App Deployment is in progress, Once it's done you'll get the public URL of your application which you can use it anywhere you want.

You'll see the below screen once deployment is done. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlheojl3lo1hl738emqt.png)

Open the URL mentioned in the response(For me: https://dhruv-rajkotia.uc.r.appspot.com/) 

Note: Here you can also use the `gcloud app browse` command which open URL in the new browser window.

That's it, You have come too far to learn the deployment with App Engine. Hope 🤞 you liked it. 

Please [Follow](https://twitter.com/dhruv_rajkotia) me on Twitter to get update regarding upcoming blogs. Glad to connect with you guys😊.