Lesson Learned from my first GCP APP Engine Deployment with Node.js

Aaron Yu
The Startup
Published in
3 min readMay 14, 2020

--

There are normally frustrating moments when you start with something for the first time. And it happened for me when I try Google Cloud Platform App Engine for the first time. So I think it might help some first-timers by sharing a few findings I had. If you are an experienced GCP App Engine user, this is not for you.

What is the problem?

I have a working node.js application. It’s running on port 3000 and it works perfectly fine. However, it failed deployment to App Engine Standard multiple times.

What normally could be wrong and what is the correct way

  • Make sure you have a correct app.yaml to tell GCP how to deploy your app.

You need to define runtime. If you are using App engine standard, you need to define as

runtime: nodejs8
OR
runtime: nodejs10
OR
runtime: nodejs12

Tip: nodejs12 is in beta. It may not work. Actually this was one of the key problems for my deployment. By changing to nodejs10, it worked just like magic!

If you use App engine flex, you should use runtime: nodejs. And you need to define the node version in your package.json

runtime: nodejs
env: flex

If you do not define the node version in package.json you will see the following warning:

Step #0: WARNING: Your package.json does not specify a supported Node.js version. Please pin your application to a major version of the Node.js runtime.
  • Make sure you have a correct package.json

Do not maintain node version as a dependency in your dependency block.

But you can define it as engines. This is required if you use App engine flex and your runtime is nodejs.

"engines": {
"node": ">=8.0.0"
},
  • Make sure your test is successful in GCP Cloud Shell

GCP Cloud Shell is really easy to use. You do not have to install SDK on your machine. After you cloned your app to Cloud Shell, you can use Cloud Shell to test your project.

#Step1
export PORT=8080 && npm install
#Step2
npm start
#Step3
Click on the Web View button to check whether your app is running or not

What does not matter

  1. The port you choose does not matter
  2. Where you define your port does not matter
  • You can hardcode it in app.js
  • You can hardcode it in ./bin/www file
  • You can define PORT=xxxx in .env file

3. How you start your app does not matter

  • You can have the script in package.json as “start”: “node app.js”
  • or “start”: “node ./bin/www”

4. You do not have to define firewall rule as there is a default ALLOW rule defined. However, you may want to restrict access to your service before it’s live for the production environment.

Some other tips

  • To create multiple services, just add a config in app.yaml: service: your-service-name. If you do not have this, it will be deployed as default service.
  • You can’t delete the default service
  • Add a friendly domain, you can do it simply in App Engine Setting-> Custom Domains

There is a free quota for App Engine Standard, so use it!

Have fun!

--

--

Aaron Yu
The Startup

I am not a coder, but I like solving problems programmably