Search code examples
node.jsgoogle-cloud-platformgoogle-cloud-storagegoogle-cloud-sdk

Problem using Google Cloud Storage library


I am running following code in Node.js app:

var GoogleCloudStorage = require('@google-cloud/storage');
 var storage =  GoogleCloudStorage({
   projectId: 'PROJECT_ID',
   keyFilename: 'keyfile.json'
 });

It is showing this error GoogleCloudStorage is not a function What is the mistake?


Solution

  • Change your code to:

    const {Storage} = require('@google-cloud/storage');
    const storage =  new Storage({
       projectId: 'PROJECT_ID',
       keyFilename: 'keyfile.json'
     });
    

    I could not get the nodejs compiler to accept GoogleCloudStorage.