Overview
The file-watch node monitors files and directories on the
local filesystem. It emits a message whenever a watched file is created, modified, or deleted.
Ideal for detecting configuration changes, monitoring upload directories, or triggering
processing pipelines when new data files arrive.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| path | string | "" | File or directory path to watch (e.g., /data/uploads) |
| recursive | boolean | true | Watch subdirectories recursively |
| pattern | string | "*" | Glob pattern to filter files (e.g., *.csv, *.json, **/*.log) |
Output Message
When a file event is detected, the node outputs a message with the following structure:
{
"payload": "/data/uploads/sensor-log.csv",
"topic": "/data/uploads",
"file": "sensor-log.csv",
"type": "file",
"size": 2048,
"event": "change", // "change", "add", or "unlink"
"_msgid": "fw001"
} Example: Watch Config File for Changes
Monitor a configuration file and reload application settings whenever it is updated. Uses a single file path to watch one specific file.
// file-watch node configuration
{
"path": "/etc/edgeflow/config.json",
"recursive": false,
"pattern": "*.json"
}
// When config.json is saved, output:
{
"payload": "/etc/edgeflow/config.json",
"file": "config.json",
"event": "change",
"size": 512
}
// Connect to a file-read node to reload the config
// then pass to a function node to apply changes:
// flow.set('config', JSON.parse(msg.payload));
// node.status({ text: "Config reloaded" }); Example: Monitor Upload Directory
Watch an upload directory for new CSV files arriving from connected sensors. Trigger processing only for newly added files matching the CSV pattern.
// file-watch node configuration
{
"path": "/data/uploads",
"recursive": true,
"pattern": "*.csv"
}
// When a new CSV is dropped in, output:
{
"payload": "/data/uploads/2024/temp-readings.csv",
"file": "temp-readings.csv",
"event": "add",
"size": 8192
}
// Connect to a switch node to filter by event type:
// Rule 1: msg.event == "add" -> process new files
// Rule 2: msg.event == "change" -> re-process updated files
// Rule 3: msg.event == "unlink" -> log deleted files Example: Detect Log File Rotation
Monitor a log directory for new log files created by rotation, and archive them automatically.
// file-watch node configuration
{
"path": "/var/log/edgeflow",
"recursive": false,
"pattern": "*.log"
}
// When logrotate creates a new file:
{
"payload": "/var/log/edgeflow/app-2024-01-15.log",
"file": "app-2024-01-15.log",
"event": "add"
}
// Downstream: compress and move to archive storage
// using an exec node or file-write + gzip pipeline Common Use Cases
Hot Reload Configuration
Reload app settings when config files change
Data Ingestion Pipeline
Process new data files as they arrive in a drop folder
Log Monitoring
Detect log rotation and trigger archival workflows
Firmware Updates
Detect new firmware files and trigger OTA updates