I've been trying to implement some Cloud Functions that reads data from Cloud Firestore. I want to test these locally, however I cannot get the Cloud Firestore emulator to run. My assumptions are that it's where the problem is, but it might be somewhere else - if that's the case please let me know.
Here is my function:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin'
admin.initializeApp()
//Functions to fetch the documents in the user collection and send them to the client.
export const getUserDocs = functions.https.onRequest((request, response) => {
admin.firestore().doc('/Users/{documentId}').get()
.then(snapshot => {
const data = snapshot.data()
response.send(data)
})
.catch(error => {
response.status(500).send(error)
})
})
This is the error I get when I run the command firebase serve --only functions
:
Carlo@Carlos-Air-2 functions % firebase serve --only functions
⚠ Your requested "node" version "8" doesn't match your global version "13"
✔ functions: functions emulator started at http://localhost:5000
i functions: Watching "/Users/Carlo/app/functions" for Cloud Functions...
✔ functions[getUserSports]: http function initialized (http://localhost:5000/app/us-central1/getUserSports).
i functions: Beginning execution of "getUserSports"
⚠ functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
⚠ External network resource requested!
- URL: "http://179.252.163.233/computeMetadata/v1/instance"
- Be careful, this may be a production service.
⚠ External network resource requested!
- URL: "http://metadata.google.internal./computeMetadata/v1/instance"
- Be careful, this may be a production service.
i functions: Finished "getUserSports" in ~9s
I've tried starting from scratch again and uninstalling and reinstalling but with no success. I've also watched the tutorial series on YouTube but for some reason my code doesn't work.
Any help is greatly appreciated.
There is no error in your output console.
It's just a warning saying that you are not running Firestore locally, which is totally normal since you run the command with --only functions
and thus started only the cloud functions
part (without firestore, rules, etc)