you can rely on process.env
as of July 28, 2020 and package.json
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1"
},
if you start your app with firebase
firebase emulators:start
thenprocess.env will have properties like
"FUNCTIONS_EMULATOR": "true",
"FIRESTORE_EMULATOR_HOST": "0.0.0.0:5002",
"PUBSUB_EMULATOR_HOST": "localhost:8085"
"FIREBASE_AUTH_EMULATOR_HOST": "0.0.0.0:9099"
if you start your app with firebase
firebase emulators:start --only functions
thenprocess.env will have properties like
"FUNCTIONS_EMULATOR": "true",
USECASE
based on process.env you can write firebase.function to prepopulate your firestore emulator (not production firestore)!
code sample
export const prepopulateFirestoreEmulator = functions.https.onRequest(
(request, response) => {
if (process.env.FUNCTIONS_EMULATOR && process.env.FIRESTORE_EMULATOR_HOST) {
// TODO: prepopulate firestore emulator from 'yourproject/src/sample_data.json
response.send('Prepopulated firestore with sample_data.json!');
} else {
response.send(
"Do not populate production firestore with sample_data.json"
);
}
}
);