Inject
Triggers flows by injecting messages manually or automatically.
Where and why do we use the Inject node?
The Inject node starts flows either manually by clicking the button on its left side or automatically on a schedule. This makes it essential for testing and debugging flows, triggering automated tasks, initializing system state on startup, or running periodic data processing jobs. It's often the first node in a flow, providing the initial message that kicks off the entire process.
Modes of operation
The Inject node can trigger flows in several different ways:
Manual Trigger
Click the button on the left side of the node to send a message on demand. This is the most common mode for testing, debugging, or manually initiating processes. The message can contain any configured payload and properties.
On Startup
Configure the node to inject a message automatically when Node-RED starts or when flows are deployed. This is useful for initializing flow state, setting default values, or starting background processes. You can add a delay before the injection occurs. When configured to inject once on start, a small '1' appears after the label inside the node.
Interval
Send messages repeatedly at a fixed time interval. Set the interval in seconds, minutes, hours, or days. The interval must be greater than 1 and less than 2^31. When the repeat value is 0 or below, Node-RED will not display an error but the interval won't function.
Scheduled
Inject messages at specific times using cron-like scheduling. This allows complex schedules like "every Monday at 9am" or "the first day of each month at midnight". Make sure to set the correct timezone in the editor settings.
How the node handles messages
The Inject node creates a new message object with configured properties. By default, it sets msg.payload to the current timestamp and msg.topic to an empty string, but you can configure any message properties.
Message properties can be set to:
- Static values (strings, numbers, booleans, JSON objects)
- Flow or global context variables
- Environment variables
- JSONata expressions for dynamic values
- Current timestamp
- Empty values
The node can set multiple message properties at once, allowing you to construct complete message objects that subsequent nodes need.
Examples
Inject on Node-RED start
To setup state when starting Node-RED, the inject node can be set to trigger a flow once with minimal delay. This example injects a timestamp immediately after deployment or restart.
Run a flow daily at midnight
By selecting "at a specific time" in the Repeat section, the inject node can generate a message at set times. This example triggers at 23:59 (11:59 PM) every day, useful for daily data processing tasks.
Inject a static string
The Inject node can set the payload to static data like strings, numbers, or JSON objects. This example injects the string "Hello FlowFuse!" when triggered manually.
Node Documentation
Injects a message into a flow either manually or at regular intervals. The message payload can be a variety of types, including strings, JavaScript objects or the current time.
Outputs
Details
The Inject node can initiate a flow with a specific payload value. The default payload is a timestamp of the current time in millisecs since January 1st, 1970.
The node also supports injecting strings, numbers, booleans, JavaScript objects, or flow/global context values.
By default, the node is triggered manually by clicking on its button within the editor. It can also be set to inject at regular intervals or according to a schedule.
It can also be configured to inject once each time the flows are started.
The maximum Interval that can be specified is about 596 hours / 24 days. However if you are looking at intervals greater than one day you should consider using a scheduler node that can cope with power outages and restarts.
Note: The "Interval between times" and "at a specific time" options use the standard cron system. This means that 20 minutes will be at the next hour, 20 minutes past and 40 minutes past - not in 20 minutes time. If you want every 20 minutes from now - use the "interval" option.
Note: To include a newline in a string you must use the Function or Template node to create the payload.