Skip to content

NR5: Type definitions for Nodes #5535

Open

Description

@knolleary

This is a long running topic of discussion that has never quite bridged the chasm to getting an issue raised to start solidifying plans around it.

It is also a topic that gets interpreted in many different ways. The goal here is to have a well-defined scope and purpose. There are some short-term requirements, some long-term aspirations and a whole load of things in between. We aren't going to solve everything in one go.

The goal here is to have a mechanism for nodes to declare type information in a standard way.

This covers:

  • node configuration properties
  • inbound message properties
  • outbound message properties

There are lots of potential use-cases for the typings, and whilst I list some examples here, I want to be as clear as possible that they are for future consideration and we're not proposing to implement them at this stage. I'm listing them here to help inform how the types could be used - and that may influence choices made

  • Automatic validation of flow files. Currently we can validate the basic structure of a flow, but we cannot validate a node configuration as we don't know what it should look like.
  • Automatic generation of edit dialog. For many nodes, the edit form has a direct correlation to its properties. It should be possible to generate the edit form from the type definition. Of course there are plenty of edge cases, and it only really works for simple configs, but its something to keep in mind
  • Runtime validation of flows.
  • UI tooling to help map message properties between nodes without having to use debug to examine messages
  • AI-driven flow generation

Each of these use cases has its own pros/cons and being in that list doesn't mean we'll do them. This issue is not intended to be a discussion of their individual merits, as much as you might like to comment on them.

Types cannot be mandatory as we have 5000+ existing nodes that don't have type information. But, over time, the types should bring sufficient benefit to end-users that node authors are inclined to include them.

Scope

  • The goal for NR 5.0 will be to have a documented method for how nodes can provide type information.
  • The core Node-RED nodes should be updated to include type information.
  • No runtime/editor functional changes related to the typings

Format of the typings

There are two possible formats. JSONSchema, or TypeScript style definitions. My instinct is the JSONSchema route, but will need to evaluate what makes most sense. I like JSON as its a well defined blob that can be transported easily. A TypeScript file is free form text and makes me twitch.

It's conceivable that some use cases may require a bit more meta-data (eg, hints on UI generation). We may need to be a little custom - as long as we have a schema to validate the schema...

Location of typings

There are three different places the typings could be consumed; editor, runtime and through static analysis without running anything. This third category is an interesting lesson to learn from the Flow Library; working out meta-data about a node from an npm package is quite hard to do as it's all done in code.

My starting point for this will be to look for a type file that sits alongside the node.js/html files. Need to pick a suitable filename format that aligns with the format of the typings and other conventions.

Activity

  1. added this to the 5.0 milestone on Mar 6, 2026
  2. self-assigned this
    on Mar 6, 2026
  3. added theissue type on Mar 6, 2026
  4. dceejay commented on Mar 6, 2026

    @dceejay
    Member

    re - a suitable filename format - see old discussion here https://stackoverflow.com/questions/9391370/json-schema-file-extension - so maybe node_name.schema.json

  5. knolleary commented on Mar 17, 2026

    @knolleary
    MemberAuthor

    This is very much a work in progress but this is where my proposal for this is heading: https://gist.github.com/knolleary/72fa793cf8e6768e44c43093bf711385

  6. AllanOricil commented on Mar 18, 2026

    @AllanOricil
    Contributor

    As a node author, I want to avoid maintaining a separate metadata file to define input/output schemas. In practice, that approach tends to drift from the actual implementation over time.

    We’ve seen a similar pattern play out in the ecosystem—for example, the shift from Prisma ORM to Drizzle ORM. One of the reasons Drizzle gained traction is that it keeps the schema definition closer to the code, reducing the risk of divergence. When the source of truth lives outside the runtime logic, inconsistency becomes almost inevitable.

    The model I’m proposing keeps the source of truth entirely in code. It’s fully typed, doesn’t require any changes to the Node-RED core, and allows packages to be distributed with schemas covering inputs, outputs, credentials, configs, and settings.

    Repo: https://github.com/AllanOricil/node-red-vue-template/tree/wip_ts

    Using TypeBox, typed JSON Schemas can be generated at build time and exported for external consumption. This also enables downstream use cases—like searchable catalogs of nodes and flows—without introducing duplication. TypeBox even supports defining schemas in a more declarative/plain-text style when needed.

    I’ve been working on this since late 2023, and it’s reached a level of maturity where I genuinely believe it’s worth your time to review.

    There’s a concrete effort behind it to solve a real problem—schema drift and fragmentation—and the approach is already implemented, not just theoretical. I’m confident it can add value to the ecosystem, or at the very least spark a useful discussion about direction.

    If you’re open to it, I’d really appreciate a focused review or even high-level feedback on whether this aligns with where you see things going.

  7. knolleary commented on Mar 18, 2026

    @knolleary
    MemberAuthor

    Full Disclosure: Allan originally posted this comment on the gist where I provided the reply below. Earlier today I decided to avoid having the discussion fragment, so disabled comments on the gist, which appears to have hidden the comment rather than just prevent addition comments being added.

    @AllanOricil I have said repeatedly, the goal here is to find a core approach that does not require nodes to be completely rewritten in some framework or other - otherwise it has little chance of adoption. It does not prevent someone using a framework if they want; as you say, the JSON could be generated. But we want to get this core right first.

    Reviewing your entire framework is not a small task as it covers so many things. It is also very opinionated in its approach and I don't know how receptive you'll be to feedback. The topic of this issue is the core schema work; so not going to get into a discussion about your framework.

  8. moved this to In Progress in 🛠 Developmenton Mar 19, 2026
  9. AllanOricil commented on Apr 30, 2026

    @AllanOricil
    Contributor

    Anybody has anything to say about @bonsae/nrg APIs? I'm almost done with the wiring contracts at deploy time, then will check if I can expose it to the client

  10. Robbilie commented on Jun 9, 2026

    @Robbilie

    I'll dig a little deeper into this but just using Json schema and something like (react) json schema form is something I can get behind (because I am using that in some other projects :P)
    We also did write down some core node schemas for validation on a proprietary backend endpoint so this just feels natural to me.

  11. HenryTJr commented on Jul 8, 2026

    @HenryTJr

    You should write nodes using @bonsae/nrg and its test libraries. The author is a genius. He improved the API without changing anything in the core, and even discovered new generalizations that make flows authored with nrg nodes way smaller and continuous, therefore eliminating "spagethi teleportation" issues that currently happen due to the exaggerated use of Catch and Complete nodes.

    https://bonsaedev.github.io/nrg/guide/why-nrg.html

    import { IONode, type Infer, type Port } from "@bonsae/nrg/server";
    import { Readable } from "node:stream";
    import { ConfigsSchema, RequestSchema } from "@/schemas/http-request";
    
    type Config = Infer<typeof ConfigsSchema>;
    type Input = Infer<typeof RequestSchema>; // ← input type inferred from a schema
    type Output = {
      body: Port<Readable>; // ← named port, non-data, no schema
      failed: Port<{ status: number; message: string }>;
    };
    
    export default class HttpRequest extends IONode<Config, never, Input, Output> {
      static override readonly type = "http-request";
      static override readonly configSchema = ConfigsSchema;
    
      override async input(msg: Input) {
        const res = await fetch(`${this.config.baseUrl}${msg.path}`);
        if (!res.ok) {
          this.sendToPort("failed", { status: res.status, message: res.statusText });
          return;
        }
        this.sendToPort("body", Readable.fromWeb(res.body!)); // the stream, not its bytes
      }
    }

    And the icon is so well constructed with several meanings

    Image
  12. knolleary commented on Jul 8, 2026

    @knolleary
    MemberAuthor

    @HenryTJr Allan, please do not spam our issues. My response from March 18th still stands.

  13. HenryTJr commented on Jul 8, 2026

    @HenryTJr

    @knolleary just look at this API. It is pure genius. He was also able to make node instances process messages non blocking!!! What a freaking genius

    import { IONode, type Port } from "@bonsae/nrg/server";
    import { ConfigsSchema, type Config } from "@/schemas/router";
    
    type Success = { ok: true; id: string };
    type Failure = { reason: string };
    type Output = { success: Port<Success>; failure: Port<Failure> };
    
    export default class Router extends IONode<Config, any, Input, Output> {
      static override readonly type = "router";
      static override readonly configSchema = ConfigsSchema;
    
      override async input(msg: Input) {
        try {
          const result = await process(msg);
          this.sendToPort("success", { ok: true, id: result.id });
        } catch (err) {
          this.sendToPort("failure", { reason: String(err) });
        }
      }
    }
  14. knolleary commented on Jul 8, 2026

    @knolleary
    MemberAuthor

    @HenryTJr Allan you are spamming this thread with off-topic comments. Please stop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions