user5389245
user5389245

Reputation:

Access Google Cloud Datastore from Node app running on local machine

I am new to Google Cloud Platform.

  1. I have written a node application to add entities to the google cloud datastore.
  2. I have a GCP(Google Cloud Platform) account and created a project within it to access the Google Cloud Datastore.
  3. I have created service keys(JSON file) for the GCP project above and downloaded the former.

Now, i need to connect the node server running on my local machine to Google Cloud Datastore using the service account key. How can i do this? I got a bit confused with lot of documentations posted on Google cloud site. Can someone please explain me the steps/process/flow ?

Upvotes: 0

Views: 484

Answers (2)

Llama D'Attore
Llama D'Attore

Reputation: 437

You can connect to a remote google datastore from your local node app via the Google Service Key API: https://cloud.google.com/docs/authentication/getting-started#linux-or-macos

The process is simple enough:

  1. Create a Google Service account key.
  2. Export your GOOGLE_APPLICATION_CREDENTIALS variable to be the path where your key file is stored.

Mac/Linux (via command line)

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"

Windows (via powershell)

$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\my-key.json"

You can generate this Google Service Key by clicking this link: https://console.cloud.google.com/apis/credentials/serviceaccountkey?_ga=fuckuranalytics

Upvotes: 0

Bira
Bira

Reputation: 5506

Google Cloud Datastore has a local development server that you can use: https://developers.google.com/datastore/docs/tools/devserver

You can create and start the local datastore using the gcd tool which is linked to in the doc above.

If you use DatastoreHelper.getDatastoreFromEnv(); to build your Datastore, you can tell it to connect to your local database by exporting the env variable DATASTORE_HOST:

export DATASTORE_HOST=http://localhost:8080

Upvotes: 1

Related Questions