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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bveenema/node-red-context-pubsub

v0.0.1

Published

Nodes for managing global context using pub/sub

Readme

node-red-context-pubsub

This project features publish and subscribe nodes for global context. It is especially useful for state management through global context, providing a tag browser style interface for your node-red project and aggregating your applications data and events into a local unified namespace.

This project was orignally inspired by node-red-contrib-context-pubsub but is a near complete re-write, with a different underlying pub/sub engine and providing many more features.

Note: This package should be considered in beta stage. It has been tested in nominal cases but not in production. Use with care. Expect issues

Installation

Either use the Manage Palette option in the Node-RED menu, run the following command in your Node-RED user directory, or add it to your Dockerfile

npm install --production --save @bveenema/node-red-context-pubsub

Omit the --production flag, in order to install the development dependencies for testing and coverage. Omit --save if you don't want to add it to your package.json.

Usage

Context Pub/Sub provides two simple nodes, publish-context and subscribe-context. They can be used very basically and expanded on as your application develops.

publish-context

This node stores data in Node-Reds global context. After the value is set, it triggers any subscribe-context nodes that are listening, causing them to trigger their flow.

Publish Context has the following inputs:

  • Name - Name of the node
  • Property - Name of the property to store the value in global context. Can use dot notation to update at sepecific point in global context (ex: "model.view.valveTable)
  • Action - Replace or Append
  • Value - a function to process the incoming msg object and return whatever should be published to property

IMPORTANT! In order for the subscribe-context node to work, global context must be updated using this Node! Any context updated outside this node will NOT trigger subscribing nodes, but will update global context

subscribe-context

This node listens for changes in the global context that are updated by the publish-context node. When the subscribed global context changes, the triggers a message with the following format

{
    "payload": {type: any}, // the new value - the type will be that of the subscribed value stored in global context
    "previousValue": {type: any}, // the previous value - the type will be that of the subscribed value stored in global context
    "changedPaths": {type: array}, // the full path to all the properties in the payload that changed
    "changedProperties": {type: array}, // the properties in the payload that changed
    "subscribedPattern": {type: string}, // the matched pattern of the subscriber
}

Subscribe supports

  • subscriptions of any depth (ie, publishes to model.view.valveTable will trigger subscriptions to model and model.view)
  • multiple subscriptions per node, with each subscription resulting in a separate message triggering a flow
  • dynamic subscriptions using:
    • Wildcards (model.view.*Table or model.*Valve.currentValue.value)
    • Regex (model\.[^.]*Valve\.(current|target)State\.value$ the value of either the currentState or targetState of any key ending in "Valve" in model)
    • JSONata (model.**[type="Valve"] any key in model that has a subkey "type" of value "Valve", ie - all "Valve" type objects in model)

Note: Dynamic Subscriptions use considerably more processing power than standard subscriptions. Care should be taken in their deployment

Example Flows

Several example flows are included to demonstrate different features:

  • examples/basic.json - Basic usage of set and subscribe
  • examples/deep-subscribe.json - Deep property subscriptions
  • examples/multi-subscribe.json - Multi value subscriptions
  • examples/dynamic-subscribe.json - Working with dynamic property updates
  • examples/append-publish.json - Appending to the global context instead of Replacing
  • examples/stress-test.json - A simple stress test that triggers multiple dynamic subscriptions frequently

Contribution

To setup your local development environment first clone this repository, then use a container runtime to get your node-red environment up and running.

Using Podman:

podman run -p 1880:1880 -v $(pwd):/data/node_modules/@bveenema/node-red-context-pubsub -d --name node-red-context-pubsub nodered/node-red

Or using Docker:

# For Linux/Mac:
docker run -p 1880:1880 -v "$(pwd)":/data/node_modules/@bveenema/node-red-context-pubsub -d --name node-red-context-pubsub nodered/node-red

# For Windows PowerShell:
docker run -p 1880:1880 -v ${PWD}:/data/node_modules/@bveenema/node-red-context-pubsub -d --name node-red-context-pubsub nodered/node-red

After you saved your changes to the code update the installation within the container with this command:

For Podman:

podman exec -it node-red-context-pubsub npm install /data/node_modules/@bveenema/node-red-context-pubsub/ && podman restart node-red-context-pubsub

For Docker:

# For Linux/Mac:
docker exec -it node-red-context-pubsub npm install /data/node_modules/@bveenema/node-red-context-pubsub/ && docker restart node-red-context-pubsub

# For Windows PowerShell:
docker exec -it node-red-context-pubsub npm install /data/node_modules/@bveenema/node-red-context-pubsub/; docker restart node-red-context-pubsub 

Roadmap

  • Build JSONata and Regex testing environments