title: Uploading files from Firebase Cloud Functions to Cloud Storage
body: <p>The <a href="https://firebase.google.com/docs/storage/extend-with-functions" rel="noreferrer">documentation</a> is too complex for me to understand. It shows how to download a file from Cloud Storage to Cloud Functions, manipulate the file, and then upload the new file to Cloud Storage. I just want to see the basic, minimum instructions for uploading a file from Cloud Functions to Cloud Storage. Why doesn't this work:</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  
  admin.initializeApp();
  
  exports.storage = functions.firestore.document('Test_Value').onUpdate((change, context) =&gt; {
  
    var metadata = {
      contentType: 'text',
    };
  
    admin.storage().ref().put( {'test': 'test'}, metadata)
    .then(function() {
      console.log("Document written.");
    })
    .catch(function(error) {
      console.error(error);
    })
  
  });
  </code></pre>
  
  <p>The error message is <code>admin.storage(...).ref is not a function</code>. I'm guessing that <code>firebase-admin</code> includes Firestore but not Storage? Instead of <code>firebase-admin</code> should I use <code>@google-cloud/storage</code>? Why doesn't this work:</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  
  const {Storage} = require('@google-cloud/storage')();
  const storage = new Storage();
  
  admin.initializeApp();
  
  exports.storage = functions.firestore.document('Test_Value').onUpdate((change, context) =&gt; {
  
    storage.bucket().upload( {'test': 'test'} , {
      metadata: {
        contentType: 'text'
      }
    })
  
  });
  </code></pre>
  
  <p>I can't even deploy this code, the error message is </p>
  
  <pre><code>Error parsing triggers: Cannot find module './clone.js'
  </code></pre>
  
  <p>Apparently a npm module dependency is missing? But the module isn't called <code>clone.js</code>? I tried requiring <code>child-process-promise</code>, <code>path</code>, <code>os</code>, and <code>fs</code>; none fixed the missing <code>clone.js</code> error.</p>
  
  <p>Why does <code>admin.initializeApp();</code> lack parameters, when in my <code>index.html</code> file I have:</p>
  
  <pre><code>firebase.initializeApp({
      apiKey: 'swordfish',
      authDomain: 'myapp.firebaseapp.com',
      databaseURL: "https://myapp.firebaseio.com",
      projectId: 'myapp',
      storageBucket: "myapp.appspot.com"
    });
  </code></pre>
  
  <p>Another issue I'm seeing:</p>
  
  <pre><code>npm list -g --depth=0       
  
  /Users/TDK/.nvm/versions/node/v6.11.2/lib
  ├── child_process@1.0.2
  ├── UNMET PEER DEPENDENCY  error: ENOENT: no such file or directory, open '/Users/TDK/.nvm/versions/node/v6.11.2/lib/node_modules/firebase-admin/package.json
  ├── firebase-functions@2.1.0
  ├── firebase-tools@6.0.1
  ├── firestore-backup-restore@1.3.1
  ├── fs@0.0.2
  ├── npm@6.4.1
  ├── npm-check@5.9.0
  ├── protractor@5.4.1
  ├── request@2.88.0
  └── watson-developer-cloud@3.13.0
  </code></pre>
  
  <p>In other words, there's something wrong with <code>firebase-admin</code>, or with <code>Node 6.11.2</code>. Should I use a Node Version Manager to revert to an older version of Node?</p>