When I make a function call to use any “net” features in node red, i get an instant error when I try to deploy. The error I am encountering when trying to use the ‘net’ module in Node-RED 3.0.2 running on Node.js v14.20.0 on an Opto22 groov EPIC controller is likely not due to the absence of the ‘net’ module itself. The ‘net’ module is a core part of Node.js v14.20.0. Is this a limitation placed on the opto22 3.0.2 node red app or glitch, and I need to redownload the firmware?
This eror checker always returns : the node error.
// Access the net module from the global context
const net = global.get(‘net’);
if (!net) {
node.error(“Unable to access the ‘net’ module. Please check your Node-RED configuration.”);
return null;
}
// Get or initialize server and connections from global context
let server = global.get(‘tcpServer’);
let connections = global.get(‘tcpConnections’) || ;
Can you link us to the flows.nodered.org ‘net’ module. When I do a search there I get a zillion results.
It might be the nodejs version we are currently running, but if you were able to install it without error, I doubt that is the core issue.
What firmware version is your EPIC currently running?
But yeah, link us with the node in question and we will take a look.
Restore Version
3.5.1-b.85
This is the default version that will become active after a Restore to Defaults operation.
Minimum Firmware Version
3.0.0
I guess the key is how v3.0.2 in the Epic is set up. Node.js was released in 2009, and the ‘net’ module, being fundamental for network operations, was likely included from the very beginning or in one of the earliest versions. The ‘net’ module provides an asynchronous network API for creating stream-based TCP servers and clients, which aligns with Node.js’s primary use case of building network programs such as web servers.
Since that’s the main function of node red I think it probably has always been there, it seem stight forward but is it possible my function call is bad? the only other possibility I see is its use is limited in the Epic OS.
I am just using the standard node red palette in V3.0.2 but its all functions.
here what perplexity had to say:
Relation to Net Nodes
The net module in Node.js is a core library that provides an asynchronous network API for creating stream-based TCP or IPC servers and clients. However, simply accessing it via global.get('net') assumes that you have previously stored it in the global context, which is not typical unless explicitly configured.
Setting Up the Net Module in Node-RED
To use the net module in Node-RED, you need to make it available in the global context through the functionGlobalContext property in your settings.js file. Here’s how you can do that:
Edit settings.js:
Open your Node-RED settings file (usually located at ~/.node-red/settings.js) and add the following line under functionGlobalContext:
javascript
functionGlobalContext: {
net: require('net'), // Make the net module available globally
// other global variables can be added here
},
so it would seem I would need to get an SSH liscence so I can add that to my node red functionGlobalContext ?
Could you share a screenshot of what you are trying to do?
We have thousands of customers using the built in nodes, we even teach API calls using http and https built in networking nodes in class, all with zero issues or needing shell.
Flow and global context have nothing to do with networking, so I am unsure of the tie up there.
If you can help us understand your task, I suspect we will be able to give some better pointers than a perplexed perplexity app < grin >
EDIT: Re-reading this thread again, I’d like to clarify this:
The Node-RED installed on EPIC is pure, we don’t customize it or limit it in anyway.
It is just behind the groov Manage authentication server (so you need to use your groov account to log into the editor or Node-RED dashboard).
I suspect you can do better than an ai search too, so what I have is a TCP server that is not using http it is on a multipoint network with 3 windows computers( remote control panels) controlling a TTL based system from the 1970s. I need a server that can manage the TCP port better than the TCS server that is already built ( and I am using in the “current Flow” pict.) So when I call the global.get (‘net’) I get a return that ‘net’ is not access is not available.
some code:
// Get or initialize server and connections from global context
let server = global.get(‘tcpServer’);
let connections = global.get(‘tcpConnections’) || ;
function startServer() {
if (server) return; // Server already running
server = net.createServer((socket) => {
node.warn('Client connected');
connections.push(socket);
global.set('tcpConnections', connections);
The get(s) for tcpServer and tcpConnections work but when I try to go to net.createServer((socket) none of that works. (verifying no access…I am thinking anyway) So on various internet searches I find (or am told) that the node red configuration can block access to the net level access i am looking for to control the sockets (and monitor) the way I want. If there is another method to do this that would be helpful.
Ahhhh. Ok, NOW we have a much better picture of what you are doing with the ‘net’ stuff.
Thanks for the details.
Going to page @torchard and he and I will do some whiteboard skunkworks stuff and see what ideas we come up with.
One question. Sounds like the '70s stuff will have a fixed port number? Any idea what it is?
Im wondering if its less than 1024 and so will require sudo / shell access to open a port on the EPIC down that low.
Not to mention that we cant run Node-RED as root, so even if we get the ‘net’ stuff working, it wont listen below port 1024, so all this might be a moot exercise…
EDIT: I see a port 9103 in the top screenshot… is this the TCP port you need to use?
Not totally locked into port 9103 but also have a flow in this same project sending udp out over port 9101, and the windows code migration would be easier (i think) if I stick with those ports. Let me know what you come up with… also if changing ports is helpful for this I’ll give it a shot.
It is built to just listen for non-http(s) TCP connections and either stream what comes in out to the flow, or to pass on single strings, base64 encoded data or a buffer.
That is where I started, the issue with using it is I have no visibility into how it corrects for errors and if the socket termination hangs or really any port error occurs, I can’t reset the port. I am aware I can shell and restart node red to clear any hanging ports, but that’s a little low on my acceptability scale. (right now)
I am using the UDP out node that just blasts UDP, but since it isn’t reliant on windows TCP connect/disconnect (just the Epic Os) I don’t think I’ll need much control or monitoring of that widget.
Also I did shell into node red and modify the → :functionGlobalContext: {
net: require(‘net’), // Make the net module available globally other global variables can be added here }, I still got the error when I use any dot net function call, so don’t to know where that puts me.
Did you restart Node-RED after making the change?
settings.js are only read the one time on startup.
Did you try using a catch node with the TCP node to catch any errors it produces?
Also, I totally agree with you on avoiding hacky work arounds when the port locks up, but if it moves you forward in your testing… Restart NodeRED After PAC Control Download
I did restart node red after the change, and I have a catch node monitoring the server and writing to a text file, but I didnt think about testing various server problems and seeing what the catch might tell me. I like the idea and will test it out. Ill let you know what happens. Thanks