# Converting code to a node

**URL:** https://discourse.nodered.org/t/converting-code-to-a-node/40294
**Category:** Developing Nodes
**Created:** [3 February 2021 08:38 UTC](https://discourse.nodered.org/t/converting-code-to-a-node/40294 "2021-02-03T08:38:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![V\_Tom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/v_tom/32/36419_2.png) [@V\_Tom](https://discourse.nodered.org/u/V_Tom)
#### Post date: [3 February 2021 08:38 UTC](https://discourse.nodered.org/t/converting-code-to-a-node/40294/1 "2021-02-03T08:38:20Z")

</div>

Hey

Some years ago, I was interested in this project: [https://github.com/crjens/PiPowerMeter](https://github.com/crjens/PiPowerMeter)

I got some of his boards and after quite some tinkering, I got it working.

Because I was not happy with the accuracy and didn't have the time to make it work properly, I left this project in the cupboard.

Now I want to give it another try. Unfortunately doing the install described on the github page is not working as there are many dependency errors.

As I'm now using Node-Red and InFluxdb for many of my home projects, I'd rather just implement this power meter into it.

Ideally, I have a node in Node-Red, where I can just inject a message saying which current channel, voltage channel and correction factor to use. And it would output a message containing current, voltage and power.

But how do I go about that? I can do some basic Javascript to make function nodes, but I have no clue on how to insert such a large amount of functions into 1 node.

Anybody that can give me some pointers, guides, help... so I can make this work?

Thanks a lot!

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [3 February 2021 10:21 UTC](https://discourse.nodered.org/t/converting-code-to-a-node/40294/2 "2021-02-03T10:21:23Z")

</div>

The easiest approach for this use case is using a subflow, then you can reuse the function.

Note that there is a big menu on the top of this site and one item is "documentation", both subflows and creating nodes is explained there.

---

<div class="post-metadata">

### Author: ![V\_Tom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/v_tom/32/36419_2.png) [@V\_Tom](https://discourse.nodered.org/u/V_Tom)
#### Post date: [3 February 2021 20:57 UTC](https://discourse.nodered.org/t/converting-code-to-a-node/40294/3 "2021-02-03T20:57:07Z")

</div>

Thanks.

So I would create a subflow with function nodes, and each function node contains 1 function from the javascript source file?

I actually looked for some information about this, but Google was not a good helper. Should've checked the nodered website of course... 🤦‍♂️

---

<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: [4 April 2021 20:57 UTC](https://discourse.nodered.org/t/converting-code-to-a-node/40294/4 "2021-04-04T20:57:42Z")

</div>

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