JavaScript API Reference

This page documents the global objects available in the JavaScript environment shared by the nodered_js and tag_processor processors. The engine is goja (ES5.1 with some ES6 features) — no Node.js APIs are available.

msg

The message object. Contains the payload and metadata of the current message.

msg.payload    // The message content (any JSON type)
msg.meta       // Metadata key-value pairs (strings)

Return behavior:

  • return msg; — pass the message through (modified or not)

  • return null; or return undefined; — drop the message

  • return { payload: ..., meta: ... }; — create a new message

Example:

msg.payload = msg.payload * 2;
msg.meta.processed = "true";
return msg;

console

Logging functions that write to the Benthos logger.

console.debug(...)  // DEBUG level
console.log(...)    // INFO level
console.info(...)   // INFO level
console.warn(...)   // WARN level
console.error(...)  // ERROR level

Accepts multiple arguments: console.log("value is", msg.payload.value)

cache

Key-value store for maintaining state across messages. Persists across all messages for the lifetime of the Benthos process. In-memory only, lost on restart. Supports any JSON-compatible type: strings, numbers, booleans, objects, arrays.

The cache is automatic and requires no configuration.

Always use cache.exists(key) before cache.get(key) to avoid error logs on missing keys.

Counter

Previous value comparison

History (last N values)

Alarm state tracking

Cycle time between events

Limitations

  • In-memory only — state is lost when the Benthos process restarts. A persistent backend is planned.

  • No size limits — the cache grows unboundedly if keys are never deleted. Use cache.delete to clean up unused keys. A memory safeguard (threshold, eviction) is planned.

  • Cache scope in tag_processor — the cache is shared across all stages (defaults, conditions, advancedProcessing). A value set in defaults is visible in advancedProcessing within the same message.

Last updated