# ReferenceError: Worker is not defined

**URL:** <https://discourse.nodered.org/t/referenceerror-worker-is-not-defined/72769>\
**Category:** Developing Nodes\
**Created:** [27 December 2022 13:34 UTC](https://discourse.nodered.org/t/referenceerror-worker-is-not-defined/72769 "2022-12-27T13:34:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dudest](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dudest/32/72328_2.png) [@dudest](https://discourse.nodered.org/u/dudest)\
**Post date:** [27 December 2022 13:34 UTC](https://discourse.nodered.org/t/referenceerror-worker-is-not-defined/72769/1 "2022-12-27T13:34:50Z")

</div>

Hello,

I'm trying to improve feedback parsing from a device I'm trying to communicate with. I've opened a client connection to the device and the .on('data', _callback()_) event handler can't process all the feedback fast enough and some of it gets dropped.

To fix this I'm experimenting with _web worker_ but I get a reference error. I've tried:

```auto
const worker = new Worker('bss_rx_worker.js');

```

```auto
const worker = new Worker('/bss_rx_worker.js');

```

```auto
const worker = new Worker('./bss_rx_worker.js');

```

Node-RED version: v3.0.2  
Node.js version: v18.12.1

Any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [27 December 2022 13:40 UTC](https://discourse.nodered.org/t/referenceerror-worker-is-not-defined/72769/2 "2022-12-27T13:40:50Z")

</div>

Where are you trying to run this code? In the editor or runtime?

If this is in the runtime, have you imported the worker\_threads module as described in the node.js docs? [Worker threads | Node.js v16.19.0 Documentation](https://nodejs.org/docs/latest-v16.x/api/worker_threads.html)

---

<div class="post-metadata">

**Author:** ![dudest](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dudest/32/72328_2.png) [@dudest](https://discourse.nodered.org/u/dudest)\
**Post date:** [27 December 2022 13:46 UTC](https://discourse.nodered.org/t/referenceerror-worker-is-not-defined/72769/3 "2022-12-27T13:46:09Z")

</div>

I'm running it in a custom node package I'm writing to communicate with a BSS Soundweb. I have not imported the worker\_threads module. I will try that. Thanks!

---

<div class="post-metadata">

**Author:** ![dudest](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dudest/32/72328_2.png) [@dudest](https://discourse.nodered.org/u/dudest)\
**Post date:** [27 December 2022 19:52 UTC](https://discourse.nodered.org/t/referenceerror-worker-is-not-defined/72769/4 "2022-12-27T19:52:49Z")

</div>

Hey Knolleary,

Turns out I didn't need multithreading after all. After much gnashing of teeth I determined the issue wasn't the device sending rapid fire feedback faster than the node could parse but sending it all in one giant buffer that needed to be segmented in order for parsing.

If the device was trying to send the state of several gain faders, I'm receiving all of the feedback in one big buffer. this works:

```auto
        this.socket.on('data', function(data) {
            let rxBuf = [];

            for (let i = 0; i < data.length; i++) {
                if (data[i] == 0x03) {
                    rxBuf.push(data[i]);

                    let rx = node.bssLib.decapsulateCommand(Buffer.from(rxBuf));
                    
                    if (rx) {
                        let temp = {
                            cmd_id: "",
                            address: "",
                            data: ""
                        }
                        temp.cmd_id = node.bssLib.getCommandIdBuffer(rx);
                        temp.address = node.bssLib.getAddressBuffer(rx);
                        temp.data = node.bssLib.getDataBuffer(rx);
                        node.emit('rxData', temp);
                    }

                    rxBuf = [];
                }
                else {
                    rxBuf.push(data[i]);
                }
            }
        });

```

package is now published! 😀  
[node-red-contrib-soundweb (node) - Node-RED (nodered.org)](https://flows.nodered.org/node/node-red-contrib-soundweb)

---

<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:** [10 January 2023 19:53 UTC](https://discourse.nodered.org/t/referenceerror-worker-is-not-defined/72769/5 "2023-01-10T19:53:05Z")

</div>

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