Checkpoints
Deploying the Application into App Engine
/ 50
Updating the Application
/ 50
Deploy Node.js Express Application in App Engine
GSP028
Overview
Google App Engine applications are easy to create, easy to maintain, and easy to scale as your traffic and data storage needs change. With App Engine, there are no servers to maintain. You simply upload your application and it's ready to go.
App Engine applications automatically scale based on incoming traffic. load balancing, microservices, authorization, SQL and NoSQL databases, Memcache, traffic splitting, logging, search, versioning, roll out and roll backs, and security scanning are all supported natively and are highly customizable.
App Engine's environments, the Standard Environment and the Flexible environment , support a host of programming languages, including Java, Python, PHP, Node.js, Go, etc.. The two environments give users maximum flexibility in how their application behaves since each environment has certain strengths. Read The App Engine Environments for more information.
This tutorial uses the sample code from the Google Cloud Node.js Getting Started guide
You will learn how to connect to computing resources hosted on Google Cloud via the web. You will learn how to use Cloud Shell and the Cloud SDK gcloud command.
What you'll learn
- How to create a Node.js Express application on Google App Engine.
- How to update the code without taking the server down.
Setup and Requirements
Qwiklabs setup
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud Console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Cloud Console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- In the Cloud Console, in the top right toolbar, click the Activate Cloud Shell button.
- Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. The output contains a line that declares the PROJECT_ID for this session:
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
-
(Optional) You can list the active account name with this command:
(Output)
-
(Optional) You can list the project ID with this command:
(Output)
(Example output)
gcloud
, in Google Cloud, Cloud SDK documentation, see the gcloud command-line tool overview.
Enable the App Engine Admin API
Click on the Navigation menu icon in the top left of the screen:
Select APIs & services from the drop down and click on Enabled APIs and services:
Click on Enable APIs and services:
Then, search for App Engine
in the search box.
Click on App Engine Admin API, then click Enable if the API isn't enabled already.
Get the Getting Started Example source code
After Cloud Shell launches, you can use the command line to clone the example source code in the home directory:
Adjust the version of node
in your package.json
:
Now, install the dependencies with npm
:
Run the Application Locally
You can start the Node.js application normally with npm
:
Once the application started, click on the Web Preview icon in the Cloud Shell toolbar and choose preview on port 8080.
A tab in your browser opens and connects to the server you just started.
In the cloud shell command line, press Ctrl+C to quit.
Deploying the Application into App Engine
App Engine uses a file called app.yaml
to describe an application's deployment configuration. If this file is not present, App Engine will try to guess the deployment configuration. However, it is a good idea to provide this file.
Open app.yaml
to see what it contains. You can use vim,
nano
,or emacs
to view the file:
app.yaml
This is the basic configuration needed to deploy a Node.js application. You can learn more about configuring App Engine here .
Close the file without making any modifications.
To deploy your application into App Engine environment, run:
Because this is the first time you are deploying App Engine, the tool will prompt you to select a location to deploy the app. For this lab choose us-central
and click Enter.
When prompted, enter y
to confirm deployment.
After the application deploys, you can visit it by opening the URL http://<project-id>.appspot.com
in your web browser. The project-id is the Project ID in the CONNECTION DETAILS section of the lab.
gcloud app browse
In this step, you set up a simple Node.js application and ran and deployed your application on App Engine.
Test Completed Task
Click Check my progress to verify your performed task. If you have successfully deployed the application into App Engine, you will see an assessment score.
Updating the Application
Update the application to generate a UUID every time someone visits the page.
Install the uuid
package with npm
:
Now modify app.js to use uuid
. You can use vim
, nano
, or emacs
to edit the file:
Enter the following in the the Cloud Shell Command Line to update the app.js
file:
Start the editor:
Import the uuid module in app.js
file:
Update the following in app.js
file:
Save the app.js file by pressing: <Esc>
then entering:
app.js
Now, you can test the application locally.
Start the Node.js application with npm
:
Once the application started, click on the Web Preview icon in the Cloud Shell toolbar and choose preview on port 8080.
A tab in your browser opens and connects to the server you just started. You should see the new app that displays a UUID!
In the cloud shell command line, press Ctrl+C to quit.
To deploy your updated application, run:
In a few minutes, the new version will be deployed and you can visit it by opening the URL http://<project-id>.appspot.com
in your web browser.
gcloud app browse
In this step, you updated your Node.js application without any downtime.
Test Completed Task
Click Check my progress to verify your performed task. If you have successfully deployed the updated application into App Engine, you will see an assessment score.
Congratulations!
You learned how to write and deploy your first App Engine web application!
Finish Your Quest
This self-paced lab is part of the Deploying Applications Quest. A Quest is a series of related labs that form a learning path. Completing this Quest earns you the badge above, to recognize your achievement. You can make your badge (or badges) public and link to them in your online resume or social media account. Enroll in this Quest and get immediate completion credit if you've taken this lab. See other available Quests.
Take Your Next Lab
Continue your Quest with Build and Launch an ASP.NET Core App from Google Cloud Shell, or check out these suggestions:
Next Steps / Learn More
- Node.js on Google Cloud: https://cloud.google.com/nodejs/
- App Engine Documentation: https://cloud.google.com/appengine/
Google Cloud Training & Certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated March 17, 2022
Lab Last Tested March 17, 2022
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.