Could not load the default credentials? (Node.js Google Compute Engine tutorial)

SITUATION:

I follow this tutorial: https://cloud.google.com/nodejs/tutorials/bookshelf-on-compute-engine

Everything works fine until I do npm start and go to:

http://localhost:8080

I am met with the following text on the blank page:

Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.

Which makes no sense since I am using OAuth. I followed the link and read the page, but I have no GOOGLE-APPLICATION-CREDENTIALS field anywhere, and nothing about it in the tutorial.


QUESTION:

Could you please reproduce the steps and tell me if you get the same result ?

(takes 5 minutes)

If not, what could I have done wrong ?


Yes, I had the same error. It's annoying cause Google Cloud Platform docs for their "getting started" bookshelf tutorial does not mention this anywhere. Which means that any new developer who tries this tutorial will see this error.

Read this: https://developers.google.com/identity/protocols/application-default-credentials

I fixed this issue by running: gcloud auth application-default login

In order to run thisgcloud auth application-default login Visit: https://cloud.google.com/sdk/install 1) You have to install sdk into your computer 2) That will enable you to run the code 3) Log in to your associated gmail account then you are good to go!

This will make you login, and after that you code locally will use that authentication.


There are 2 solutions for this problem. One option, as mentioned by others, is to use gcloud auth application-default login

Second option is to set the environment variable GOOGLE_APPLICATION_CREDENTIALS. It should point to a file that defines the credentials. To get this file you need to follow these steps:

Go to the API Console Credentials page.

From the project drop-down, select your project.

On the Credentials page, select the Create credentials drop-down, then select Service account key.

From the Service account drop-down, select an existing service account or create a new one.

For Key type, select the JSON key option, then select Create. The file automatically downloads to your computer.

Put the *.json file you just downloaded in a directory of your choosing.

This directory must be private (you can't let anyone get access to this), but accessible to your web server code.

Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file downloaded.

See https://developers.google.com/identity/protocols/application-default-credentials for details