Skip to main content

Write

Writes content to a file with atomic write support for data integrity.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.

Inputs

  • File Path - string - Absolute path to the file to write (required).
  • Content - string - Content to write to the file (required).

Outputs

  • File Path - string - Path to the written file.
  • File Size - int - Size of the written file in bytes.
  • File Info - object - File metadata after writing (size, modTime, permissions, name).

How It Works

The Write node writes content to a file using atomic write operations to ensure data integrity. When executed, the node:

  1. Validates the file path is absolute
  2. Checks for directory traversal attempts (blocks ".." in paths)
  3. Creates parent directories if they don't exist
  4. Writes content atomically using a temporary file:
    • Creates a temporary file in the same directory
    • Writes content to the temporary file
    • Syncs data to disk
    • Preserves original file permissions (if file exists)
    • Atomically renames temporary file to target path
  5. Returns file metadata after successful write

Requirements

  • Valid absolute file path
  • Write permissions in the target directory
  • No ".." directory traversal in path
  • Sufficient disk space

Error Handling

The node will return specific errors in the following cases:

  • Missing file path - "File path is required"
  • Missing content - "Content is required"
  • Relative path - "File path must be absolute"
  • Directory traversal - "Path cannot contain '..' for security reasons"
  • Directory creation failed - "Failed to create directory: {{error}}"
  • Write failed - "Failed to write file: {{error}}"
  • Access denied - "Cannot access written file: {{error}}"

Usage Examples

Create New File

Write content to a new file:

File Path: /home/user/documents/report.txt
Content: This is the report content.
Multiple lines are supported.

Overwrite Existing File

Replace the contents of an existing file:

File Path: /home/user/config/settings.json
Content: \{"theme": "dark", "language": "en"\}

Create File in New Directory

Automatically creates parent directories:

File Path: /home/user/new_folder/subfolder/data.txt
Content: Data in a new directory structure

Write Binary Content

Write base64-encoded binary data:

File Path: /home/user/images/output.png
Content: [base64 encoded image data]

Usage Notes

  • The atomic write operation prevents data corruption if the process is interrupted
  • Parent directories are created automatically with 0755 permissions
  • If the file already exists, its permissions are preserved
  • For new files, permissions are set to 0644
  • The temporary file is automatically cleaned up even if the rename fails
  • Directory traversal (..) is blocked for security
  • All file paths must be absolute (no relative paths allowed)
  • The operation is thread-safe due to atomic rename
  • Content is synced to disk before the rename operation

Common Use Cases

Save Configuration Files

Write application configuration as JSON, YAML, or XML files.

Generate Reports

Create text-based reports from automation data.

Create Log Files

Write structured logs to the filesystem.

Save API Responses

Store API response data to files for later processing.

Generate HTML/CSS Files

Create web assets from templates or dynamic content.

Export Data

Save processed data in CSV, JSON, or other formats.

Best Practices

  • Always provide absolute paths
  • Check available disk space before writing large files
  • Use appropriate content encoding (UTF-8 recommended)
  • Validate content before writing to ensure data integrity
  • Consider using Edit node for modifying existing files
  • Use Multi Edit for multiple changes to avoid multiple writes