Actions2
Overview
The Write to File operation of the Csv File node converts incoming workflow data into a CSV file and outputs it as binary data. This is useful when you need to export n8n data for use in other systems, store results as files, or send CSVs via email or APIs. For example, you might use this node to generate a report from processed data and attach it to an outgoing email, or to save workflow results to a file storage service.
Properties
| Name | Type | Meaning |
|---|---|---|
| Binary Property | String | The name of the binary property where the generated CSV file will be stored. |
| Options | Collection | Additional settings for the output file: |
| └ File Name | String | The filename to assign to the generated CSV file (default: "data.csv"). |
| └ Header Row | Boolean | Whether to include a header row with column names in the CSV file (default: true). |
Output
- binary:
- The specified binary property (as set by "Binary Property") will contain the generated CSV file as binary data.
- The file will have the name specified in "File Name" (or "data.csv" by default).
- json:
- An empty object (
{}) is provided in thejsonfield for each output item.
- An empty object (
- pairedItem:
- Contains a reference to the original input item.
Example output structure:
{
"json": {},
"binary": {
"yourBinaryPropertyName": {
"data": "<base64-encoded CSV file>",
"fileName": "yourFileName.csv",
// ...other metadata
}
},
"pairedItem": {
"item": 0
}
}
If an error occurs and "Continue On Fail" is enabled, the output will instead be:
{
"json": {
"error": "Error message"
},
"pairedItem": {
"item": 0
}
}
Dependencies
- No external services or API keys are required.
- The node uses the following npm packages internally:
csv,csv-stringify/sync, andiconv-lite. - No special n8n configuration or environment variables are needed for this operation.
Troubleshooting
Common Issues:
- Missing Binary Property:
If the "Binary Property" value is not set, or if there is a conflict with another binary property, the node may fail to output the file correctly. - Invalid File Name:
Using invalid characters in the "File Name" option could cause issues when saving or using the file downstream. - Large Data Sets:
Exporting very large datasets may result in memory issues or slow performance.
Error Messages:
"The operation \"<operation>\" is not supported!"
This occurs if an unsupported operation is selected. Ensure "Write to File" is chosen.- Error messages in the
json.errorfield (when "Continue On Fail" is enabled) indicate what went wrong during processing, such as encoding errors or unexpected data structures.