Skip to content

CSV Downloader ​

The ui-csv-downloader node is a hidden widget: it shows nothing on the dashboard. When a message arrives, it takes an object from a configurable field of the message, turns it into a CSV file and makes the browser download it, with no interaction.

The widget belongs to a dashboard page, not to a group: the download happens in every browser that has that page open when the message arrives.

Palette: category dashboard, label CSV Downloader. 1 input, 1 output.

Configuration ​

PropertyDescriptionDefault
NameNode name shown in the editor.""
PageDashboard page the widget is registered on.— (required)
FieldMessage property, after msg., that holds the object to convert. Nested properties use dot notation (payload.csvData).payload

Input ​

The value at Field must be an object. If the property is missing or is not an object, nothing is downloaded.

The file has two lines:

  • the header: the keys of the object, separated by commas;
  • one data row: each value written as JSON, so strings appear in double quotes, numbers and booleans as they are, nested objects and arrays as JSON text, and null or missing values as "".

Values and keys are not quoted the CSV way: a comma inside a key, or inside a value that is not a string, starts a new column, and a quote inside a string is written \". The file suits flat objects of numbers and simple strings.

The file is named session_<sessionId>.csv when the object has a non-empty sessionId, and session_<milliseconds since 1970>.csv otherwise.

js
msg.payload = {
    sessionId: "session_123",
    timestamp: "2024-01-01T10:00:00",
    temperature: 25.5,
    humidity: 60
};

downloads session_session_123.csv:

text
sessionId,timestamp,temperature,humidity
"session_123","2024-01-01T10:00:00",25.5,60

Output ​

The received message is passed on unchanged to the output, so the node can sit in the middle of a flow. The conversion and the download happen in the browser.

Usage example ​

Download the figures of the current session when the operator presses a dashboard button. A function node between the button and the CSV Downloader (Field payload.csvData):

js
msg.payload = {
    csvData: {
        sessionId: flow.get("sessionId"),
        pieces: flow.get("pieces"),
        rejected: flow.get("rejected")
    }
};
return msg;

Every browser that has the page of the CSV Downloader open downloads session_<sessionId>.csv with one row.