Remote Config triggers (1st gen)
Stay organized with collections
Save and categorize content based on your preferences.
You can trigger a function in response to
Firebase Remote Config events, including
the publication of a new config version or the rollback to an older version.
This guide describes how to create a Remote Config background function
that performs a diff of two template versions.
Trigger a Remote Config function
To define a handler for Remote Config events, use the
functions.remoteConfig
module's onUpdate()
function.
The TemplateVersion
object returned by
onUpdate
contains the key metadata
fields for a template update such as the version number and time of the update.
You can also retrieve the email for the user who made the update, with name
and an image if available.
Here's an example of a Remote Config function that
returns a diff of each updated version and the version it replaced. The function
examines the versionNumber
field of the template object and retrieves the
current (newly updated) version together with the version one number lower:
exports.showConfigDiff = functions.remoteConfig.onUpdate(versionMetadata => {
return admin.credential.applicationDefault().getAccessToken()
.then(accessTokenObj => {
return accessTokenObj.access_token;
})
.then(accessToken => {
const currentVersion = versionMetadata.versionNumber;
const templatePromises = [];
templatePromises.push(getTemplate(currentVersion, accessToken));
templatePromises.push(getTemplate(currentVersion - 1, accessToken));
return Promise.all(templatePromises);
})
.then(results => {
const currentTemplate = results[0];
const previousTemplate = results[1];
const diff = jsonDiff.diffString(previousTemplate, currentTemplate);
functions.logger.log(diff);
return null;
}).catch(error => {
functions.logger.error(error);
return null;
});
});
This sample uses the json-diff
and
request-promise
modules to
create the diff and build the request to get the template object. For a sample
that incorporates Remote Config client logic as well as Firebase Cloud Messaging,
see Propagate Remote Config updates in real time.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-05 UTC.
[null,null,["Last updated 2025-09-05 UTC."],[],[],null,["\u003cbr /\u003e\n\nYou can trigger a function in response to\n[Firebase Remote Config](/docs/remote-config) events, including\nthe publication of a new config version or the rollback to an older version.\nThis guide describes how to create a Remote Config background function\nthat performs a diff of two template versions.\n\nTrigger a Remote Config function\n\nTo define a handler for Remote Config events, use the\n[`functions.remoteConfig`](/docs/reference/functions/firebase-functions.remoteconfig)\nmodule's `onUpdate()` function.\nThe `TemplateVersion` object returned by\n`onUpdate` contains the key metadata\nfields for a template update such as the version number and time of the update.\nYou can also retrieve the email for the user who made the update, with name\nand an image if available.\n\nHere's an example of a Remote Config function that\nreturns a diff of each updated version and the version it replaced. The function\nexamines the `versionNumber` field of the template object and retrieves the\ncurrent (newly updated) version together with the version one number lower: \n\n```gdscript\nexports.showConfigDiff = functions.remoteConfig.onUpdate(versionMetadata =\u003e {\n return admin.credential.applicationDefault().getAccessToken()\n .then(accessTokenObj =\u003e {\n return accessTokenObj.access_token;\n })\n .then(accessToken =\u003e {\n const currentVersion = versionMetadata.versionNumber;\n const templatePromises = [];\n templatePromises.push(getTemplate(currentVersion, accessToken));\n templatePromises.push(getTemplate(currentVersion - 1, accessToken));\n\n return Promise.all(templatePromises);\n })\n .then(results =\u003e {\n const currentTemplate = results[0];\n const previousTemplate = results[1];\n\n const diff = jsonDiff.diffString(previousTemplate, currentTemplate);\n\n functions.logger.log(diff);\n\n return null;\n }).catch(error =\u003e {\n functions.logger.error(error);\n return null;\n });\n});https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Node-1st-gen/remote-config-diff/functions/index.js#L25-L51\n```\n\nThis sample uses the [`json-diff`](https://www.npmjs.com/package/json-diff) and\n[`request-promise`](https://www.npmjs.com/package/request-promise) modules to\ncreate the diff and build the request to get the template object. For a sample\nthat incorporates Remote Config client logic as well as Firebase Cloud Messaging,\nsee [Propagate Remote Config updates in real time](/docs/remote-config/propagate-updates-realtime)."]]