Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module '@google-cloud/storage'

I am using the GCP console on my browser. I have created a function as following:

function listFiles(bucketName) {
  // [START storage_list_files]
  // Imports the Google Cloud client library
  const Storage = require('@google-cloud/storage');

  // Creates a client
  const storage = new Storage();


  storage
.bucket(bucketName)
.getFiles()
.then(results => {
  const files = results[0];

  console.log('Files:');
  files.forEach(file => {
    console.log(file.name);
  });
})
.catch(err => {
  console.error('ERROR:', err);
    });
  // [END storage_list_files]
}

exports.helloWorld = function helloWorld (req, res) {
  if (req.body.message === undefined) {
    // This is an error case, as "message" is required
    res.status(400).send('No message defined!');
  } 
  else {
    // Everything is ok
    console.log(req.body.lat);
    console.log(req.body.lon);
    listFiles("drive-test-demo");
    res.status(200).end();
  }
}

Literally all I am trying to do right now is list the files inside a bucket, if a certain HTTPS trigger comes through.

my package.json file is as follows:

{
  "name": "sample-http",
  "version": "0.0.1",
  "dependencies": {
    "@google-cloud/storage": "1.5.1"
  }

} 

and I am getting the error "Cannot find module '@google-cloud/storage'"

Most queries I have seen thus far have been resolved by using npm install, but I don't know how to do that considering that my index.js and package.json files are stored in a zip file inside a gcloud bucket. Any advice on how to solve this would be much apreciated.

like image 444
R.Dyer-Evans Avatar asked Dec 19 '17 12:12

R.Dyer-Evans


People also ask

What types of data are supported by Google Cloud Storage?

Example: Financial data, logs, etc. From the various offerings of Google Storage service, structured data can be stored in Cloud SQL, Cloud Spanner, Cloud Datastore, Cloud Bigtable, Cloud BigQuery, and Persistent disk.

What is cloud storage in GCP?

Cloud Storage is a service for storing your objects in Google Cloud. An object is an immutable piece of data consisting of a file of any format. You store objects in containers called buckets.


1 Answers

Open console, change dir to you functions project and type:

npm install --save @google-cloud/storage

That's all!

like image 189
Serge Avatar answered Oct 20 '22 19:10

Serge