arrow_back

App Dev - Setting up a Development Environment: Node.js

登录 加入
访问 700 多个实验和课程

App Dev - Setting up a Development Environment: Node.js

实验 2 个小时 universal_currency_alt 5 积分 show_chart 入门级
info 此实验可能会提供 AI 工具来支持您学习。
访问 700 多个实验和课程

Overview

In this lab, you provision a Google Compute Engine virtual machine and install software libraries for Node.js software development on Google Cloud Platform (GCP).

Objectives

In this lab, you learn how to perform the following tasks:

  • Provision a Google Compute Engine instance.
  • Connect to the instance using SSH.
  • Install software on the instance.
  • Verify the software installation.

Setup and requirements

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Sign in to Qwiklabs using an incognito window.

  2. Note the lab's access time (for example, 1:15:00), and make sure you can finish within that time.
    There is no pause feature. You can restart if needed, but you have to start at the beginning.

  3. When ready, click Start lab.

  4. Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.

  5. Click Open Google Console.

  6. Click Use another account and copy/paste credentials for this lab into the prompts.
    If you use other credentials, you'll receive errors or incur charges.

  7. Accept the terms and skip the recovery resource page.

Task 1. Create a Compute Engine Virtual Machine instance

In this section, you use the Google Cloud Platform Console to provision a new Google Compute Engine virtual machine (VM) instance.

  1. In the Cloud Platform Console, on the Navigation menu, select Compute Engine > VM instances.

  2. Click Create Instance.

  3. On the Machine configuration page, specify the following:

  • Name: dev-instance.
  • Region: us-central1.
  • Zone: us-central1-a.
Note: Regions and zones

Google Cloud offers products and services in multiple distinct geographic locations, called regions. Each region has multiple distinct zones. Each zone is isolated from other zones in terms of power and internet connectivity.
  1. Click Networking.
  2. For Firewall, enable Allow HTTP traffic.
  3. Click Security.
  4. For Access scopes, enable Allow full access to all Cloud APIs.
  5. Leave the remaining settings as their defaults, and click Create.
Note: It takes about 20 seconds for the virtual machine to be provisioned and started.
  1. On the VM instances dialog, in the row for the dev-instance, click SSH (in the Connect column).
Note: This launches a browser-hosted SSH session. If you have a popup blocker, you may need to click twice. There's no need to configure or manage SSH keys.

Click Check my progress below to verify the objective. Create a Compute Engine Virtual Machine Instance

Task 2. Install software on the VM instance

In this section, you use the SSH session to install software on your VM instance.

  1. In the SSH session, to update the Debian package list, execute the following command:

    sudo apt-get update
  2. To install Git, execute the following command:

    sudo apt-get install git

    If prompted, press Y then Enter to continue.

  3. To install Node.js and Node Package Manager (npm), execute the following commands:

    sudo apt-get install -y ca-certificates curl gnupg sudo mkdir -p /etc/apt/keyrings curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg NODE_MAJOR=20 echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list sudo apt-get update sudo apt-get install nodejs -y

Click Check my progress to verify the objective. Install software on the VM instance

Task 3. Configure the VM to run application software

In this section, you verify the software installation and run some sample codes.

  1. To check the version of Node.js, execute the following command:

    node -v
Note: You should see the Node.js version 20.x.x.
  1. To clone the class repository, execute the following command:

    git clone --depth=1 https://github.com/GoogleCloudPlatform/training-data-analyst
  2. Create a soft link as a shortcut to the working directory:

    ln -s ~/training-data-analyst/courses/developingapps/v1.3/nodejs/devenv ~/devenv
  3. Navigate to the directory that contains the sample files for this lab, execute the following command:

    cd ~/devenv
  4. To run a simple web server, execute the following command:

    sudo node server/app.js
  5. Return to the Cloud Console VM instances list, and click on the External IP address for the dev-instance.

Note: A browser tab opens to display a Hello GCP dev! message from Node.js.
  1. Return to the SSH window and stop the application by pressing Ctrl+C.

  2. To install the Node.js library for Compute Engine, execute the following command:

    npm install
  3. To run a simple Node.js application that lists Compute Engine instances, execute the following command:

    node list-gce-instances.js
Note: Many details about your machine should appear in the terminal window. Note: If you try to do this on your own machine, it will not work if credentials have not been set up to access Google Cloud on your machine.

Click Check my progress to verify the objective. Clone the repository

Review

Congratulations! You learned how to provision a Google Compute Engine virtual machine and install software libraries for Node.js software development on Google Cloud Platform.

End your lab

When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

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.

准备工作

  1. 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
  2. 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
  3. 在屏幕左上角,点击开始实验即可开始

此内容目前不可用

一旦可用,我们会通过电子邮件告知您

太好了!

一旦可用,我们会通过电子邮件告知您

一次一个实验

确认结束所有现有实验并开始此实验

使用无痕浏览模式运行实验

请使用无痕模式或无痕式浏览器窗口运行此实验。这可以避免您的个人账号与学生账号之间发生冲突,这种冲突可能导致您的个人账号产生额外费用。