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.
Go to my local Firebase project path. Start the emulators using: firebase emulators:start. Create manually some mockup data using the GUI at http://localhost:4000/firestore using the buttons provided: + Start Collection and + Add Document. Export this data locally using: emulators:export ./mydirectory.
Launch the Local Emulator Suite with firebase emulators:start . The Cloud Functions and database emulators start up, automatically configured to interoperate. View the UI in your browser at http://localhost:4000 . Port 4000 is the default for the UI, but check terminal messages output by the Firebase CLI.
I was getting the following error when trying to run firebase for local testing:
The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
What I did wrong was no select both Firestore and Functions (see image).
then there are a number of commands available to spin up local testing:
The last one (#4) resolved the issue for me.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With