firebase cloud function environment variables code example

Example 1: firebase functions config

const functions = require('firebase-functions');const request = require('request-promise');exports.userCreated = functions.database.ref('/users/{id}').onWrite(event => {  let email = event.data.child('email').val();  return request({    url: 'https://someservice.com/api/some/call',    headers: {      'X-Client-ID': functions.config().someservice.id,      'Authorization': `Bearer ${functions.config().someservice.key}`    },    body: {email: email}  });});

Example 2: firebase functions config

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

Example 3: deleting enviroment variables in firebase cloud functions

firebase functions:config:unset config.key

Example 4: firebase functions config

{  "someservice": {    "key":"THE API KEY",    "id":"THE CLIENT ID"  }}

Tags:

Misc Example