Custom node and ext package guidance (with modern ts possibly)


I'm writing my first custom node (not a script node). While I'm navigating using the documentation here, I'm not seeing any guidance on how to use other external npm libraries, and also most of them use ts.
In my case I'm trying to use firebase, for example.

What I have so far?

My super early WIP is here.
What it has so far is some basic inputs for firebase RTDB config with which I'm beginning to test.
In future these will be in a configuration node.


  1. I do not intent to not push it to npm BTW (only for my learning purposes).
  2. I will have configuration node and everything setup later.
  3. There will be many more features like status green when successfully connected to DB etc.

What help I'm looking for?

I'm not the JS/TS ninja unfortunately :smiling_face_with_tear:
So I was wondering if there could be someone who can show how to implement the simple functions (in my WIP firebase-rtdb-connect.js) like the one below (as those functions would are intended to be implemented):


  1. I'm currently facing struggles with these import styles and examples for pure js in firebase's documentation doesn't exist.
  2. I also came across a tutorial here, which helped a lot in my custom node creation's mental model but I'm getting stuck while trying/testing to importing ext modules.
click test.mjs (some function in here will are intended for implmentation)
import { initializeApp } from 'firebase/app';
import { getDatabase, ref, child, set, get, onValue, onChildAdded, onChildChanged, onChildRemoved} from "firebase/database";

const firebaseConfig = {
apiKey: "xxx",
authDomain: "xxx",
databaseURL: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx",
appId: "xxx"

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getDatabase();
const dbRef = ref(db);

// -- Listen Always
// onValue(data_struct_var, (snapshot) => {
onValue(ref(db, 'children'), (snapshot) => {  
const data = snapshot.val();
console.log("Const Listener->\t\t", data);

// -- Child Added
onChildAdded(ref(db, 'children'), (data) => {
console.log("\nOn child added->\t\t", "data.key:", data.key, ", data.val():", data.val());

// -- Child Changed
onChildChanged(ref(db, 'children'), (data) => {
console.log("\nOn child changed->\t\t", "data.key:", data.key, ", data.val():", data.val());

onChildChanged(ref(db, 'test'), (data) => {
console.log("\nOn child changed->\t\t", "data.key:", data.key, ", data.val():", data.val());

// -- Child Removed
onChildRemoved(ref(db, 'children'), (data) => {
console.log("\nOn child removed->\t\t", "data.key:", data.key, ", data.val():", data.val());

// -- Get once
get(child(dbRef, 'children')).then((snapshot) => {
if (snapshot.exists()){
  const data = snapshot.val();
  console.log("One time Get() Listener->\t", data);
  console.log("\nNo data available");
}).catch((error) => {

// -- Set/Write/Update
// set(ref(db, 'test'), {
//   username: name,
//   email: email,
//   profile_picture : imageUrl
// });

set(ref(db, 'test'), 6);

// -- Push

Initially, I would like to propose you read the "Creating nodes" documentation... from the first letter to the last.

That done, you may create your first - simple - node & a use it in an (again) simple flow - to get accustomed to the working principles of Node-RED.

These steps will boost your learning curve - and give you a solid foundation for the rest of your journey.

And then ... you should give us some more details on what you're trying to achieve:
What I currently see is a standard script - yet nothing that leads to creating a node. Node-RED nodes act on messages that are sent to a node & processed by the node. The result of this processing is then forwarded ... to the next node in the flow.
Therefore - based on the info you gave us - I get the impression you should reconsider your setup...

Why did you choose Firebase to start?
It's a big implementation, not to mention that you first need to understand how Node-RED works.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.