Deploying node.js app in GCP

Google has been the pioneer in the technology field from popularizing AJAX to cloud to Bigdata, you name it. However, Amazon is the one that is successful in monetizing on these technologies. IMHO, The reason is two fold, one it was late to the market and second being documentation. If it was pretty late to join the cloud party, preparing documentation like a IEEE journal didn’t help its cause either. In fact, it made it worse. I have been playing with AWS since 2008 but when I looked at GCP (formerly GCE) couple of years ago at one of their events, I left pretty depressing, couldn’t accomplish a simple task of creating a server and hosting a site!

With this background, I started my journey couple of days back to deploy a node.js website in GCP. The webapp is a simple SPA, developed with AngularJS 2.0 as the front and node.js on the back-end. One small twist was that this app was accessing AWS CloudSearch to perform the search and return the results.

One thing I should admit that their documentation has come a long way (I was successful in hosting the site:-)). I started with this Now that Google is also offering a generous $300 credit for the first year and I was able to follow their document and host the hello-world sample app. Having said that, I looked at the documentation to achieve this on three other places Heroku, Azure and AWS. I must say GCP is the simplest. However, it was not without its quirks. I had my webapp developed using node.js, Express and Angular.JS and here is what you can do to get your webapp ready for deploying in GCP .

  1. Copy the app.yaml from the hello-world sample that you downloaded from the github. Make sure the exclude ^nodemodules is not there.
  2. Went to the command prompt and followed the documentation.
  3. I did gcloud app deploy.

This took a long time and errored out saying “Error loading module (‘aws-sdk’)”. I searched around and after couple of hours found out by trial & error that this is not mentioned in the dependencies in the package.json file. Finally the app got successfully deployed after it took a very long time. I was thrilled but my euphoria was short-lived as the app was not loading on the browser and was throwing 502 error and asked me to try in 30 seconds.

I started researching, there is no solution in sight. Everyone was pointing me to read the logs and being new to GCP, was moping around figured where the logs are and started going through them which is like finding needle in a haystack. Some error was pointing to upstream connectivity failure on nginix and I noticed a loadbalancer error of unable to connect back to the server. Having setup a loadbalancer in both Azure and AWS, I thought that the loadbalancer is not able to direct the traffic to the actual webserver where the site is hosted (though, i didn’t ask for a loadbalancer, GCP by default deploys the site atleast on two servers to make it HA). I found an article ( ) that loadbalancer uses port 80 or 8080 for HTTP traffic and 443 for HTTPS. My server.js file was listening on 8000. I changed it to 8080, voila! it worked. I was ecstatic, how cool is that?

I built and hosted a site on Google Firebase + Angular earlier and now this one, my perception about GCP is changing. Google is becoming a player as well.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: