Skip to Content
AppTemplateCustom Nodes

Custom Nodes

Custom Nodes erweitern Node-RED um eigene Funktionalität. Im AppTemplate wird gezeigt, wie ein Node über External Tasks mit der ProcessCube® Engine kommuniziert.

Aufbau eines Custom Nodes

Ein Custom Node besteht aus zwei Dateien:

DateiBeschreibung
JavaScript (.js)Backend-Logik des Nodes
HTML (.html)Editor-Oberfläche in Node-RED

Beispiel: Hello Node

JavaScript-Datei (hello.js)

module.exports = function(RED) { function HelloNode(config) { RED.nodes.createNode(this, config); const node = this; node.on('input', function(msg) { const greeting = config.greeting || 'Hello'; msg.payload = `${greeting}, ${msg.payload}!`; node.send(msg); }); } RED.nodes.registerType("hello", HelloNode); }

HTML-Datei (hello.html)

Die HTML-Datei definiert drei Bereiche:

  1. Node-Registrierung — Kategorie, Farbe, Ein-/Ausgänge und Eigenschaften
  2. Edit-Dialog — Formularfelder für die Konfiguration
  3. Hilfetext — Dokumentation im Node-RED Editor
<script type="text/javascript"> RED.nodes.registerType('hello', { category: 'MyProject', color: '#f7a823', defaults: { name: { value: "" }, greeting: { value: "Hello", required: true } }, inputs: 1, outputs: 1, label: function() { return this.name || "hello"; } }); </script> <script type="text/html" data-template-name="hello"> <div class="form-row"> <label for="node-input-greeting">Begruessung</label> <input type="text" id="node-input-greeting" placeholder="Hello"> </div> </script> <script type="text/html" data-help-name="hello"> <p>Fuegt eine Begruessung zur Nachricht hinzu.</p> </script>

Registrierung in package.json

Damit Node-RED den Node findet, muss er in der package.json registriert werden:

{ "node-red": { "nodes": { "hello": "nodes/sample_node/hello.js" } } }

Verzeichnisstruktur

apps/lowcode/src/ ├── nodes/ │ ├── sample_node/ │ │ ├── hello.js # Backend: Node-Logik │ │ └── hello.html # Editor: Konfiguration │ ├── form_context/ │ │ └── form_context.js # Formular-Kontext-Node │ └── aplugin/ │ └── sample_plugin.js # Plugin (siehe Plugins) ├── package.json # Node-Registrierung └── custom_settings.js # Node-RED Einstellungen

Integration mit External Tasks

Custom Nodes können über External Tasks mit der Engine kommunizieren. Der Node registriert sich als External Task Worker und wartet auf Tasks eines bestimmten Topics.

Mehr dazu unter External Tasks (LowCode).

Nächste Schritte

  • UI-Widgets — Dashboard-2 Widgets mit Vue.js entwickeln
  • External Tasks — Engine-Integration über External Tasks
  • Debugging — Breakpoints in Custom Nodes setzen