Read File

Read content from a file

Overview

This node reads the content of a file from the local filesystem. It supports reading files as plain text, binary data (base64 encoded), or parsed JSON. The node is useful in workflows where you need to ingest file contents for further processing, such as reading configuration files, importing data, or handling attachments.

Common scenarios include:

  • Reading a log file as text to analyze its contents.
  • Importing a JSON file and using its structured data downstream.
  • Loading binary files like images or documents encoded in base64 for transmission or storage.

Properties

Name Meaning
File Path The full path to the file to read.
Read Mode How to interpret the file content: "Text" (plain text), "Binary" (base64 encoded), or "JSON" (parse as JSON).
Encoding Text encoding used when reading the file (only applies if Read Mode is "Text"). Options: UTF-8, ASCII, UTF-16 LE, Base64, Hex.
Additional Options Collection of extra settings:
• Include File Stats: Whether to include file metadata (size, dates, etc.)
• Property Name: The name of the property in output JSON where the file content will be stored (default "content")
• Max File Size (MB): Maximum allowed file size; 0 means no limit.

Output

The node outputs an array of items, each containing a json object with the following structure:

  • A property named as specified by the "Property Name" input (default "content"), holding the file content:
    • If "Text" mode: string with the file's text content.
    • If "Binary" mode: base64 encoded string of the file's binary data.
    • If "JSON" mode: parsed JSON object from the file.
  • filePath: resolved absolute path of the file.
  • fileName: base name of the file.
  • fileExtension: file extension including the dot (e.g., .txt).
  • readMode: the mode used to read the file (text, binary, or json).

If "Include File Stats" is enabled, an additional fileStats object is included with:

  • size: file size in bytes.
  • sizeHuman: human-readable file size (e.g., "1.23 MB").
  • created: file creation date.
  • modified: last modification date.
  • accessed: last access date.
  • isFile: boolean indicating if path is a file.
  • isDirectory: boolean indicating if path is a directory.
  • mode: file mode/permissions.
  • uid: user ID of owner.
  • gid: group ID of owner.

Dependencies

  • Requires access to the local filesystem where n8n is running.
  • Uses Node.js built-in modules: fs, fs/promises, and path.
  • No external API keys or services are needed.

Troubleshooting

  • File path is required: Ensure the "File Path" property is set and points to a valid file.
  • File not found: The specified file does not exist at the given path. Verify the path and permissions.
  • Path is not a file: The path points to a directory or non-file entity. Provide a valid file path.
  • File size exceeds limit: The file size is larger than the configured maximum. Increase the limit or choose a smaller file.
  • Failed to parse JSON: When reading in JSON mode, the file content is not valid JSON. Check the file format.
  • Invalid read mode: An unsupported read mode was selected. Use one of the provided options.

To resolve errors, verify file existence, permissions, correct paths, and that the file content matches the expected format.

Links and References

Discussion