How to deploy Node.js app on Google App Engine

Google App Engine is a part of the Google Cloud Suite which provides a cloud platform for developers where they can develop and host their apps. It provides easily configurable, fast and secure programming environments/tools with the help of which developers can setup a development environment in just a few minutes. Therefore developers don’t need to worry about configuring the environment, they can just focus on writing code. It supports all the popular programming languages Java, PHP, Node.js, Python, C#, .Net, Ruby and Go.

Till now there was no support for Node.js, but Google has just announced that developers will now be able to deploy their Node.js apps to the App Engine. NodeJS on Google Cloud App Engine

Steps to deploy Node.js web service on App Engine

Prerequisites

  1. You must have a project on the Google Cloud Platform. If you don’t, create one using the GCP Console.

  2. The development environment should be configured. You have 2 options here.

    • Configure it on the cloud using Cloud Shell
    • Setup your local machine
      • Download and install Node.js and Node Package Manager Get Node.js and npm

        Only Node.js version 8 or greater is supported on App Engine.

      • Download and install Google Cloud SDK Get Google Cloud SDK

        Google Cloud SDK also installs gcloud command line tool.

Hello world!

  1. There’s a sample Node.js repository on GitHub. Either clone it using git or download the zip.

    git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
  2. Navigate to the below directory

    cd nodejs-docs-samples/appengine/hello-world/standard
  3. Install the required dependencies using npm utility

    npm install
  4. Start the web server

    npm start
  5. Check output

    • If you are using Cloud Shell then click on Web preview
    • If you are on Local Machine then navigate to http://localhost:8080/

Deploy on App Engine

Since we have verified that our Hello World program is working fine, it’s time to deploy it.

  1. If you had installed Google Cloud SDK properly (as mentioned in Prerequisites), you’ll have access to the gcloud command. Run it as below

    gcloud app deploy
  2. Your app should now be live at https://<PROJECT_ID>.appspot.com/

    gcloud app browse   

That’s it. You have successfully deployed your sample Node.js app on the Google App Engine.

Refer Google’s official guide on Building a Node.js App on App Engine

You can try out Google App Engine’s free tier to deploy your Node.js app and see if you like it.

Help us improve this content by editing this page on GitHub