如何使用 google-auth-library 和 Google Cloud Storage with NodeJS?

How to use google-auth-library with Google Cloud Storage with NodeJS?

我想用Google Cloud Storage in NodeJS but authenticate with google-auth-library 具体来说:我想在 heroku 上托管它,所以我想将秘密保存在环境变量中,而不是文件中(因为我必须提交文件才能部署到 heroku)。基本上 auth 库中的建议是什么: https://github.com/googleapis/google-auth-library-nodejs#loading-credentials-from-environment-variables

但我似乎无法将生成的客户端传递给存储构造函数?

阅读代码 [1,2,3,4,5] 您应该能够将凭据作为构造函数选项传递:

storageOptions = {
  projectId: 'your-project-id',
  credentials: {
        client_email: 'your-client-email',
        private_key: 'your-private-key'
  }
};
client = new Storage(storageOptions);