Firebase cloud functions - How to fetch the model data

firebase cloud functions write to database
firebase-functions
cloud functions firebase tutorial
firebase-functions express
firestore cloud functions example
firebase function return json
firebase functions middleware
firebase function call rest api

I'm working on creating the API using the firebase cloud functions. That API will display all data of model 'profiles'. My code is below but it is not working. (not able to read the document 'profiles' from firebase)

const functions = require('firebase-functions')

const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send('Hello from Firebase!')
})

exports.profiles = functions.https.onRequest((request, response) => {
  return admin.database().ref('/profiles').once('value')
    .then(function (snapshot) {
      const profiles = snapshot.val()
      response.status(200).send(profiles)
    })
})

The code of your Cloud Function should work (Successfully tested in my environment).

Your error is probably coming from the fact that you initialize like:

admin.initializeApp(functions.config().firebase)

when, since version 1.0, you should use a new syntax as follows:

admin.initializeApp();

See https://firebase.google.com/docs/functions/beta-v1-diff#new_initialization_syntax_for_firebase_admin

Extend Realtime Database with Cloud Functions - Firebase, The developer writes code for a new function, selecting an event provider (such as Realtime Duration: 2:23 Posted: May 18, 2018 Querying Data. With Firebase database queries, you can selectively retrieve data based on various factors. To construct a query in your database, you start by specifying how you want your data to


Change

response.status(200).send(username)

To

response.status(200).send(profiles)

Cloud Functions for Firebase, use cases using Cloud Functions for Firebase - firebase/functions-samples. how to create an isomorphic React application with server-side data fetching. Automatically publishes models to Firebase ML for each TensorFlow Lite file that​  Cloud firestore vs Realtime database. It provides us more structural data. This database is scalable. East to fetch the data. Multi-region support.


It seems you are triting to send as response the whole snapshot value, wich could include not Json compatible lines

const profiles = [];
snapshot.forEach(function(item) {
        const item = item.val();
        profiles.push(item);
    });
response.status(200).send(profiles);

This way you return an array of objects, wich is more JSON standard according to REST guidelines

firebase/functions-samples: Collection of sample apps , Use Firebase Realtime Database to implement an easy yet powerful API cache for your mobile apps. The cloud function we developed in part one was used to fetch raw data from our Persist cleaned up model to Firebase. Today I want to discuss about a very important topic. That is data retrieving. I know a lot of people are struggling to get data from Cloud Firestore. Especially from sub-collections. No more…


Take control of your backend with Firebase Cloud Functions (II), Next, read a bit more carefully through the docs on DataSnapshot, a.k.a. event.​data. This is the crux of Realtime Database events. Pay attention to  The Firebase Realtime Database can be accessed directly from a mobile device or web browser; there’s no need for an application server. Security and data validation are available through the Firebase Realtime Database Security Rules, expression-based rules that are executed when data is read or written.


Cloud Functions for Firebase, In this post I'll explain how we can use Firebase Cloud Functions to clean act as Server API models for the unnecessary received data and helper that will execute a function to fetch today's news edition from the backend,  Cloud Functions lets you run Realtime Database operations with full administrative privileges, and ensures that each change to Realtime Database is processed individually. You can make Firebase Realtime Database changes via the DataSnapshot or via the Admin SDK. In a typical lifecycle, a Firebase Realtime Database function does the following:


Take control of your backend with Firebase Cloud Functions, Cloud Functions allows you to write code that responds to changes in your Realtime Database Duration: 8:50 Posted: Jul 11, 2018 Firebase integrates with Google Cloud Functions to create lightweight Node.js tasks that are fired off by adding items to a Firebase list. Users can add jobs to a queue and your Cloud Functions can listen to that queue, process the job, remove the job from the queue and even add another job to a different queue for further processing.