Problems adding external npm module

Hi all,

I'm having problems getting nodered to load after adding an external npm module.

npm install -g ansi-to-html

npm list -g

/usr/local/lib
├── ansi-to-html@0.7.2

It looks like it's installed.

I edited settings.js in my .node-red directory

functionGlobalContext: {

// os:require('os'),
ansitohtml:require('ansi-to-html'),
},

When I start nodered via systemd

Dec 12 01:07:26 bbs Node-RED[1071764]: Error loading settings file: /home/nodered/.node-red/settings.js
Dec 12 01:07:26 bbs systemd[1]: nodered.service: Main process exited, code=exited, status=1/FAILURE

So I'm not sure what I'm doing wrong. It doesn't give any good reason for why it failed.

Would appreciate some advice.

Thanks,

You have an extra comma , at the end of the line you added. Remove it.

I do. I did. It didn't fix it.

Does it remove that issue if you comment out that line and the comma on the line above?

Since that is the only line I added then yes, it works fine without it. Considering almost every other line ends in a comma, I don't think that is of any relevance in this case, however it works neither with or without it.

Actually, it works fine with the comma on the above line, since the above line is also commented out. Essentially, if I comment out the line I added then the function is empty.

for shits & grins, I removed the comment from the os:require('os'), line and it works, including the trailing comma.

So it seems to have an issue with me requiring ansi-to-html. Lacking any sort of meaningful debug message, I have no idea what the problem is.

Did I miss a step or something?

Nevermind, i got it working.

In the nodered-modules directory I did npm install --save ansi-to-html and it started right up. Ended up running it through strace and saw it was looking in the local directories so I was able to find what I needed from there,. Maybe this will help someone in the future.

For future reference, you can also avoid all this manual editing of settings.js & manual npm installation etc.

Instead, simply add modules via the UI on a function node (the setup tab). Here is an article demonstrating this.

1 Like

Now that would have been good to know. I'll maybe convert to this method.

So I tried with the solution mentioned above and I think I'm pretty close.

I removed the entry in settings.js and in the function > Setup I entered ansi-to-html and used the variable ansiToHtml.

Now, the output it changed but I just get a string of numbers.

Please refer to Ansi to ascii or html which is what I was trying to do in the first place. So I'm not sure what is going on here.

const ansitext = msg.payload;

const Converter = ansiToHtml;

const convert = new Converter();

const htmltext = convert.toHtml(ansitext);

msg.payload = htmltext;

How my payload looks like "27914910927915154109200205187...." So, again, appreciative of any assistance. I feel I'm close..

What was in msg.payload before the node?

Please refer to Ansi to ascii or html as noted above.

That text has been rendered. I need to see the real data in node-red to see if it is actual/valid Ansi escape codes.

Have you tried feeding a known sample of ANSI data?

Ah, I think that's the clue I needed.

12/12/2023, 3:28:34 PM[node: debug 12](http://endofthelinebbs.com:1880/admin/#)sbbs/EOTLBBS/node/2/output : msg.payload : buffer[11]

[ 27, 91, 48, 109, 27, 91, 50, 74, 27, 91 … ]

it's arriving as a string of ascii values rather than the characters themselves.

buffer[200][raw](http://endofthelinebbs.com:1880/admin/#)
[0 … 9]
0: 0x1b
1: 0x5b
2: 0x32
3: 0x4a
4: 0x1b
5: 0x5b
6: 0x48
7: 0x1b
8: 0x5b
9: 0x33
[10 … 19]
[20 … 29]

So I probably need to convert the ascii values to characters and then join them together in a string before passing them to the conversion routine.

You can simply call .toString() on a buffer.

As for posting data on the forum, it is far better (and actually usable) if you use the tools in the debug panel.

Canned Text:

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

.toString() did it but unfortunately the results are far from what I expected, though it did what it was supposed to. I'm probably going to have to write my own routine to handle the graphics aspect of it or I might end up using websockets via nodered rather than mqtt for this bit since it's an option.

If you post a copy of the ANSI data (using the proper "copy value" button) I will take a look. I suspect the backslashes are escaping the adjacent characters.

Also, where does the data originated from? What is sending it over MQTT - another node-red?

It may be you need to escape the backslashes before you send the data to prevent them escaping their adjacent characters.

[27,91,63,49,48,48,48,108,27,91,63,49,48,48,54,108,27,91,50,74,27,91,72,27,91,51,48,109,32,32,27,91,49,109,27,91,51,54,109,201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187,13,10,201,205,188,27,91,48,109,32,27,91,52,52,109,27,91,49,109,27,91,51,51,109,32,32,32,71,111,111,100,32,77,111,114,110,105,110,103,46,32,84,105,109,101,32,105,110,32,84,101,120,97,115,32,50,58,50,56,97,109,32,87,101,100,110,101,115,100,97,121,44,32,49,51,116,104,32,68,101,99,101,109,98,101,114,32,50,48,50,51,32,32,32,32,32,27,91,48,109,32,27,91,49,109,27,91,51,54,109,200,205,187,186,27,91,48,109,27,91,51,67,27,91,49,109,27,91,51,51,109,220,220,220,32,27,91,48,109,27,91,51,54,109,46,27,91,49,109,27,91,51,51,109,32,222,32,220,32,27,91,48,109,27,91,51,54,109,250,27,91,49,109,27,91,51,51,109,220,220,220,220,27,91,48,109,27,91,49,50,67,27,91,51,54,109,250,27,91,49,109,27,91,51,51,109,220,220,220,27,91,48,109,27,91,52,67,27,91,49,109,27,91,51,51,109,220,220,220,220,220,32,220,32,46,220,220,220,220,32,27,91,48,109,27,91,51,54,109,46,27,91,48,109,27,91,52,67,27,91,49,109,27,91,51,51,109,220,220,221,32,32,46,27,91,48,109,27,91,51,67,27,91,49,109,27,91,51,51,109,222,32,220,32,220,220,220,32,27,91,48,109,27,91,51,54,109,249,27,91,48,109,27,91,51,67,27,91,49,109,27,91,51,54,109,186,186,27,91,48,109,27,91,51,67,27,91,49,109,27,91,51,51,109,223,220,27,91,48,109,27,91,51,54,109,46,27,91,49,109,27,91,51,51,109,223,27,91,48,109,27,91,51,54,109,250,249,27,91,49,109,27,91,51,51]

This is an example of some of the data using "copy value" as noted above.

This is after it has been through toString(). I don't think it likes the graphics characters.
I'm not going to waste any more time on this. It looks like one screen can take upto 3 mqtt packets and I can't be arsed to deal with trying to know which ones belong together, put them together so that items are not split between two sets of messages. I'm including this here since you are curious. The source cannot be altered so that's a moot point.

e[?1000le[?1006le[2Je[He[30m e[1me[36m��������������������������������������������������������������������������ͻ �ͼe[0m e[44me[1me[33m Good Morning. Time in Texas 2:30am Wednesday, 13th December 2023 e[0m e[1me[36m�ͻ�e[0me[3Ce[1me[33m��� e[0me[36m.e[1me[33m � � e[0me[36m�e[1me[33m����e[0me[12Ce[36m�e[1me[33m���e[0me[4Ce[1me[33m����� � .���� e[0me[36m.e[0me[4Ce[1me[33m��� .e[0me[3Ce[1me[33m� � ��� e[0me[36m�e[0me[3Ce[1me[36m��e[0me[3Ce[1me[33m��e[0me[36m.e[1me[33m�e[0me[36m��e[1me[33m������. ��e[0me[5Ce[1me[33m.e[0me[5Ce[1me[33m���e[0me[36m�e[0me[4Ce[36m�e[1me[33m�� ��.����e[0me[36m.e[1me[33m�e[0me[36m�e[0me[4Ce[1me[33m��e[0me[36m�e[1me[33m �� e[0me[36m�e[1me[33m������e[0me[36m.e[1me[33m�e[0me[36m�e[0me[3Ce[1me[36m��e[0me[3Ce[1me[33m���.��������e[0me[36m�e[1me[33m ���e[0me[5Ce[1me[33m���� ��.e[0me[6Ce[1me[33m��e[0me[36m.e[1me[33m.��������.�e[0me[4Ce[1me[33m��. ��e[0me[36m�e[1me[33m��������.�e[0me[3Ce[1me[36m��e[0me[3Ce[1me[33m������������e[0me[36m.e[1me[33m ��e[0me[5Ce[1me[...

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