New node property and validation

Hi,
What is the right way to add new property to configuration node (in case node exists in production systems)? I've put my new property in defaults section, for example like this below:

reconnectPeriod: {value: 1000, validate: (val) => val > 0 }

When I start new NR I see my nodes has a red triangle, which indicate invalid value in config node I guess. And if I open the config node I see the value is empty.
I have tried init this property on few ways but without luck. Any suggestions?

Hi @Onixarts,

I have described here some time ago some stuff you can do when adding new properties to existing nodes. Hopefully it can help you...

Bart

I'm doing it in almost the same way, but I wonder if there is a proper solution for that, that I don't know. Thanks, I'm going to put that code in my node :).

Hey @Onixarts,
If you ever find a simpler (more elegant) solution, don't hesitate to share your solution :wink:

Hi @BartButenaers. I read your post (Upgrading Nodes specifically my own) and seen from the screen shots you are debugging the onEditPrepare . How do you achieve this? I can never find the script from my .html in chrome debugger!?!
I guess it has something to do with downloading and running node red from source instead of npm install (minified)?

Hi Steve (@Steve-Mcl),
Indeed you cannot find that code anywhere, even not by searching for specific keywords using the 'Search' panel in the developer tools. Other people on this forum will be able to explain you why that happens. I 'assume' your code is somehow build into the .min.js file together with all other code, and it is minified (so functions and variables are renamed so you cannot search them). But I might be mistaken ...

I just add a hardcoded debugger; statement in my code. When you have your developer tools open, you will arrive at that breakpoint automatically (with normal not-minified code). Don't forget to remove that statement afterwards! Because it is very annoying when developers are debugging their code, and they arrive all the time at your breakpoint. Users that don't have their developer tool window open, won't notice that you have forgotten to remove your debugger statement...

[EDIT] If I'm not mistaken it is enough to add such a debugger statement in your oneditprepare function. As soon as you double click a node, the debugger will stop there. At that moment you can add normal breakpoints in your developer tools in the other functions of your html file. So I don't think you have to put such debugger statements all over the place, because I think ALL the code from your html file will become visible at that moment. But again I can be mistaken ...

Bart

You can debug node-red nodes easily with vscode. Just add new debug configuration, select node.js: attach to process and that's it. You can attach in any time with vscode debugger and debug whole code, including Yours :slight_smile:

@Onixarts: we are a 'bit' off-topic, but do you know a good tutorial for setting up VsCode from scratch for Node-RED? I assume you use it to debug both for server and client side?

Well, I'm debugging only nodes (server side). In frontend I'm using firefox dev tools. Just google for "vscode nodered debug" and choose one of the first 5 results :).

It's very simple:

  • just click on debuger mode in vscode,
  • then click add configuration on top
  • the json configuration file shows up, click again Add configuration button in the bottom of the page
  • the list shows up, choose {} Node.js Attach to process, it adds few lines to the config file
  • save file and You're ready to debug

After run node-red in the console, in vscode select Attach to process command from combobox in the top of debug panel, then the nodejs process apear, confirm by hiting enter. In Node-red console You will see "Debuger attached" message. Then if your module hit a breakpoint You will be able to runing code step by step, check variables, objects etc.

1 Like
2 Likes