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

**URL:** <https://discourse.nodered.org/t/custom-node-and-ext-package-guidance-with-modern-ts-possibly/75900>\
**Category:** Developing Nodes\
**Tags:** database, external-package\
**Created:** [1 March 2023 01:03 UTC](https://discourse.nodered.org/t/custom-node-and-ext-package-guidance-with-modern-ts-possibly/75900 "2023-03-01T01:03:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dattasaurabh82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dattasaurabh82/32/57236_2.png) [@dattasaurabh82](https://discourse.nodered.org/u/dattasaurabh82)\
**Post date:** [1 March 2023 01:03 UTC](https://discourse.nodered.org/t/custom-node-and-ext-package-guidance-with-modern-ts-possibly/75900/1 "2023-03-01T01:03:17Z")

</div>

## What?

I'm writing my first custom node (not a script node). While I'm navigating using the [documentation here](https://nodered.org/docs/creating-nodes/node-js), 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](https://firebase.google.com/docs/database/web/read-and-write?authuser=4), for example.

## What I have so far?

My super early WIP is [here](https://github.com/dattasaurabh82/node-red-contrib-firebase-rtdb-custom-lts).  
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.

**Notes:**

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 🥲  
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](https://github.com/dattasaurabh82/node-red-contrib-firebase-rtdb-custom-lts/blob/main/firebase-rtdb-connect.js)) **like the one below** (as those functions would are intended to be implemented):

**Note:**

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](https://medium.com/@darshan_dharmendra.chawda.kt/how-to-create-a-custom-node-in-the-node-red-61d88ebc2ffb), 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)**
>
> ```ts
> 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);
> }else{
> console.log("\nNo data available");
> }
> }).catch((error) => {
> console.error(error);
> });
> 
> // -- Set/Write/Update
> // set(ref(db, 'test'), {
> // username: name,
> // email: email,
> // profile_picture : imageUrl
> // });
> 
> set(ref(db, 'test'), 6);
> 
> // -- Push
> 
> ```

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [1 March 2023 08:49 UTC](https://discourse.nodered.org/t/custom-node-and-ext-package-guidance-with-modern-ts-possibly/75900/2 "2023-03-01T08:49:57Z")

</div>

Initially, I would like to propose you read the "[Creating nodes](https://nodered.org/docs/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...

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [1 March 2023 21:32 UTC](https://discourse.nodered.org/t/custom-node-and-ext-package-guidance-with-modern-ts-possibly/75900/3 "2023-03-01T21:32:25Z")

</div>

Hi,  
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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 April 2023 21:32 UTC](https://discourse.nodered.org/t/custom-node-and-ext-package-guidance-with-modern-ts-possibly/75900/4 "2023-04-30T21:32:27Z")

</div>

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