google-cloud-node: Error: Missing key, key or keyFile option must be provided!

While using gcloud on my own local server, I write:

var gcloud = require('gcloud');
var bucket;

bucket = gcloud.storage.bucket({
    projectId: 'myProjectName',
    keyFilename: 'resources/key.json',
    bucketName: 'testnameorwhatever'
});

bucket.write('demo.txt', 'Hello World', function(err) {
        var stuff = err || 'Created demo.txt'
        console.log(stuff);
});

if I do specify the right path to the key, it gives this output (not thrown error, just console log): [Error: Missing key, key or keyFile option must be provided!] I do not understand this message. There is a key specified, and the path to it is right. I know that, as if I write the wrong keyFilename path, it throws ENOENT error 34. So, is it about the key description or something?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 21 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I’d say this issue comes down to a misunderstanding of the error message. The error itself is suggesting that a keyFile or key parameter should be specified, when really the error should suggest that they are likely using an invalid key file. Should we improve this err message?

I’m not proprietary of the project on the Google Cloud.

This is my view to get the json or the client and private keys. http://imgur.com/i4ZFKT4

var gcloud = require('gcloud');
var storage = gcloud.storage({
  projectId: 'teste-edco',
  keyFilename: __dirname +'/client.json'
  /*credentials: {
    client_email: 'email',
    private_key: '26chars_key'
  }*/
});

Not dumb at all! There are a million things you can do in the Developers Console, it’s very easy to get lost.

I believe you are using a client ID for a webapp, where what we want is a service account. https://github.com/GoogleCloudPlatform/gcloud-node/#elsewhere step 4 should show how to do that.

I’m going to close as I was able to reproduce the same error with a webapp key, and remedy it with a service key. If you run into anything else, ask away!