# How to use Doppler with Firebase functions?

**URL:** <https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379>\
**Category:** Need Help\
**Created:** [October 21, 2021, 8:06pm UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379 "2021-10-21T20:06:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ytrkptl](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@ytrkptl](https://community.doppler.com/u/ytrkptl)\
**Post date:** [October 21, 2021, 8:06pm UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/1 "2021-10-21T20:06:18Z")

</div>

I was able to use doppler locally while using Firebase Emulator using the docs in Doppler but am not sure how to use it in production. The docs didn’t help me much regarding production. It refers us to firebase docs, so is it trying to indicate that we need to use “firebase functions:config:set” to set each env variable we want to use?

---

<div class="post-metadata">

**Author:** ![ryan-blunden](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/ryan-blunden/32/9_2.png) [@ryan-blunden](https://community.doppler.com/u/ryan-blunden)\
**Post date:** [October 22, 2021, 4:26am UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/2 "2021-10-22T04:26:25Z")

</div>

Hi @ytrkptl and welcome to the Doppler community!

It seems our Firebase docs are in need of an update but for now, I’ve got the next best thing which is a sample repository that shows how to:

- [Perform config loading in dev and prod](https://github.com/DopplerUniversity/yodaspeak-firebase/blob/main/functions/config.js)
- [Update the config env store with Doppler production secrets](https://github.com/DopplerUniversity/yodaspeak-firebase/blob/main/functions/package.json#L7)
- [Deploy the function to apply the config changes](https://github.com/DopplerUniversity/yodaspeak-firebase/blob/main/functions/package.json#L8)

I’ll get to updating the docs next week but hopefully the sample repository will give you the coding patterns you need for now and I’d love to get your feedback!

---

<div class="post-metadata">

**Author:** ![ytrkptl](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@ytrkptl](https://community.doppler.com/u/ytrkptl)\
**Post date:** [October 22, 2021, 11:47am UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/3 "2021-10-22T11:47:52Z")

</div>

Hi there, thank you for replying. Here is what I did so far:

1. Updated package.json inside my functions folder to match the scripts in the 2nd and 3rd link you provided.
2. Updated environment.js inside the functions folder to match the first link you provided above.
3. From within the function directory, I ran `npm run config-env-set`

Here is the result I got. It threw an error showing the following:

 ![firebase-doppler-err1](https://us1.discourse-cdn.com/flex016/uploads/doppler/original/1X/6eaf743857579a08ae853b878cb6b5579dd1c9ee.png)

I then tried to deploy my function, which threw an error stating the following:

 ![firebase-doppler-err2](https://us1.discourse-cdn.com/flex016/uploads/doppler/original/1X/402a360494d47c80bff421fb06d52282c860b509.png)

Also, while trying using the existing docs yesterday, one error I received mentioned something about firebase not allowing uppercase letters when manually trying to set an env variable.

Any help would be appreciated with this error.

---

<div class="post-metadata">

**Author:** ![ryan-blunden](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/ryan-blunden/32/9_2.png) [@ryan-blunden](https://community.doppler.com/u/ryan-blunden)\
**Post date:** [October 22, 2021, 2:18pm UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/4 "2021-10-22T14:18:08Z")

</div>

No worries! We’ll figure it out!

Are you able to run the ‘doppler secrets download’ command in your package.json to confirm its actually returning JSON?

Can you also paste in the text commands for the config set and deploy commands from your package.json?

I think it’s really close.

---

<div class="post-metadata">

**Author:** ![ytrkptl](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@ytrkptl](https://community.doppler.com/u/ytrkptl)\
**Post date:** [October 22, 2021, 10:39pm UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/5 "2021-10-22T22:39:59Z")

</div>

Running `doppler secrets download` from within the functions folder created a doppler.json file in that folder with some gibberish in it. My package.json looks the same as the one you linked except that I did not enable linting.

Here is what I had prior to our discussion:

 ![packageJsonImg1](https://us1.discourse-cdn.com/flex016/uploads/doppler/original/1X/2465dd110adbe083ac82437f36852b4cd424ecb6.png)

I also tried to update the package.json based on the links you provided. Here is what it looks like now:

 ![packageJsonImg2](https://us1.discourse-cdn.com/flex016/uploads/doppler/original/1X/d115403db50cb39d273a1ec575b4fe1bd6f58a44.png)

Running `npm run config-env-set` shows the following this time around:

![firebase-doppler-err3](https://us1.discourse-cdn.com/flex016/uploads/doppler/original/1X/953e434c0d02a5f86caacf8715db8537825e8b45.png)

Thank you for the quick replies.

---

<div class="post-metadata">

**Author:** ![ryan-blunden](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/ryan-blunden/32/9_2.png) [@ryan-blunden](https://community.doppler.com/u/ryan-blunden)\
**Post date:** [October 25, 2021, 12:09am UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/6 "2021-10-25T00:09:31Z")

</div>

I believe this may be a quoting issue related to the shell that the script is executing in.

It appears you’re on Windows? What shell are you currently using?

Can you try running each command below to verify that what I’m seeing is consistent with your results in your shell:

```auto
# 1. This should work
firebase functions:config:set env="$(echo '{"TEST":"testing"}')"

# 2. This should also work
firebase functions:config:set env='{"TEST":"testing"}'

# 3. This should fail
firebase functions:config:set env="{"TEST":"testing"}"

```

Then can you try executing the code for the `config-env-set` script, but replace `\"` with `"` and run it directly in your shell (not through npm).

```auto
firebase functions:config:unset env && firebase functions:config:set env="$(doppler secrets download --config dev --no-file --format json --silent)"

```

Did that work?

If it does, that’s great news, as it’s now just a case of configuring npm to use the shell environment in which you executed the command.

If not, then we’ll likely need to look at a different shell for executing the command or perhaps writing a Node script that uses the Firebase SDK.

---

<div class="post-metadata">

**Author:** ![ytrkptl](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@ytrkptl](https://community.doppler.com/u/ytrkptl)\
**Post date:** [October 25, 2021, 1:14am UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/7 "2021-10-25T01:14:36Z")

</div>

The first command failed stating “Error: Invalid argument, each config value must have a 2-part key (e.g. foo.bar).”

I just use the Command Prompt on my Windows 10.

---

<div class="post-metadata">

**Author:** ![ytrkptl](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@ytrkptl](https://community.doppler.com/u/ytrkptl)\
**Post date:** [October 25, 2021, 11:57am UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/8 "2021-10-25T11:57:43Z")

</div>

> [@ryan-blunden](#):
>
> ```auto
> firebase functions:config:set env="$(echo '{"TEST":"testing"}')"
> 
> ```

Running the first command using the Git Bash terminal worked.

---

<div class="post-metadata">

**Author:** ![ytrkptl](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@ytrkptl](https://community.doppler.com/u/ytrkptl)\
**Post date:** [October 25, 2021, 1:01pm UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/9 "2021-10-25T13:01:41Z")

</div>

I ran that command you asked but replaced dev with prd like so

`firebase functions:config:unset env && firebase functions:config:set env="$(doppler secrets download --config prd --no-file --format json --silent)"`

and that created a config in firebase but with only the “env” variable set to an object like so:

 ![firebase-doppler-err4](https://us1.discourse-cdn.com/flex016/uploads/doppler/original/1X/4ce40378dacee05365e95bc2a07f8269ac18a278.png)

---

<div class="post-metadata">

**Author:** ![ryan-blunden](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/ryan-blunden/32/9_2.png) [@ryan-blunden](https://community.doppler.com/u/ryan-blunden)\
**Post date:** [October 26, 2021, 7:04am UTC](https://community.doppler.com/t/how-to-use-doppler-with-firebase-functions/379/10 "2021-10-26T07:04:25Z")

</div>

Awesome! That’s exactly the result you want!

So it sounds like configuring `npm` to use the Git bash terminal instead of the default Command Prompt is the right solution.

You should be able to verify the shell `npm` is using by running:

```auto
npm config ls -l

```

Then find the value for `script-shell`.

To change to using Git bash, override the default `script-shell` and set to the path of the Git Bash executable:

```auto
npm config set script-shell "C:\Program Files\Git\bin\bash.exe"

```

All this does is create a file at `~/.npmrc` that contains this override so nothing magical going on.

You should then be able to run the `npm run config-env-set` command without any issues.

Hope that clears this up for you and let me know how you go!
