title: Uploading multiple files from a Google Cloud VM to Google Cloud Storage using node.js and Glob
body: <p>I am trying Node.js to upload multiple files from my Google Compute Engine VM local directory to a GCS bucket that I have already created. I am getting the following error each time I am running the script. </p>
  
  <p><code>TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type function</code></p>
  
  <p>The script: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> `// Imports the Google Cloud client library
  const {Storage} = require('@google-cloud/storage');
  const fs = require ('fs');
  const glob = require('glob');
  
  // The name of the bucket to access, e.g. "my-bucket"
     const bucketName = "myBucket";
  
  
  // Instantiates a client
  const storage = new Storage({
    projectId: 'myprojectID', 
    keyFilename: 'my GCS service key'
  });
  
  //get files in the local directory of VM 
  
  var allfiles = glob('folder/*.js', function (err, files) { 
      if (err) { 
          console.log(err); 
      }  
  });
  
  
  // Uploads VM local dir files  to the bucket
  storage
    .bucket(bucketName)
    .upload(allfiles)
    .then(() =&gt; {
      console.log(`${allfiles} uploaded to ${bucketName}.`);
    })
    .catch(err =&gt; {
      console.error('ERROR:', err);
    });'</code></pre>
  </div>
  </div>
  </p>
  
  <p>Apparently the 'Upload' process needs the file pathnames as string. But that's what the Glob function is supposed to do. Still why is the error? </p>
  
  <p>Any help will be seriously appreciated!</p>