Can I use c++ in node red?

I am a beginner of node-red and I want to use c++ language in node red.
I found that I can use c++ code as modules in node.js project by c++ addon
but I don't know how to utilize it with node red.
I searched online and found that there are some node-red nodes which is written in C++,
but I could not find any examples.
I wasted much time searching online, but I even don't know how to start.
Can you give me some recommendations for me?

It all depends on what you are trying to accomplish.

You can use c++ with nodejs. node-red uses nodejs for its modules (read: nodes).
So in order to use c++ in NR, you will need to create your own nodes. Did you search the flow library before you reinvent the wheel ?

1 Like

Thanks for the reply!
Actually, I found that I could use c++ by changing cc file to node file and using the node.js module named "bindings", but it takes a long step..
And I found that there is a python function node in flow library
but I couldn't find the c++ function node
so I thought I have to create a new node.
I visited the hyperlink that you mentioned and I mimicked the page and made my lower-case node.
From now on, I will read the code of python function node and I will try to make the c++ function node.
Thank you!

You cannot directly use the same approach. That is because Python is "just in time" transparently compiled upon first execution of the code and C++ uses a separate process for compilation that builds a separate executable file.

So you would have to build in the C++ compiler to the node as well so that committing a code change forced the compile to happen. You would also have to have a way of handling the executable file and all of that would need to work cross-platform. Typically, there are a lot of different dependencies on different platforms that are required in order to be able to compile C++.

Of course, the compilation step is also a slow process so you will need to make allowances for that to happen in the background with suitable information given to the Editor.

However, it would be an interesting node indeed.


Can you explain why you want to use C++? There may be other solutions if you explain exactly what you want to achieve.


Actually I was just curious about that and there was no purpose.
I am familiar with cpp and I wonder if there is any node for c++.
If I found any node for c++, I would try opencv with them.
Thank you though!

Could you not ship the node with compiled binaries?

1 Like

This might be of interest:

Extending Node.js with native C++ modules

Node.js can not only load the JavaScript libraries, but also be extended with native modules (compiled C/C++ code). While this does not mean that you should wipe out your existing JavaScript modules in favor of good ol’ C++, this knowledge might come in handy in specific use cases.

1 Like

OpenCV works excellent already with Python

Check Adrians fantastic source of example projects

1 Like

If it's opencv you are interested in getting working in node-red, you could look at using the wasm Version (opencv.js).

1 Like

Yes, of course, it was already explained that C/C++ code can be distributed with node.js packages. But that didn't appear to be the ask since the Python function node was being talked about.


My question was genuine - curious and still learning! :slight_smile: The article I linked to talks about using node-gyp to automagically build included C++ packages.


I use node-gyp when I build node file with cc file.
I also find I can do it with g++ with shared library(??) as follows.
g++ -std=c++11 --shared -fPIC -o "name".node "name".cc
I am too ignorant about English and programming to create a new node now,
but I hope someone finally make the c++ function node.. haha
Thanks a lot

The Node JS node-addon

has already been around for some time and have a solid community support behind.
I work on a framework with CMAKE and QT Creator devl. environment that take care of most of the household incl. generating the package as a node-red extension. Still a few things to get done.
I clearly sees the arguments to use C/C++ when it come the manipulating data and for so many other reasons. The guys managing the node-addon has taken a big pile of work in ensuring that your custom nodes seamlessly follows general updates in node JS and will stay functional for users.

1 Like