Skip to content

GogoVega/Firebase-Config-Node

Repository files navigation

Node-RED config-node to communicate with Firebase

Logo


Report Bug · Request Feature · Discussion

shield-license shield-issues shield-stars shield-forks shield-downloads shield-dependencies

Caution

BREAKING CHANGES: v0.2.0 - the required version of Node.js is now >=18 and the required version of Node-RED >=3

What is it?

This repo is used by the following modules:

Of coure, you can use it for your own module.

Preview

Below is a current overview of the config node, its appearance may change in the future.

Screenshot of the Connection tab
Screenshot of the config-node Connection tab
Screenshot of the Security tab
Screenshot of the config-node Security tab
Screenshot of the Databases tab
Screenshot of the config-node Databases tab

Authentication Methods

  • Anonymous
  • Email
  • Private Key (Firebase Admin Node.js SDK)
  • Custom Token (Generated with Private Key)

Available Databases

  • RTDB
  • Firestore

How to use?

  1. Add this package as dependency
npm i @gogovega/firebase-config-node@latest --omit=dev --save
  1. Retrieve the config-node and use the built-in methods
module.exports = function (RED) {
  function MyFirebaseNode(this, config) {
    RED.nodes.createNode(this, config);

    // Get the config-node
    const configNode = RED.nodes.getNode(config.database);

    // Init the RTDB and subscribe to the communication status
    configNode.addStatusListener(this.id, "rtdb");

    // The RTDB reference instance
    const rtdb = configNode.rtdb.database;

    // Gets data from msg.path and yields a `payload`
    this.on("input", async (msg, send, done) => {
      try {
        const snapshot = await configNode.rtdb.get(msg.path);
        send({ payload: snapshot });
        done();
      } catch (error) {
        done(error);
      }
    });

    // Unsubscribe the communication status
    this.on("close", (done) => configNode.removeStatusListener(done));
  }

  RED.nodes.registerType("my-firebase-node", MyFirebaseNode);
};

Getting Started Link

License

MIT License

Copyright (c) 2023 Gauthier Dandele

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.