mahendra
mahendra

Reputation: 203

Integrate remote config with Nodejs

I'm looking for a better way to integrate firebase remote config into my Nodejs server.

Basically I have 2 questions,

  1. firebase's Official js sdk documentation says remoteconfig does not support nodeJs, I was wondering what's the reason behind supporting web and not nodeJS?

  2. nodejs-quickstart uses rest endpoint, if I use this technique for managing my server's config,would I have to Implement polling? or is there a better way?

PS : Env variables are not an option because these configs changed over the time.

Upvotes: 3

Views: 6693

Answers (3)

alexbchr
alexbchr

Reputation: 613

Just for others landing here, the Firebase team seems to have added support for Server environments using Node.js quite recently, as documented here.

Although it is still under Preview at the moment and only supports Node.js, I guess it would solve the question.

Here's a short snippet showing it at work with a basic setup, but again I really recommend the documentation, which should be more up-to-date and more detailed than this answer, especially in the long term.

import { initializeApp } from "firebase-admin/app";
import { getRemoteConfig } from "firebase-admin/remote-config";

// Initialize Firebase
const firebaseApp = initializeApp();

// Initialize server-side Remote Config
const rc = getRemoteConfig(firebaseApp);
const template = rc.initServerTemplate();

// Load Remote Config
await template.load();

// Add template parameters to `config`. Evaluates the
// template and returns the parameter value assigned to
// the group assigned to the {randomizationId} and version.
const config = template.evaluate({
  randomizationId: "2ac93c28-c459-4760-963d-a3974ec26c04",
  version: "1.0",
  platform: "Android"
});

Upvotes: 1

0xori
0xori

Reputation: 585

You can use admin SDK

const admin = require("firebase-admin");
const serviceAccount = require("path/toyour/firebase-adminsdk.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://<project-database>.firebaseio.com"
});


const getConfig = async () => {
    let config = admin.remoteConfig();
    const template = await config.getTemplate()
   //all parameters will be under template.parameters
}

see docs here

Upvotes: 11

Frank van Puffelen
Frank van Puffelen

Reputation: 599686

firebaser here

The REST API for Firebase Remote Config allows you to change/manage the configurations, it does not allow you to consume them.

In other words: the REST API allows you to code your own replacement for the Remote Config panel in the Firebase console, it does not allow you to code your own replacement for the client-side SDKs.

If you'd like to see the Remote Config consumer APIs also be ported to the Node.js SDK, I recommend that you file a feature request. I don't see this request very often though, so you might want to look for alternatives in the meantime.

Upvotes: 8

Related Questions