Skip to main content

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 TypeDescriptionInput Requirements
txtPlain text fileAny data (converted to string)
csvComma-separated valuesArray of objects or CSV string
docxMicrosoft Word documentMarkdown-formatted text
jpegJPEG imageJimp image object
pdfPDF documentMarkdown-formatted text (converted via DOCX)
latexStringLaTeX to PDFLaTeX string with optional assets
Copy Existing Files

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

InputTypeDescriptionDefault
RunEventTriggers the file write operation-
DataDataContent to write. Can be text, tabular data, Jimp image, or existing file object-
NameTextFilename for the new file (extension added automatically based on file type)-
PathTextDirectory path in the library (e.g., "reports/2024"). Creates directories if they don't existroot
File TypeEnumFormat to save the file: txt, csv, docx, jpeg, pdf, or latexStringtxt
Prevent SearchBooleanIf true, prevents the file from being indexed for searchtrue

Outputs

OutputTypeDescription
DoneEventFires when the file has been successfully written
FileDataFile 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., .pdf for 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 latexString type compiles LaTeX to PDF and supports asset references via the assets array 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.