Write To Library
Controlled node
Overview
The Write To Library node saves data as a file in the project's library. It supports multiple file formats including text, CSV, Word documents, images, and PDFs. The node can create new files or copy existing library files, and automatically creates directory structures as needed.
File Type Options
The node supports writing data in the following formats:
| File Type | Description | Input Requirements |
|---|---|---|
| txt | Plain text file | Any data (converted to string) |
| csv | Comma-separated values | Array of objects or CSV string |
| docx | Microsoft Word document | Markdown-formatted text |
| jpeg | JPEG image | Jimp image object |
| PDF document | Markdown-formatted text (converted via DOCX) | |
| latexString | LaTeX to PDF | LaTeX string with optional assets |
If the data input contains a file object with an id field (from the library), the node will download and re-upload that file to the specified location, effectively copying it.
Inputs
| Input | Type | Description | Default |
|---|---|---|---|
| Run | Event | Triggers the file write operation | - |
| Data | Data | Content to write. Can be text, tabular data, Jimp image, or existing file object | - |
| Name | Text | Filename for the new file (extension added automatically based on file type) | - |
| Path | Text | Directory path in the library (e.g., "reports/2024"). Creates directories if they don't exist | root |
| File Type | Enum | Format to save the file: txt, csv, docx, jpeg, pdf, or latexString | txt |
| Prevent Search | Boolean | If true, prevents the file from being indexed for search | true |
Outputs
| Output | Type | Description |
|---|---|---|
| Done | Event | Fires when the file has been successfully written |
| File | Data | File metadata object containing id, name, mimeType, dir, and size |
Runtime Behavior and Defaults
- Default File Type: Text files (
txt) - Default Search Prevention: Files are excluded from search indexing by default (
preventSearch: true) - Directory Creation: Automatically creates any missing directories in the specified path
- File Extensions: Automatically appends appropriate extensions based on file type (e.g.,
.pdffor PDF type) - Existing Files: If the data input is a file object with an
id, the node copies that file rather than creating new content - Image Handling: For JPEG output, accepts Jimp image objects and converts them to buffers automatically
- Document Conversion: DOCX and PDF types automatically convert markdown input to the respective formats
- LaTeX Support: The
latexStringtype compiles LaTeX to PDF and supports asset references via theassetsarray in the data input
Example Usage
Simple Text File:
Connect a Text node to the data input and set the name to "report". The node will create "report.txt" in the library root.
CSV from Data:
Connect a List node containing objects to the data input, set fileType to csv, and the node will automatically convert the data to CSV format using PapaParse.
Organized Storage:
Set the path input to "projects/client-a/invoices" and the name to "invoice-001". The node will create the directory structure if it doesn't exist and save the file accordingly.
Copying Files:
Pass a file object (from Get Library Files or similar) to the data input. The node will copy that file to the new path/name without modifying its content.