1

i created a web app using node js express and firebase. i created a form which will upload a file to firebase but when i tried what's on the guide it gives an error..

var firebase = require('firebase');

var config = {
  apiKey: "----------------------------------",
  authDomain: "----------------------------------",
  databaseURL: "-",----------------------------------
  projectId: "---------",
  storageBucket: "----------------",
  messagingSenderId: "---------------"
};

firebase.initializeApp(config);

module.exports = firebase;

// Get a reference to the storage service, which is used to create references in your storage bucket
var storage = firebase.storage();

// Create a storage reference from our storage service
var storageRef = storage.ref();

this is the set up i use for using firebase on node js.

var storage = firebase.storage();
                       ^
TypeError: firebase.storage is not a function

and this is the error i receive from the console. after searching they said that i need to use google-cloud npm. so my question is if i install google-cloud on my node do i need to create an account on google cloud platform?..

1 Answer 1

1

Node js google-cloud package is used instead of firebase to store files, videos etc. Right now firebase storage is not compatible with Nodejs that's why you are getting that error^, yoou can do something like this to use google-cloud:-

npm install --save google-cloud

And then to use storage in your project this is a sample code:-

const gcloud = require('google-cloud');

const storage = gcloud.storage({
projectId: //project id here,
keyFilename: //service account credentials here,
});

const storagebucket = storage.bucket('projectID.appspot.com');

This link here has the complete guide how to do google-cloud stuff.

 https://medium.com/@stardusteric/nodejs-with-firebase-storage-c6ddcf131ceb
Sign up to request clarification or add additional context in comments.

5 Comments

why can i get my service account credential?.
here you can make one or use existing.....cloud.google.com/storage/docs/authentication
i got an error ...var storage-bucket = storage.bucket('iwatcher-a1e76.appspot.com'); ^ SyntaxError: Unexpected token -
give any name to the variable lol "-" cant be used as variable names.
i replace it.. thanks but following what is on link you provided after trying i always lands on this script.. blobStream.on('error', (error) => { reject('Something is wrong! Unable to upload at the moment.'); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.