Function

Executes a JavaScript function on the payload data that the node receives from the previous node.

Use

This node executes a JavaScript function and returns the output in the msg.payload. You can create conditional output, or multiple outputs in an array.

Properties

AttributeValuesRemarks
Nameany stringEnter a self-explaining name of the node. If you leave this field empty, the generic name displays in the dashboard.
Setupany JavaScriptCode that you enter here is executed once whenever the node is deployed. Initializes any values in the node context that are required for the function. For example, a counter.
Functionany JavaScriptEnter a JavaScript function. Input variable is usually msg.payload. Return values are passed into the msg.payload as well.
Outputsany integerIf the function creates more than one output, this value can be set to return an array with different messages to the outputs. For example, if a function returns [null, msg], the first output is NULL, the second output contains the payload.
Closeany JavaScriptCode that you enter here is executed when the node is stopped or re-deployed. Cleans up outstanding requests or closes connections.

Example

Integration with Logstash and ElasticSearch

Template

Creates a payload snippet from the received data and the defined template and hands over the payload to the following node.

Use

The node applies a template to the defined property (usually msg.payload). It can be used to create a formatted msg.payload from any properties/values that are injected into the flow via Inject nodes. It outputs the formatted msg.payload.

Properties

AttributeValuesRemarks
Nameany stringEnter a self-explaining name of the node. If you leave this field empty, the generic name displays in the dashboard.
Property
Prefixmsg.|flow.|global.Default is msg. This refers to the message context. Select flow. to set the context to the complete flow (tab). Select global. to set the context to all flows in your Node-RED instance.
Valueenter value nameDefault is payload. This refers to the default property that all nodes can work with. Within the payload you can access any property that it contains.
Syntax Highlightselect value according to the template syntaxThe syntax highlighter helps you to create valid templates.
TemplateanythingEnter your template here.
FormatMustache template|Plain textSelect the output format. The output is written in the msg.payload (default) or in the context and property configured above.
Output asPlain text|Parsed JSON|Parsed YAMLOptionally, parse the output to JSON or YAML for further processing in following nodes.

Kafka Consumer

Subscribes to one or more topics from a Kafka broker.

Use

The node can be placed anywhere in a flow. Received messages can be forwarded as msg.payload to other nodes.

Properties

AttributeValuesRemarks
Nameany stringEnter a self-explaining name of the node. If you leave this field empty, the generic name displays in the dashboard.
TypeBaseThe value is pre-selected and cannot be changed!
Brokera Kafka broker id (string)The Kafka brokers are configured for all flows. The Kafka brokers can be selected in the node properties, to set the respective id.
Topics 
Nametopic name (string)Enter the name of the topic to subscribe. You can configure multiple topics in one node.
Wildcard (regex)true|falseIf true, you can enter a topic name with wildcard (*) to dynamically subscribe to a partition and offset.
Offsetany integer valueDefaults to 0. In this case, the consumer receives messages from the start. If you select a higher value, the consumer receives messages from that position on. For example, if you select 3 , the offset is at position 3 and the consumer receives message 4, 5, 6, ...
Partitionany integer valueDefaults to 0. Alternatively, select the partition to subscribe.
Options
Group IdA Kafka group id (string)Enter name of the Kafka group to which the consumer subscribes.
Auto Committrue|falseDefaults to true. This means the node automatically commits the messages that were already processed (the offset).
Auto Commit Interval (Ms)any integer valueDefaults to 5000 Ms. The auto-commit of processed messages (offest) is committed every five seconds to the Kafka broker.
Fetch
Fetch Max Wait (Ms)any integer valueDefaults to 100 Ms. Time delay to fetch messages from the Kafka broker.
Fetch Min Bytesany integer valueDefaults to 1 byte. This ensures that empty messages are ignored.
Fetch Max Bytesany integer valueDefaults to 1048576 bytes (approximately 1 MB). Higher values can create a high load on the service and must be tested properly.
Encoding
From Offsettrue|falseDefaults to true. Reads the messages in a partition of a topic from the last saved position. The offset works as a counter. Each message that is written into a partition of a topic adds a new offset value.
Encodingutf8Defaults to UTF8. Do not change!
Key Encodingutf8Defaults to UTF8. Do not change!
Convert message to JSONtrue|falseIf true, the Kafka message is converted into a JSON object, that can be processed in other nodes. If false, the Kafka message is passed as is.

Example

Integration with Kafka