@google-cloud/datastore

The default export of the @google-cloud/datastore package is the Datastore class.

See the Datastore class for client methods and configuration options.

Examples
Install the client library with <a href="https://www.npmjs.com/">npm</a>:
```
npm install --save
```
Import the client library
```
const {Datastore} = require('@google-cloud/datastore');

```
Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
```
const datastore = new Datastore();

```
Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:
```
const datastore = new Datastore({ projectId:
'your-project-id', keyFilename: '/path/to/keyfile.json'
});

```

Full quickstart example:

// Imports the Google Cloud client library
const {Datastore} = require('@google-cloud/datastore');

// Creates a client
const datastore = new Datastore();

async function quickstart() {
  // The kind for the new entity
  const kind = 'Task';

  // The name/ID for the new entity
  const name = 'sampletask1';

  // The Cloud Datastore key for the new entity
  const taskKey = datastore.key([kind, name]);

  // Prepares the new entity
  const task = {
    key: taskKey,
    data: {
      description: 'Buy milk',
    },
  };

  // Saves the entity
  await datastore.save(task);
  console.log(`Saved ${task.key.name}: ${task.data.description}`);
}
quickstart();

Members

v1

Properties:
Name Type Description
DatastoreClient constructor

Reference to v1.DatastoreClient.

See: