Msg topic explanation

I've just started Node-Red and I've been taking lots of tutorials and they all mention msg.topic but never explain what it is used for.

Hi @scottriggle

A node-red message is a javascript object that can have any properties.

By convention the "interesting" information is put under a property called "payload".

Some nodes also make use of a property called "topic" to add some other contextual metadata to the message. Exactly what a node may do with msg.topic will depend on the node itself - their sidebar will highlight if they make use of the topic property at all. But on the whole, most nodes don't care about msg.topic.

The choice of 'topic' and 'payload' as property names come from the Node-RED origins handling MQTT messages, where messages containing a payload are published with to a topic that other clients can subscribe to.


Thank you for the excellent explanation.