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 Google Cloud Client Library for Node.js 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 Node.js repository to your machine:

    git clone https://github.com/googleapis/nodejs-bigtable.git
    

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

  2. Change to the Hello World code sample directory:

    cd nodejs-bigtable/samples/hello-world
    

Costs

This sample uses billable components of Google Cloud Platform, including:

  • Cloud Bigtable

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

Before you begin

This sample requires Node.js 8.0 or later.

Installing Node dependencies

Run the following command to download the sample's dependencies:

npm install

Creating a project in the GCP Console

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

  1. Open the GCP 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. You must enable billing to use Cloud Bigtable.

Enable the Cloud Bigtable APIs

Make sure to enable the Cloud Bigtable APIs.

Install the Google Cloud SDK

If you haven't already installed the Google Cloud SDK, install it now, and be sure to run gcloud init to initialize the Cloud SDK. The SDK contains tools and libraries that enable you to create and manage resources on GCP.

Get credentials

To handle authentication, create a service account, and set the GOOGLE_AUTHENTICATION_CREDENTIALS environment variable to point to your service account key.

Creating an instance

Follow the instructions in the user documentation to create a GCP project and Cloud Bigtable instance if necessary. You'll need to use your Cloud Bigtable instance ID to run the application.

Running the application

Run the sample using Node.js. Replace BIGTABLEINSTANCE with the instance ID you chose.

INSTANCE_ID=BIGTABLEINSTANCE node index.js

The sample logs the following output to the console, along with informational logs from the client library:

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 GCP account, remove the resources created for this sample.

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

  2. Click the instance name.

  3. Click Delete instance.

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