Save Word
Saves a Word document to a specified file path.
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 the node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- File Descriptor - Unique identifier of the document to save. This comes from the Create Word or Open Word node. Default variable is
{{$message.word_fd}}. - Save Path - File path where the document will be saved. Must include the full path with .docx extension (e.g.,
/home/user/documents/report.docxorC:\Documents\report.docx).
Options
- Overwrite - Determines whether to overwrite an existing file at the specified path. Default is false.
- When true: Replaces existing file
- When false: Raises error if file exists
How It Works
The Save Word node persists the in-memory Word document to disk. When executed, the node:
- Validates the file descriptor and save path
- Retrieves the document from memory using the file descriptor
- Creates the directory structure if it doesn't exist
- Checks if a file already exists at the path
- If file exists and Overwrite is false, raises an error
- Saves the document to the specified path
- Preserves all formatting, content, and document properties
Requirements
- Valid file descriptor from Create Word or Open Word node
- Non-empty save path
- Valid file path format with .docx extension
- Write permissions for the target directory
- Sufficient disk space
Error Handling
The node will return specific errors in the following cases:
- Empty or invalid file descriptor
- Document not found
- Empty save path
- File already exists and Overwrite is disabled
- Invalid file path format
- Insufficient permissions to write to the location
- Disk space issues
- Directory creation failures
Usage Examples
Example 1: Save New Report
Scenario: Create and save a new monthly report
// Build report path with current date
$local.year = new Date().getFullYear();
$local.month = new Date().getMonth() + 1;
$local.reportPath = `/reports/monthly_report_${$local.year}_${$local.month}.docx`;
Configuration:
- File Descriptor:
{{$message.word_fd}} - Save Path:
{{$local.reportPath}} - Overwrite:
false
Result: Report saved to /reports/monthly_report_2025_1.docx. Error if file exists.
Example 2: Update Existing Document
Scenario: Open, modify, and save an existing document
// Path to existing contract
$local.contractPath = "/contracts/client_contract.docx";
Workflow:
- Open Word node: Opens
/contracts/client_contract.docx - Replace Text node: Updates contract details
- Save Word node: Saves changes back
Configuration:
- File Descriptor:
{{$message.word_fd}} - Save Path:
{{$local.contractPath}} - Overwrite:
true
Result: Original file is updated with new content.
Example 3: Save with Timestamp
Scenario: Save document with unique timestamp to prevent conflicts
// Create unique filename with timestamp
$local.timestamp = new Date().toISOString().replace(/[:.]/g, '-');
$local.outputPath = `/output/report_${$local.timestamp}.docx`;
Configuration:
- File Descriptor:
{{$message.word_fd}} - Save Path:
{{$local.outputPath}} - Overwrite:
false
Result: Document saved as report_2025-01-15T10-30-45-123Z.docx.
Example 4: Save to User-Specific Location
Scenario: Save document to user's home directory
// Build path using environment variables
$local.userName = $env.username || "user";
$local.savePath = `/home/${$local.userName}/Documents/my_document.docx`;
Configuration:
- File Descriptor:
{{$message.word_fd}} - Save Path:
{{$local.savePath}} - Overwrite:
true
Result: Document saved to user's Documents folder.
Usage Notes
- This is typically the last node in a Word automation flow
- The node creates parent directories automatically on some systems
- Saving does not close the document or invalidate the file descriptor
- Multiple saves to different paths are possible with the same document
- File extension should always be .docx
- The same document can be saved multiple times during a flow
Tips for Effective Use
- Always Save: Don't forget to save - changes are only in memory until saved
- Unique Names: Use timestamps or unique IDs to avoid conflicts
- Directory Existence: Verify parent directories exist or will be created
- Overwrite Carefully: Only enable when you're certain existing files should be replaced
- Path Variables: Use variables for flexible path management
- Backup Strategy: Save important documents to multiple locations if needed
- Test Paths: Verify write permissions before running in production
Best Practices
- Error Handling:
- Use Try-Catch blocks for file operations
- Check if files exist before overwriting
- Validate paths before saving
- File Naming:
- Use descriptive, consistent naming conventions
- Include dates or versions in filenames
- Avoid special characters in filenames
- Path Management:
- Use absolute paths for reliability
- Store base paths in configuration
- Handle different OS path formats
- Version Control:
- Save versions with incremental numbers
- Keep backups of important documents
- Use timestamped filenames for audit trails
File Naming Conventions
| Convention | Example | Best For |
|---|---|---|
| Date-based | report_2025-01-15.docx | Daily reports, time-series documents |
| Timestamped | document_20250115_103045.docx | Unique files, preventing conflicts |
| Version numbered | contract_v1.2.docx | Iterative documents, version tracking |
| Client-based | invoice_acme_corp_jan2025.docx | Client-specific documents |
| Sequential | order_00123.docx | Sequential processing, orders |
Path Examples
Windows Paths
// Absolute path
$local.path = "C:\\Documents\\Reports\\report.docx";
// UNC path
$local.path = "\\\\server\\share\\documents\\report.docx";
// User directory
$local.path = "C:\\Users\\username\\Documents\\report.docx";
Linux/Mac Paths
// Absolute path
$local.path = "/home/user/documents/report.docx";
// Relative to home
$local.path = "~/Documents/report.docx";
// Shared location
$local.path = "/mnt/shared/documents/report.docx";
Common Errors and Solutions
| Error | Cause | Solution |
|---|---|---|
| "File Descriptor cannot be empty" | No file descriptor provided | Ensure Create/Open Word node runs first |
| "Save path cannot be empty" | No save path provided | Provide a valid file path in Save Path input |
| "File already exists and overwrite is disabled" | File exists at path | Enable Overwrite or use different filename |
| "Document not found" | Invalid file descriptor | Verify file descriptor matches Create/Open Word output |
| "Failed to save Word document" | Permission or disk space issue | Check permissions and available disk space |
| Directory creation failure | Parent directory cannot be created | Verify path is valid and permissions are correct |
Overwrite Behavior
Overwrite = false (Default)
// First save: Success
Save Path: "/documents/report.docx"
Result: File created
// Second save with same path: Error
Save Path: "/documents/report.docx"
Result: Error - "File already exists and overwrite is disabled"
Overwrite = true
// First save: Success
Save Path: "/documents/report.docx"
Result: File created
// Second save with same path: Success
Save Path: "/documents/report.docx"
Result: Original file replaced with new content
Advanced Usage Patterns
Conditional Save Paths
// Choose save location based on document type
if ($local.documentType === "invoice") {
$local.savePath = "/documents/invoices/" + $local.filename;
} else if ($local.documentType === "contract") {
$local.savePath = "/documents/contracts/" + $local.filename;
} else {
$local.savePath = "/documents/general/" + $local.filename;
}
Version Management
// Auto-increment version if file exists
$local.baseFilename = "report";
$local.basePath = "/documents";
$local.version = 1;
// Check if file exists and increment version
while (fileExists(`${$local.basePath}/${$local.baseFilename}_v${$local.version}.docx`)) {
$local.version++;
}
$local.savePath = `${$local.basePath}/${$local.baseFilename}_v${$local.version}.docx`;
// Use Overwrite: false for safety
Multi-Location Save
// Save to multiple locations for backup
$local.primaryPath = "/documents/reports/report.docx";
$local.backupPath = "/backup/reports/report.docx";
$local.archivePath = `/archive/reports/report_${new Date().toISOString()}.docx`;
// Use three Save Word nodes in sequence with same file descriptor
// Node 1: Save to primary location
// Node 2: Save to backup location
// Node 3: Save to archive with timestamp
Dynamic Directory Structure
// Create organized directory structure
$local.year = new Date().getFullYear();
$local.month = String(new Date().getMonth() + 1).padStart(2, '0');
$local.day = String(new Date().getDate()).padStart(2, '0');
$local.savePath = `/documents/${$local.year}/${$local.month}/${$local.day}/report.docx`;
// Directory structure: /documents/2025/01/15/report.docx
Performance Considerations
- Large Documents: Saving large documents with many images takes longer
- Network Drives: Saving to network locations slower than local drives
- File Size: Documents with embedded images increase save time
- Compression: .docx format uses compression, which takes processing time
Workflow Integration
Typical Word Automation Flow
1. Create Word or Open Word
↓ (file descriptor)
2. Add Text / Add Table / Add Image / Replace Text (multiple nodes)
↓ (same file descriptor)
3. Save Word
↓
4. (Optional) Email file, upload to cloud, etc.
Document Generation Pipeline
1. Open Word (template)
2. Replace Text (fill placeholders)
3. Replace Image (update charts/logos)
4. Add Table (insert data)
5. Save Word (output path)
6. Convert to PDF (if needed)
7. Send via email or upload
Troubleshooting Tips
- Save Not Working: Verify file descriptor is valid and document exists in memory
- Permission Denied: Check write permissions for target directory
- Path Errors: Ensure path format is correct for the operating system
- Overwrite Issues: Check Overwrite setting matches your intent
- Large Files: For very large documents, allow sufficient time for save operation
- Network Issues: When saving to network drives, ensure stable connection
Integration with Other Nodes
After Save Operations
- Email Send: Attach the saved document to an email
- FTP Upload: Upload the saved file to a remote server
- Cloud Storage: Upload to Google Drive, OneDrive, etc.
- PDF Conversion: Convert saved .docx to PDF
- File Copy: Copy to additional backup locations
- Database Update: Record file path and metadata in database
Example: Save and Email
// 1. Create and populate document
// 2. Save document
$local.reportPath = "/tmp/monthly_report.docx";
// 3. Email the saved file
// Use Email Send node with attachment: $local.reportPath