Write File

Write content to a file

Overview

This node writes content to a file on the filesystem. It supports multiple content sources including direct text input, base64-encoded binary data, JSON objects, or content extracted from a property of the input data. Users can specify how the file is written—overwriting existing files, appending to them, or creating new files only if they don't exist. Additional options allow control over encoding, file permissions, automatic creation of parent directories, and backing up existing files before overwriting.

Common scenarios:

  • Saving generated reports or logs as text files.
  • Writing binary data such as images or documents decoded from base64.
  • Exporting structured data by writing JSON objects formatted as text files.
  • Dynamically writing content extracted from previous workflow steps.

Practical example:

  • After processing some data, you want to save a summary report as a UTF-8 encoded text file, overwriting any existing file.
  • You receive base64-encoded image data and want to write it as a binary file.
  • You have a JSON object representing configuration settings and want to export it as a pretty-formatted JSON file.
  • You want to append log entries to an existing log file without overwriting previous content.

Properties

Name Meaning
File Path The full path where the file will be written.
Content Source The source of the content to write. Options: Text Input, Binary Data (base64), JSON Object, From Property (content taken from a specified input property).
Content The text content to write (used when Content Source is "Text Input").
Binary Data (Base64) Base64 encoded binary data to write (used when Content Source is "Binary Data").
JSON Object JSON object to write as formatted text (used when Content Source is "JSON Object").
Property Name Name of the property in the input data containing the content to write (used when Content Source is "From Property").
Write Mode How to write the file. Options: Overwrite (replace existing or create new), Append (add to existing or create new), Create Only (fail if file exists).
Encoding Encoding used when writing the file (applies to Text Input, JSON Object, and From Property). Options: UTF-8, ASCII, UTF-16 LE, Base64, Hex.
Additional Options Collection of extra settings:
- Create Parent Directories Whether to create parent directories if they do not exist (default true).
- File Mode (Permissions) File permissions in octal notation (e.g., 0644).
- JSON Formatting How to format JSON output: Pretty (indented) or Compact (no extra spaces). Applies only when Content Source is JSON Object.
- Backup Existing File Whether to create a backup copy of the existing file before overwriting it.

Output

The node outputs one item per input with a JSON object containing details about the write operation:

  • success (boolean): Indicates if the file was written successfully.
  • filePath (string): The resolved absolute path of the written file.
  • fileName (string): The base name of the file.
  • fileExtension (string): The file extension including the dot (e.g., ".txt").
  • writeMode (string): The mode used for writing ("overwrite", "append", or "create").
  • contentSource (string): The source type of the content written.
  • bytesWritten (number): Number of bytes written to the file.
  • sizeHuman (string): Human-readable size of the file (e.g., "1.23 MB").
  • created (Date): Timestamp when the file was created.
  • modified (Date): Timestamp when the file was last modified.
  • encoding (string, optional): The encoding used (present if content source is text, JSON, or property).

If the node encounters an error and "Continue On Fail" is enabled, the output JSON will contain:

  • success: false
  • error: Error message string
  • filePath: The attempted file path

The node does not output binary data directly; binary content is written to the file system.

Dependencies

  • Requires access to the local filesystem where n8n is running.
  • Uses Node.js built-in modules: fs (filesystem operations) and path (path resolution).
  • No external API keys or services are required.
  • Permissions to create, write, and modify files and directories at the specified paths are necessary.
  • If "Create Parent Directories" is enabled, the node will create missing directories recursively.

Troubleshooting

  • File path missing or invalid: The node throws an error if the file path is empty or invalid. Ensure the path is correct and accessible.
  • File already exists with 'Create Only' mode: Writing fails if the file exists and the mode is set to create only. Use overwrite or append modes if you want to modify existing files.
  • Property not found: When using "From Property" content source, if the specified property does not exist in the input data, an error is thrown.
  • Permission errors: Lack of write permissions on the target directory or file will cause failures. Verify filesystem permissions.
  • Invalid base64 data: For binary content, ensure the base64 string is valid; otherwise, writing may fail or produce corrupted files.
  • Backup failure: If backup creation is enabled but fails (e.g., due to permission issues), the node will throw an error.
  • Encoding mismatches: Using an incorrect encoding for the content may result in corrupted files or unreadable content.

To resolve errors, check the error messages provided in the output or thrown exceptions, verify file paths, permissions, and input data correctness.

Links and References

Discussion