node.jsfirebasegoogle-cloud-functions

Setting up dotenv in firebase functions


I am trying to move the tiny node-express app I made into Firebase functions.

The files have dotenv variables. Earlier I thought If I just deployed and put the dotenv in dependency, It would work but that didn't happen so...

So, I went to the environment configuration article of Firebase to understand how I can set .env

Which states to set things by doing something like this

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

But I have so many environment configurations and doing that some what seems to be a cumbersome task.

So let's say this is an environment file

# App port Address
PORT = 8080

# Google Secret 
GOOGLE_CALLBACK_URL =   http://localhost:8080/auth/google/callback
GOOGLE_CLIENT_ID = 40xxxx8-xxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET = lxxxxxxxxxxxxO

# Client Address 
CLIENT_ADDRESS = http://localhost:3000/


# Meetup Secret 
MEETUP_CALLBACK_URL = http://localhost:8080/auth/meetup/callback
MEETUP_CLIENT_ID = exxxxxxxxxxxxxxxxxxxt
MEETUP_CLIENT_SECRET = sxxxxxxxxxxxxxxxxt

#EventBrite Secret 
EVENTBRITE_CALLBACK_URL = http://localhost:8080/auth/eventbrite/callback
EVENTBRITE_CLIENT_ID = UxxxxxxxxxxxxxN
EVENTBRITE_CLIENT_SECRET = Nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4 

How Can I best set up so that when I do firebase firebase serve --only functions,hosting it doesn't throw any errors such as

OAuth2Strategy requires a clientID option


Solution

  • The Firebase CLI currently doesn't allow you to set process environment variables on deployment. This may change in the future. The configuration vars it supports today (that you linked to) are not actually process environment variables - they stored somewhere else that's not actually the process environment.

    If you absolutely need to be able to set process environment variables, you will have to deploy your function with gcloud, which means that you also won't be able to use the firebase-functions module to define your function. Start with the Google Cloud Functions documentation to learn about deployment from a Cloud perspective.

    If you want to use the Firebase tools, I'd recommend that you find a different way to configure your function that doesn't involve process environment variables.