Deploy Nest.js App on Google App Engine

Wajiha Abid
4 min readMay 27, 2021

Before rolling into the deployment process lets have some basic about the service for better understanding .

What is Google App Engine?

Google App Engine (GAE) is a serverless cloud computing platform as a service for hosting web applications . It is fully managed , no need to take care how things will happened just deploy your app and enjoy your services. Its a single application resource which carry multiple services . Each service can hold different configurations , operations etc . Each service have its own versions , so its upon you on which version you want to migrate the traffic.

Difference Between GAE & Compute Engine

Lots of time people got confused between these two terms as both manage deployments but manner is quite different and has its own pros and cons so lets have a small intro of each .

GCE:

Google Compute Engine is a IaaS (Infrastructure as a Service). In GCE you have to create and configure your own virtual machines and deploy your servers on those VMs . You have to manage your instances and VMs by yourself .

Pros: Its cheaper than GAE . Cons: One instance will always be active even if the traffic is off for week/month/years ,this will be like paying a price without any gain.

GAE:

Google App Engine is a PaaS (Platform as a Service). It is fully managed , you just have to deploy your application rest will be handle by GAE . It is fully automated , your application will scale out as the traffic increases .

Pros: It can sense the inactivity and scale down the instances to zero if there is no traffic for 15 minutes .Cons: Its quite expensive for applications with heavy traffic .

For more about cloud computing services check out this link.

Now lets start the deployment!

STEP 1:

First of all make a project or use an exsiting project and navigate to compute engine list in the side nav . Navigate to dashboard.

STEP 2:

As you navigate to dashboard following page will appear with the GET STARTED button . Bang on the button and start the process .

STEP 3:

Now configure the resources . Select the language you have used as we are dealing with Nest.js(Node.js framework) so we will go with Node.js . And set the environment as Standard , you can use flexible too according to your need but then you have to set VMs and specify instances and scaling criteria.

STEP 4:

Now before moving further we have to add a yaml file in our project which will hold certain configurations .

In the app.yaml file , do specify the runtime version of the language (latest version will reduce the latency of errors) .

As I have mentioned above that in a single application we can have multiple services so you can specify it in your yaml file .If it is not mentioned in the file GCP will put it in default service . We can configure more things like which files to skip , error handlers etc . For more detail check out the docs.

STEP 5:

Now move back to the GCP console and open terminal (icon on right side of search bar). Follow the following steps:

  1. Clone the your repository (you can use GCP repository too).
git clone  https://github.com/jiaabid/first.git

2. move to your project directory

cd first

3. install the node modules

npm i

4.DO BUILD your project with whatever build command you have set in you package.json file , this will create the dist folder in your project .

npm run build

5.Start your server and check is everything working fine .

npm run start

STEP 6:

Your project is now ready to deploy , run the following command to deploy

gcloud app deploy

And here your application is deployed !!

Above command will deploy the service with auto generated version id .If you want to keep the track of versions you can specify your own version id too at time of deployment.

gcloud app deploy -v ["any_version_id"]

In case you want to trace error , you can monitor the logs with following command,

gcloud app logs tail 

Or you can monitor it on App Engine dashboard too .

CONCLUSION:

These are few easy steps to deploy your Nest app on GCP . You can play around more like splitting the traffic on different versions or migrating the whole traffic to single version . Still alot to explore in this platform so let me know if I missed something .

Thanks for a read :)

--

--