Fixed-Width File icon

Fixed-Width File

Fixed Width File

Overview

The Write to File operation of the "Fixed-Width File" node serializes workflow data into a fixed-width formatted file. Each field in the output file has a specified width, alignment, and type, making it suitable for integration with legacy systems or applications that require strict column-based text formats (such as mainframe imports, banking, or EDI systems). The node outputs the generated file as binary data, which can be used in subsequent nodes (e.g., for email attachments, FTP uploads, or storage).

Example use cases:

  • Exporting customer records to a fixed-width format for batch processing.
  • Generating payroll files for financial institutions.
  • Creating standardized data exports for third-party integrations.

Properties

Name Type Meaning
Binary Property String Name of the binary property in which to save the binary data of the fixed-width formatted file.
Fields Fixed Collection Defines the structure of each field in the output file. Each field includes:
- Property Name: Source property (supports dot notation).
- Type: Data type (Boolean, Float, Integer, Number, String).
- Width: Number of characters allocated.
- Align: Alignment within the field (Left/Right).
Options > Encoding Options Character encoding for the output file (ASCII, Base64, Hex, Latin-1, UTF-16 LE, UTF-8). Default is UTF-8.
Options > End-of-Line Character String Character(s) used to separate rows in the file. Default is \n.
Options > Append End-of-File Character Boolean Whether to add an end-of-line character at the end of the file. Default is true.
Options > Padding Character String Character used to pad values shorter than their field's width. Default is a space ( ).
Options > Trim Options Trimming behavior for field values: Both, None, Left, Right. Default is Both.
Options > File Name String Optional file name to set in the binary data.

Output

  • The node outputs a single item with:
    • An empty json object.
    • A binary property whose key matches the value of Binary Property. This contains the fixed-width formatted file as binary data.
    • If a file name was provided, it is included in the binary metadata.

Example output:

{
  "json": {},
  "binary": {
    "data": {
      "data": "<Buffer ...>", // The actual file content as a Buffer
      "fileName": "example.txt", // (if provided)
      "mimeType": "application/octet-stream"
    }
  }
}

Dependencies

  • No external API keys or services are required.
  • The node relies on the following npm packages (bundled):
    • @evologi/fixed-width for parsing and stringifying fixed-width data.
  • n8n helpers are used for binary data handling.

Troubleshooting

Common issues:

  • Field Width Mismatch: If the sum of field widths does not match the expected record length, downstream systems may reject the file.
  • Encoding Problems: Using the wrong encoding may result in unreadable files for target systems.
  • Missing Fields: If a specified property does not exist in the input data, the corresponding field will be padded.
  • Error Handling: If an error occurs during serialization (e.g., invalid field configuration), the node will throw an error unless "Continue On Fail" is enabled.

Typical error messages:

  • "Cannot read property 'field' of undefined": Likely due to missing or misconfigured fields.
  • "Invalid field width": Ensure all fields have a positive integer width.
  • "Failed to prepare binary data": Check if the file name or encoding is valid.

Resolution steps:

  • Double-check field definitions and ensure all required properties are present in your input data.
  • Verify encoding compatibility with your target system.
  • Use "Continue On Fail" to skip problematic items and review errors in the output.

Links and References

Discussion