When you are done with Assignment 1 you will need to deploy it

How to deploy a Node application to Google Cloud

Google Cloud Platform (GCP) is one of the three major cloud computing platforms, alongside Amazon Web Services (AWS) and Microsoft Azure. Google Cloud Platform is widely used by businesses and organizations of all sizes for various cloud computing services, including infrastructure as a service (IaaS), platform as a service (PaaS), and software as a service (SaaS).

You will deploying your Node.js applications to GCP using their App Engine service. Here is a step-by-step guide:

GCP setup

The first few steps involve setting up a project on GCP

1. Sign up with Google Cloud

First, go to Google Cloud and click on the Get started for free button to create an account.

picture

You will need to supply a credit card for identification purposes. It will not be charged. If you stay within the free tier services you will not incur any charges (not even to your free $300 credit). All your work for ITM 352 will easily stay within the free tier. However, please take care not to accidentally authorize billable services!

Note: If you are unable to sign-up with your UH email account, use another gmail account (if you have one) or create a new gmail account.

2. Create new project

Go to the Managed Resources and select CREATE PROJECT: (see Managing and Creating Projects for details on creating a new project)

picture

Then fill in the project name and click on the CREATE button:

picture

Make a note of the Project ID so that you will recognize it later.

See https://cloud.google.com/resource-manager/docs/creating-managing-projects if you have trouble creating a new project.

Local setup

The remainder of this sample deployment will be done on your laptop.

3. Go to your project directory and open a terminal

Do an npm init and answer the questions. When it asks for the git repository, you can leave it blank or put in the URL of your GitHub repository for this application e.g. https://github.com/dport96/Port_Dan_Assignment1

After answering the questions at the prompts, make sure package.json has:

"scripts": {
"start" : "node server.js"
}

Ensure your Node.js application is properly structured with a package.json file specifying dependencies and an entry point (e.g., server.js). Make sure your application is listening on the correct port. Google App Engine expects applications to listen on port 8080.

Test that your application starts with npm start

4. Install Install Google Cloud SDK: (if you haven’t already done so)

Download and install the Google Cloud SDK if you haven’t already done so. Choose the appropriate operating system for your environment. This SDK includes the gcloud command-line tool, which you’ll use to interact with GCP.

5. Run gcloud init

Use the following command to initialize your GCP project: gcloud init

Follow the prompts to log in, select your GCP project, and configure the default settings.

See Setting up the Cloud SDK for more information.

6. deploy your application

Create an app.yaml file in the top-level directory and put in

runtime: nodejs20

Now use the gcloud app deploy command to deploy your Node.js application to Google App Engine:

gcloud app deploy

This command uploads your application’s source code to GCP, builds and packages it, and deploys it to App Engine. Follow the instructions and answer the questions when asked.

7. View your deployed application

After the deployment is successful, you can access your application using the following URL:

https://[YOUR_PROJECT_ID].appspot.com

Replace [YOUR_PROJECT_ID] with the ID of your GCP project.

For example:

picture

When your app is running you can view the console.log output you would normally see in your terminal by issuing gcloud app logs tail in your terminal. This will watch the console output on GCP for your running app.

You may want to watch the screencast on Deploying and Submitting Assignment 1 if you find the above instructions confusing or problematic.