|
| 1 | +# @google-cloud/bigtable |
| 2 | +> Google Cloud Bigtable Client Library for Node.js |
| 3 | +
|
| 4 | +*Looking for more Google APIs than just Bigtable? You might want to check out [`google-cloud`][google-cloud].* |
| 5 | + |
| 6 | +- [API Documentation][gcloud-bigtable-docs] |
| 7 | +- [Official Documentation][cloud-bigtable-docs] |
| 8 | + |
| 9 | +*You may need to [create a cluster][cloud-bigtable-cluster] to use the Google Cloud Bigtable API with your project.* |
| 10 | + |
| 11 | + |
| 12 | +```sh |
| 13 | +$ npm install --save @google-cloud/bigtable |
| 14 | +``` |
| 15 | +```js |
| 16 | +var bigtable = require('@google-cloud/bigtable')({ |
| 17 | + projectId: 'grape-spaceship-123', |
| 18 | + keyFilename: '/path/to/keyfile.json', |
| 19 | + zone: 'my-zone', |
| 20 | + cluster: 'my-cluster' |
| 21 | +}); |
| 22 | + |
| 23 | +var table = bigtable.table('prezzy'); |
| 24 | + |
| 25 | +table.getRows(function(err, rows) {}); |
| 26 | + |
| 27 | +// Update a row in your table. |
| 28 | +var row = table.row('alincoln'); |
| 29 | + |
| 30 | +row.save('follows:gwashington', 1, function(err) { |
| 31 | + if (err) { |
| 32 | + // Error handling omitted. |
| 33 | + } |
| 34 | + |
| 35 | + row.get('follows:gwashington', function(err, data) { |
| 36 | + if (err) { |
| 37 | + // Error handling omitted. |
| 38 | + } |
| 39 | + |
| 40 | + // data = { |
| 41 | + // follows: { |
| 42 | + // gwashington: [ |
| 43 | + // { |
| 44 | + // value: 1 |
| 45 | + // } |
| 46 | + // ] |
| 47 | + // } |
| 48 | + // } |
| 49 | + }); |
| 50 | +}); |
| 51 | +``` |
| 52 | + |
| 53 | + |
| 54 | +## Authentication |
| 55 | + |
| 56 | +It's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Google Cloud services. |
| 57 | + |
| 58 | +### On Google Compute Engine |
| 59 | + |
| 60 | +If you are running this client on Google Compute Engine, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access. |
| 61 | + |
| 62 | +``` js |
| 63 | +// Authenticating on a global basis. |
| 64 | +var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123' |
| 65 | + |
| 66 | +var bigtable = require('@google-cloud/bigtable')({ |
| 67 | + projectId: projectId |
| 68 | +}); |
| 69 | + |
| 70 | +// ...you're good to go! |
| 71 | +``` |
| 72 | + |
| 73 | +### Elsewhere |
| 74 | + |
| 75 | +If you are not running this client on Google Compute Engine, you need a Google Developers service account. To create a service account: |
| 76 | + |
| 77 | +1. Visit the [Google Developers Console][dev-console]. |
| 78 | +2. Create a new project or click on an existing project. |
| 79 | +3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services): |
| 80 | + * Cloud Bigtable API |
| 81 | + * Cloud Bigtable Admin API |
| 82 | + * Cloud Bigtable Table Admin API |
| 83 | +4. Navigate to **APIs & auth** > **Credentials** and then: |
| 84 | + * If you want to use a new service account, click on **Create new Client ID** and select **Service account**. After the account is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests. |
| 85 | + * If you want to generate a new key for an existing service account, click on **Generate new JSON key** and download the JSON key file. |
| 86 | + |
| 87 | +``` js |
| 88 | +var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123' |
| 89 | + |
| 90 | +var bigtable = require('@google-cloud/bigtable')({ |
| 91 | + projectId: projectId, |
| 92 | + |
| 93 | + // The path to your key file: |
| 94 | + keyFilename: '/path/to/keyfile.json' |
| 95 | + |
| 96 | + // Or the contents of the key file: |
| 97 | + credentials: require('./path/to/keyfile.json') |
| 98 | +}); |
| 99 | + |
| 100 | +// ...you're good to go! |
| 101 | +``` |
| 102 | + |
| 103 | + |
| 104 | +[google-cloud]: https://github.com/GoogleCloudPlatform/google-cloud-node |
| 105 | +[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using |
| 106 | +[dev-console]: https://console.developers.google.com/project |
| 107 | +[gcloud-bigtable-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/bigtable |
| 108 | +[cloud-bigtable-docs]: https://cloud.google.com/bigtable/docs |
| 109 | +[cloud-bigtable-cluster]: https://cloud.google.com/bigtable/docs/creating-compute-instance |
0 commit comments