npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nrutils/node-red-utils

v0.4.0

Published

Mixin toolkit for authors of Node-RED custom nodes: editor messaging, worker threads, popups, singletons, resource serving, pub/sub and optional GPU compute.

Readme

node-red-utils

npm

A toolkit for Node-RED custom nodes: worker threads, GPU compute, messages between the editor and the runtime, pub/sub between nodes, editor resources, a popup and singleton nodes.

  • NodeRedNodeBase: builds a node from a setup function and a list of mixins. A mixin is one feature; you add it by listing it.
  • nodeRedWorker: runs node code in a worker thread. Wired worker nodes talk thread to thread, the same as the wires in the flow.
  • nodeRedGpu (experimental): Vulkan compute kernels in worker threads, with a CPU fallback.
  • nodeRedEditorComms: messages between the runtime node and the same node in the editor.
  • nodeRedPubsubBus: pub/sub for data that nodes share without wires.
  • nodeRedConnection: opens, closes and reconnects a client connection (TCP, MQTT, Modbus) while nodes hold it.
  • nodeRedResourceEndpoint: serves scripts, styles and images to the editor.
  • nodeRedPopup (experimental): a resizable panel that opens when you click the node in the editor.
  • nodeRedSingleton (experimental): allows only one node of a type in the editor.

Install

In your node package:

npm install @nrutils/node-red-utils

Works with Node-RED 4 and Node.js 18 or later.

Building with AI

Use an AI coding assistant to build nodes! Here's some AI dreamed up paste-ready prompts. Not particularly useful nodes though.

Example: a counter node

A node that counts messages, shows the count as its status, and resets the count when you click its button in the editor.

counter.js:

const { NodeRedNodeBase, nodeRedEditorComms } = require('@nrutils/node-red-utils');

module.exports = NodeRedNodeBase.createNode('counter', [nodeRedEditorComms], (RED, thisNode, config) => {
    let count = 0;
    const show = () => thisNode.status({ text: `${count} messages` });

    // Sent by the button in counter.html
    thisNode.nodeRedEditorComms.subscribe('reset', () => {
        count = 0;
        show();
    });

    thisNode.on('input', (msg, send, done) => {
        count++;
        show();
        send(msg);
        done();
    });
});

counter.html:

<script type="text/javascript" src="node-red-resourceendpoint/node-red-editorcomms/EditorCommsFrontend.js"></script>

<script type="text/javascript">
    RED.nodes.registerType('counter', {
        category: 'function',
        color: '#a6bbcf',
        defaults: { name: { value: '' } },
        inputs: 1,
        outputs: 1,
        icon: 'function.svg',
        label: function () { return this.name || 'counter'; },
        button: {
            onclick: function () {
                this.nodeRedEditorComms.publish('reset', {})
                    .catch((err) => RED.notify(err.status === 404 ? 'Deploy the node first' : err.message, 'warning'));
            }
        }
    });
</script>

<script type="text/html" data-template-name="counter">
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
</script>

The first <script> line loads the editor side of nodeRedEditorComms. Copy this line exactly. The library serves the file; there is nothing to install.

Example: a worker node

A node that hashes each payload in a worker thread, so the Node-RED event loop does not wait.

hash-node.js:

const path = require('path');
const { NodeRedNodeBase, nodeRedWorker } = require('@nrutils/node-red-utils');

module.exports = NodeRedNodeBase.createNode('hash-node', [nodeRedWorker], (RED, thisNode, config) => {
    const worker = thisNode.nodeRedWorker.init(path.join(__dirname, 'hash-worker.js'), { rounds: 1000 });

    thisNode.on('input', (msg, send, done) => {
        worker.request('hash', String(msg.payload)).then((digest) => {
            msg.payload = digest;
            send(msg);
            done();
        }, done);
    });
});

hash-worker.js:

const crypto = require('crypto');

module.exports = function (worker, data) {
    worker.handle('hash', (text) => {
        let digest = text;
        for (let i = 0; i < data.rounds; i++) digest = crypto.createHash('sha256').update(digest).digest('hex');
        return digest;
    });
};

package.json

{
  "name": "node-red-contrib-counter",
  "version": "0.1.0",
  "keywords": ["node-red"],
  "node-red": {
    "version": ">=4.0.0",
    "nodes": { "counter": "counter.js" }
  },
  "dependencies": { "@nrutils/node-red-utils": "^0.1.0" }
}
  • The .html file sits next to the .js file and has the same base name.
  • The type string in the HTML registerType equals the type in createNode.
  • Put the library under dependencies, not devDependencies.

To load your node package into Node-RED on your own computer, run cd ~/.node-red && npm install /path/to/your-package, then restart Node-RED.

Reference

Put the features you want in the array of createNode; they apply in that order, then setup(RED, thisNode, config) runs.

| Mixin | What it adds on thisNode | Editor script <script src=...> line | | --- | --- | --- | | nodeRedWorker | nodeRedWorker; call init() to start the worker | none | | nodeRedGpu | nothing; the GPU API is in the worker, from nodeRedGpuWorker() | none | | nodeRedEditorComms | nodeRedEditorComms | node-red-resourceendpoint/node-red-editorcomms/EditorCommsFrontend.js | | nodeRedPubsubBus | nodeRedPubsubBus | none | | nodeRedConnection | nodeRedConnection; call manage() to get the connection | none | | nodeRedResourceEndpoint | nodeRedResourceEndpoint | none | | nodeRedPopup | nothing | node-red-resourceendpoint/node-red-popup/NodeRedPopupFrontend.js | | nodeRedSingleton | nothing | node-red-resourceendpoint/node-red-singleton/NodeRedSingletonFrontend.js |

A mixin with an editor script must be in the array, or the script answers 404.

Exports: NodeRedNodeBase and the lowercase mixins above, plus:

  • getBus(): the pub/sub bus of the process, for code that is not a node.
  • NodeRedResourceEndpoint: serves files without a node instance; new NodeRedResourceEndpoint(RED).registerResources(nodeType, paths).

To write your own mixin, see node-red-base.

Examples

examples/basic-examples has one small node package for each feature. Install one with cd ~/.node-red && npm install --install-links /path/to/node-red-utils/examples/basic-examples/<name>, then restart Node-RED.

Troubleshooting

  • The editor script gets a 404 (for example node-red-resourceendpoint/node-red-editorcomms/EditorCommsFrontend.js, in the browser's network tab): the mixin is not in the createNode array of a node type that Node-RED loaded, or the src of the <script> tag starts with /. Restart Node-RED after you install or change a node package.

Contributing

Issues and pull requests are welcome on GitHub. Run npm test before you send a pull request.

License

Apache-2.0

Sponsor this project