Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  18] [ 6]  / answers: 1 / hits: 92690  / 8 Years ago, tue, december 27, 2016, 12:00:00

Following this example, I keep getting the error:



 TypeError: firebase.storage is not a function


From this line in my code:



var storageRef = firebase.storage().ref();


(And when I simply try to initialize storage from the storage guide, linked from firebase's npm site, I get the same error.)



In my Node.js project, I'm including the following libraries:




  • const firebase = require('firebase');

  • var admin = require('firebase-admin');

  • const fs = require('fs');



Up to this point, I've successfully been able to read from and write to the firebase database, creating a reference to the database with var db = admin.database(), then var ref = db.ref(/)... So I know I've configured Firebase and firebase-database correctly. But I'm stuck on storage, and have tried both admin.storage().ref() and firebase.storage().ref(), and firebase.storage().ref(/) with the same error message.



I've also tried:



var storage = firbase.storage();
var storageRef = storage.ref();


and



const app = firebase.initializeApp(config);
var storage = app.storage();


and with ref()'s void argument () and with /... but have the same message, yet to no avail.



I'm using:




  • firebase: ^3.6.4

  • firebase-admin: ^4.0.4

  • Node.js : v6.9.1



What must I do to successfully create a reference to storage?


More From » node.js

 Answers
18

DEPRECATED, see below:



According to this answer, instead of firebase storage, in Node.js, google-cloud package storage should be used, and it seems that this answer should confirm it. Code example:



npm i --save google-cloud


Then:



const gcloud = require('google-cloud')

const storage = gcloud.storage({
projectId: '<projectID>',
keyFilename: 'service-account-credentials.json',
});

const bucket = storage.bucket('<projectID>.appspot.com')


As of 2018, this is the correct answer:



Or using only the storage part of the package:



npm install --save @google-cloud/storage


And then:



var storage = require('@google-cloud/storage')


Also check the docs for more.


[#59544] Sunday, December 25, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taylert

Total Points: 627
Total Questions: 91
Total Answers: 108

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
taylert questions
;