# Problems adding external npm module

**URL:** https://discourse.nodered.org/t/problems-adding-external-npm-module/83622
**Category:** General
**Created:** [12 December 2023 07:09 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622 "2023-12-12T07:09:25Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [12 December 2023 07:09 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/1 "2023-12-12T07:09:25Z")

</div>

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,

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [12 December 2023 07:14 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/2 "2023-12-12T07:14:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [12 December 2023 07:17 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/3 "2023-12-12T07:17:17Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 December 2023 07:40 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/4 "2023-12-12T07:40:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [12 December 2023 07:47 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/5 "2023-12-12T07:47:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [12 December 2023 07:50 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/6 "2023-12-12T07:50:09Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [12 December 2023 07:59 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/7 "2023-12-12T07:59:34Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [12 December 2023 08:17 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/8 "2023-12-12T08:17:48Z")

</div>

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](https://flowfuse.com/blog/2023/06/import-modules/) is an article demonstrating this.

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [12 December 2023 16:08 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/9 "2023-12-12T16:08:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [12 December 2023 21:03 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/10 "2023-12-12T21:03:41Z")

</div>

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](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364) which is what I was trying to do in the first place. So I'm not sure what is going on here.

```auto
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..

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [12 December 2023 21:12 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/11 "2023-12-12T21:12:08Z")

</div>

> [@nelgin](#):
>
> `msg.payload`

What was in `msg.payload` before the node?

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [12 December 2023 21:19 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/12 "2023-12-12T21:19:12Z")

</div>

> [@nelgin](#):
>
> Please refer to [Ansi to ascii or html](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364)

Please refer to [Ansi to ascii or html](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364) as noted above.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [12 December 2023 21:23 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/13 "2023-12-12T21:23:55Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [12 December 2023 21:36 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/14 "2023-12-12T21:36:06Z")

</div>

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

```auto
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.

```auto
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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [12 December 2023 21:40 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/15 "2023-12-12T21:40:39Z")

</div>

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](https://nodered.org/docs/user-guide/messages)) 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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [13 December 2023 07:51 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/16 "2023-12-13T07:51:39Z")

</div>

.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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [13 December 2023 08:04 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/17 "2023-12-13T08:04:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)
#### Post date: [13 December 2023 08:38 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/18 "2023-12-13T08:38:05Z")

</div>

```auto
[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[...`

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [11 February 2024 08:39 UTC](https://discourse.nodered.org/t/problems-adding-external-npm-module/83622/19 "2024-02-11T08:39:01Z")

</div>

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