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
- Costs
- Before you begin
- Provisioning an instance
- Running the application
- Cleaning up
Download the sample app and navigate into the app directory:
-
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.
-
Change to the Hello World code sample directory.
cd cloud-bigtable-examples/node/hello-world
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.
This sample assumes you have Node with a minimum version of 8.0 installed.
Run the following command to download the bigtable library dependency:
npm install
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.
- Open the Cloud Platform Console.
- In the drop-down menu at the top, select Create a project.
- Give your project a name.
- 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.
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.
Make sure to enable the Bigtable APIs.
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.
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
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.
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
To avoid incurring extra charges to your Google Cloud Platform account, remove the resources created for this sample.
-
Go to the Cloud Bigtable instance page in the Cloud Console.
-
Click on the instance name.
-
Click Delete instance.
-
Type the instance ID, then click Delete to delete the instance.