Ionică Bizău Ionică Bizău - 20 days ago 43x
Javascript Question

Upload files to Firebase storage using Node.js

I'm trying to understand how to upload files in Firebase Storage, using Node.js. My first try was to use the


"use strict";

var firebase = require('firebase');

var config = {
apiKey: "AIz...kBY",
authDomain: "",
databaseURL: "",
storageBucket: "",
messagingSenderId: "95...6"


// Error: is undefined, so not a function
var storageRef =;

var uploadTask = storageRef.child('images/octofez.png').put(file);

// Register three observers:
// 1. 'state_changed' observer, called any time the state changes
// 2. Error observer, called on failure
// 3. Completion observer, called on successful completion
uploadTask.on('state_changed', function(snapshot){
}, function(error) {
console.error("Something nasty happened", error);
}, function() {
var downloadURL = uploadTask.snapshot.downloadURL;
console.log("Done. Enjoy.", downloadURL);

But it turns out that
cannot upload files from the server side, as it clearly states in the docs:

Firebase Storage is not included in the server side Firebase npm
module. Instead, you can use the gcloud Node.js client.

$ npm install --save gcloud

In your code, you can access your Storage
bucket using:

var gcloud = require('gcloud')({ ... }); var gcs =;
var bucket = gcs.bucket('<your-firebase-storage-bucket>');

Can we use
without having an account on Google Cloud Platform? How?

If not, how come that uploading files to Firebase Storage from the client side is possible?

Can't we just create a library that makes the same requests from the server side?

How is Firebase Storage connected with Google Cloud Platform at all? Why
allows us to upload images only from the client side?

My second try was to use the
library, like mentioned in the docs:

var gcloud = require("gcloud");

// The following environment variables are set by app.yaml when running on GAE,
// but will need to be manually set when running locally.
// The storage client is used to communicate with Google Cloud Storage
var storage ={
projectId: "em...",
keyFilename: 'auth.json'

storage.createBucket('octocats', function(err, bucket) {

// Error: 403, accountDisabled
// The account for the specified project has been disabled.

// Create a new blob in the bucket and upload the file data.
var blob = bucket.file("octofez.png");
var blobStream = blob.createWriteStream();

blobStream.on('error', function (err) {

blobStream.on('finish', function () {
var publicUrl = `${}/${}`;



When using the firebase library on a server you would typically authorize using a service account as this will give you admin access to the Realtime database for instance. You can use the same Service Account's credentials file to authorize gcloud.

By the way: A Firebase project is essentially also a Google Cloud Platform project, you can access your Firebase project on both and and You can see your Project ID on the Firebase Console > Project Settings or in the Cloud Console Dashboard

When using the gcloud SDK make sure that you use the (already existing) same bucket that Firebase Storage is using. You can find the bucket name in the Firebase web config object or in the Firebase Storage tab. Basically your code should start like this:

var gcloud = require("gcloud");

var storage ={
  projectId: "<projectID>",
  keyFilename: 'auth.json'

var bucket = storage.bucket('<projectID>')