Up until now I've been doing the following to use and test my functions locally during development:
I leave this running in one terminal:
firebase serve --only functions
And I add this on my client code when I'm initializing my Firebase app:
const config = {
apiKey: process.env.FIREBASE_APP_API_KEY,
authDomain: process.env.FIREBASE_APP_AUTH_DOMAIN,
databaseURL: process.env.FIREBASE_APP_DATABASE_URL,
projectId: process.env.FIREBASE_APP_PROJECT_ID,
storageBucket: process.env.FIREBASE_APP_STORAGE_BUCKET,
messagingSenderId: process.env.FIREBASE_APP_MESSAGING_SENDER_ID
};
firebase.initializeApp(config);
// THIS IS THE DEFAULT HOST AND PORT USED BY 'firebase serve command'
firebase.functions().useFunctionsEmulator('http://localhost:5000');
I have tested only HTTP callable functions and so far this has been working fine.
But in the docs, I see this:
https://firebase.google.com/docs/functions/local-emulator
Run functions locally
The Firebase CLI includes a Cloud Functions emulator which can emulate the following function types:
- HTTPS functions
- Callable functions
- Cloud Firestore functions
You can run functions locally to test them before deploying to production.
1. Install the Firebase CLI - Link
2. Set up admin credentials (optional) - Link
$ set GOOGLE_APPLICATION_CREDENTIALS=pathokey.json
$ firebase emulators:start
After completing these steps, your functions tests can access Firebase and Google APIs using the Admin SDK. For example, when testing an Authentication trigger, the emulated function could call admin.auth().getUserByEmail(email).
QUESTION
What is the difference between the two methods of running functions locally?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…