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
- Costs
- Before you begin
- Creating an instance
- Running the application
- Cleaning up
Download the sample app and navigate into the app directory:
-
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.
-
Change to the Hello World code sample directory:
cd nodejs-bigtable/samples/hello-world
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.
This sample requires Node.js 8.0 or later.
Run the following command to download the sample's dependencies:
npm install
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.
- Open the GCP 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. You must enable billing to use Cloud Bigtable.
Make sure to enable the Cloud Bigtable APIs.
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.
To handle authentication, create a service account, and set
the GOOGLE_AUTHENTICATION_CREDENTIALS
environment variable to point to your
service account key.
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.
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
To avoid incurring extra charges to your GCP account, remove the resources created for this sample.
-
Go to the Cloud Bigtable instance page in the GCP Console.
-
Click the instance name.
-
Click Delete instance.
-
Type the instance ID, then click Delete to delete the instance.