Skip to content

Latest commit

 

History

History
 
 

hello-world

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Cloud Bigtable Hello World

This is a simple application that demonstrates using the Nodejs Google Cloud API to connect to and interact with Cloud Bigtable.

Table of Contents

Downloading the sample

Download the sample app and navigate into the app directory:

  1. Clone the Cloud Bigtable examples repository, to your local machine:

    git clone https://github.com/GoogleCloudPlatform/cloud-bigtable-examples.git
    

    Alternatively, you can download the sample as a zip file and extract it.

  2. Change to the Hello World code sample directory.

    cd cloud-bigtable-examples/node/hello-world
    

Costs

This sample uses billable components of Cloud Platform, including:

  • Google Cloud Bigtable

Use the Pricing Calculator to generate a cost estimate based on your projected usage. New Cloud Platform users might be eligible for a free trial.

Before you begin

This sample assumes you have Node with a minimum version of 8.0 installed.

Installing Node dependencies

Run the following command to download the bigtable library dependency:

npm install

Creating a Project in the Google Cloud Platform Console

If you haven't already created a project, create one now. Projects enable you to manage all Google Cloud Platform resources for your app, including deployment, access control, billing, and services.

  1. Open the Cloud Platform Console.
  2. In the drop-down menu at the top, select Create a project.
  3. Give your project a name.
  4. Make a note of the project ID, which might be different from the project name. The project ID is used in commands and in configurations.

Enabling billing for your project.

If you haven't already enabled billing for your project, enable billing now. Enabling billing allows is required to use Cloud Bigtable and to create VM instances.

Enable the Cloud Bigtable APIs.

Make sure to enable the Bigtable APIs.

Install the Google Cloud SDK.

If you haven't already installed the Google Cloud SDK, install the Google Cloud SDK now. The SDK contains tools and libraries that enable you to create and manage resources on Google Cloud Platform.

Setting Google Application Default Credentials

Set your Google Application Default Credentials by initializing the Google Cloud SDK with the command:

gcloud init

Generate a credentials file by running the application-default login command:

gcloud auth application-default login

Provisioning an instance

Follow the instructions in the user documentation to create a Google Cloud Platform project and Cloud Bigtable instance if necessary. You'll need to reference your project id and instance id to run the application.

Running the application

Run the sample using node. Replace BIGTABLEINSTANCE with what you called it when provisioning the instance.

INSTANCE_ID=BIGTABLEINSTANCE node index.js

You will see output resembling the following, interspersed with informational logging from the underlying libraries:

Creating table Hello-Bigtable
Write some greetings to the table
Reading a single row by row key
  Read: Hello World!
Reading the entire table
  Read: Hello World!
  Read: Hello Bigtable!
  Read: Hello Node!
Delete the table

Cleaning up

To avoid incurring extra charges to your Google Cloud Platform account, remove the resources created for this sample.

  1. Go to the Cloud Bigtable instance page in the Cloud Console.

  2. Click on the instance name.

  3. Click Delete instance.

    Delete

  4. Type the instance ID, then click Delete to delete the instance.