how to set firebase_config and gcloud_project in firebase project
Asked Answered
C

2

11

I tried to run the index.js file and it shows me the below error

C:\blog\functions>node index.js
{"severity": "WARNING", "message": "Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail"}```

i know that 

firebase functions:config:set someservice.key="THE API KEY" someservice.id="THE CLIENT ID"

this command will set environmental variables but what values should I set in environmental variables

I don't understand these lines from firebase documentation: (https://firebase.google.com/docs/functions/config-env)
process.env.GCLOUD_PROJECT: Provides the Firebase project ID
process.env.FIREBASE_CONFIG: Provides the following Firebase project config info:

should i set firebaseConfig details from project settings into environmental variables
Claymore answered 2/1, 2021 at 6:45 Comment(1)
Please check if you have stored values in environment variablesFated
R
11

FIREBASE_CONFIG and GCLOUD_PROJECT are environment variables on Firebase Functions servers. The reason they're not set is because you're trying to run your functions code in a standard node environment (node index.js) instead of running them on the Firebase production servers or in your local environment through the firebase-tools package's serve, shell or emulate which would locally mock the servers and give you the right config.

You don't have to set these values - just run your functions in the Firebase emulator (or shell). Check out the docs on how to get up and running.

Rann answered 2/1, 2021 at 13:45 Comment(0)
A
0

If you're finding this a bit noisy when running tests etc you can temporarily disable console.warn or replace it with a function that filters out the unwanted message.

const warn = console.warn
if (process.env.NODE_ENV === 'test')
    console.warn = (msg) => 
        !msg.includes('Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail')
        && warn(msg)

import * as functions from 'firebase-functions'
console.warn = warn

Just make sure this doesn't happen in production by using NODE_ENV === 'test' or something similar.

Ample answered 20/6, 2022 at 2:3 Comment(2)
Hey I am trying to remove this annoying warning messages from my tests but I cannot do it by following above set up. Do I have to add this to all my files or just on the index. Even adding to the index did not work. Also is there a way to temporarily disable console.warnMagnification
Hard to say without more info, if module-foo is using firebase-functions just replace the import line in the above example with module-fooAmple

© 2022 - 2024 — McMap. All rights reserved.