Csv File icon

Csv File

Reads and writes data from a csv file

Overview

The Csv File node with the "Read From File" operation reads and parses CSV data from a binary file property in incoming n8n items. It is useful for workflows that need to extract structured data from uploaded or previously processed CSV files, enabling further automation steps such as filtering, transformation, or integration with other systems.

Common scenarios:

  • Importing user-uploaded CSV files for processing.
  • Reading exported data from external systems in CSV format.
  • Parsing CSV attachments from emails or cloud storage.

Practical example:
A workflow receives a CSV file via email, uses this node to parse its contents, and then iterates over each row to create records in a database.


Properties

Name Type Meaning
Binary Property String Name of the binary property from which to read the binary data of the CSV file. This should match the property name where the file's binary data is stored (e.g., "data").
Options Collection Additional options for parsing the CSV file. See below for details.

Options sub-properties:

Name Type Meaning
BOM Boolean If enabled, strips the byte order mark (BOM) from the input string or buffer. Automatically detects and handles BOM if present. Default: true.
Encoding Options Specifies the encoding of the input file (e.g., utf8, ascii, base64, etc.). If not set, defaults to utf8.
Header Row Boolean If enabled, generates records as object literals using the first row as column headers. If disabled, outputs each row as an array. Default: true.
Skip Empty Lines Boolean If enabled, skips any empty lines in the CSV file. Default: false.
RAW Boolean If enabled, output includes both the original CSV content (raw) and the parsed record (record). Default: false.
Comment String Treats all characters after this one as a comment. Disabled by default (empty string).
From Number Starts emitting records from this record number (1-based index). Default: 1.
From Line Number Starts emitting records from this line number (1-based index). Default: 1.

Output

  • If "Header Row" is enabled (default):
    Each output item contains a json object representing a row, with keys corresponding to the CSV header columns and values from the row.

    {
      "column1": "value1",
      "column2": "value2"
    }
    
  • If "Header Row" is disabled:
    Each output item contains a json object with a single property row, which is an array of values from the CSV row.

    {
      "row": ["value1", "value2"]
    }
    
  • If "RAW" option is enabled:
    Each output item contains a json object with two properties:

    • raw: The original CSV content for the row.
    • record: The parsed row as an object or array, depending on the "Header Row" setting.
    {
      "raw": "\"value1\",\"value2\"",
      "record": { "column1": "value1", "column2": "value2" }
    }
    
  • On error (if "Continue On Fail" is enabled):
    The output will contain an error property with the error message.

    {
      "error": "Error message here"
    }
    

Dependencies

  • External packages:

    • csv (for parsing CSV data)
    • iconv-lite (for handling various encodings)
  • n8n requirements:

    • The binary property specified must exist and contain valid CSV file data.
    • No API keys or external service credentials are required.

Troubleshooting

Common issues:

  • Missing binary property:
    If the specified binary property does not exist or is missing from the input item, the node will skip that item without output (unless "Continue On Fail" is enabled).
  • Invalid encoding:
    If an unsupported encoding is specified, parsing may fail with an error about unknown encoding.
  • Malformed CSV:
    If the CSV file is not well-formed, parsing errors may occur.

Error messages:

  • "The operation \"...\" is not supported!"
    Ensure you have selected a valid operation ("Read From File" or "Write to File").
  • Errors related to parsing or encoding will be included in the output under the error property if "Continue On Fail" is enabled.

Links and References

Discussion