Node.warn( ) help

#1

Ok,

node.warn("message" + variable_name);

A line of text in the debug window to the right.
Not wanting to be difficult, but can I send multiple lines of text from one message?

Say I want to send: (Literally)


** information as requested **


with ONE node.warn( ) line.

Can it be done?

Just I am finding that with NR's async' operation sometimes consecutive node.warn( ) messages are not.

Just asking.

0 Likes

#2

I always start my node.warn's with an identifier so the first would be:
node.warn("DBG01: message" + variable_name);
and the second:
node.warn("DBG02: message" + variable_name);
however if you want something like:

=============
dbg01 testing
=============

then add a '\n' where you want the breaks like this:

var dbg = '=============\n';
dbg = dbg + 'dbg01 testing\n';
dbg =dbg + '=============\n';
1 Like

#3

Thanks.

Sorry it was a bad example.

I didn't know the line of *'s would be ....... changed.

So trying to get my head around what you said:
I want:
(This time I'll use a different symbol)

xxxxxxxxxxxxxxxxxxxxxxxx
xx TITLE : (var name)
xxxxxxxxxxxxxxxxxxxxxxxx

I'm reading it to be written as:

var y = 'xxxxxxxxxxxxxxxxxxxx\n';
var x = y + "  Title : " + variable name\n;
x = y;

I tried a bit of "sneaky stuff" there to save repeating putting in the line of x's.

Am I getting the hang of it?

0 Likes

#4

So what is the result if you try that?

0 Likes

#5

I am just now sitting down with a text editor going through the flows trying to reconsile (?) what is the problem with the flows which are working on one machine and not on another.

I'll try it shortly.

Unexpected symbol line 3 at the \n at the end of the variable_name\n; part.

var variable_name = "test";
var y = 'xxxxxxxxxxxxxxxxxxxx\n';
var x = y + "  Title : " + variable_name\n;
x = y;
return msg;
0 Likes

#6

In line 3, the \n should be added onto the end of the line surrounded by quote marks

In line 4, your resetting x back to the value of y - so line 3 will have no effect

In line 5, you are returning the msg but since you haven't altered the msg.payload so it will just return the original msg

0 Likes

#7

I also forgot to declare it was a node.warn( ) that I was doing.

This is the code I "resolved" from the first reply:

var variable_name = "test";
var y = 'xxxxxxxxxxxxxxxxxxxx\n';
var x = y + "  Title : " + variable_name+'\n';
x = x + y;
node.warn(x);
return msg;

Forgetting the message and just looking at the node.warn( ) part.

It works - kinda.
But all I get is:

Not quite 3 lines as originally mentioned.

Sorry. This is way out of my skill set. Syntax with " ' ` and other such things has illuded (?) me for ever.

0 Likes

#8

And what happens it you press the triangle in the warn sidebar?

0 Likes

#9

ARGH!

Sorry.

I thought I did it. Mia Culpa.

Now I am having fun with a function node with 4 outputs and working out if I always have to send 4 outputs, or if I can send any combination of.......

0 Likes

#10

This should be the clue you need.
https://nodered.org/docs/writing-functions#multiple-outputs

0 Likes

#11

'Eluded'.

The following will take you through the basics:

https://www.w3schools.com/js/js_strings.asp

In JavaScript, single and double quotes are really the same, chose one and stick with it until you need to do something odd like trying to nest a set of quotes within a string.

back-ticks (Template literals) are very different and only work in newer versions of nodejs and newer browsers. You can do all sorts of clever things with them such as multi-line strings and embedded JavaScript code. Avoid until you've mastered the basics. Still avoid unless you know that you are only working with newer environments. Still avoid until you hit a problem with normal quotes that you can't fix without lots of code. :slight_smile:

0 Likes