Firebase

Enabling CORS Middleware In Firebase Cloud Functions

Firebase Cloud Functions are great, but there might come a time where you need CORS support. This can be enabled easily by using the CORS middleware. The documentation does detail part of the process, but it doesn’t mention you need to install the cors package and also specify origin: true as a configuration option. If you’re new to Node.js, this might catch you off guard. Go into your functions directory in your application and in your terminal: npm install cors --save this will add the CORS middleware package to your package.json.

Convert A Firebase Database Snapshot/Collection To An Array In Javascript

Because Firebase is a NoSQL JSON data store, you might have noticed that when you get some data from Firebase that it is an object. If the title wasn’t obvious enough, we are talking about using Firebase Realtime Database in a web application. Take the following example: firebase.database().ref('/posts').on('value', function(snapshot) { console.log(snapshot.val()); }); Let’s imagine that we have 20 posts in our database. You’ll get back an object containing keys and objects for all of our imaginary posts.