taildir
Version:
A simple directory watcher that recursively monitors file changes using only native Node.js libraries
79 lines (56 loc) • 1.71 kB
Markdown
# taildir
A lightweight Node.js directory watcher that monitors file changes recursively and outputs new content as it's appended - similar to `tail -f` but for entire directories.
## Features
- Recursively watches all files in a directory tree
- Outputs only new content when files grow (like `tail -f`)
- Filter by file extensions (e.g., watch only `.log` files)
- Ignores hidden files and temporary files
- Lightweight - uses only native Node.js libraries
- Trims empty lines from output
## Installation
```bash
npm install -g taildir
```
Or run directly with `npx`:
```bash
npx taildir <directory>
```
## Usage
Watch the current directory:
```bash
taildir
```
Watch a specific directory:
```bash
taildir /path/to/directory
```
Watch only specific file extensions:
```bash
taildir /path/to/directory -e js,ts,json
taildir --ext log,txt
```
### Example Output
```
Starting to watch: /home/user/logs
Press Ctrl+C to stop
==> /home/user/logs/app.log <==
[2024-01-15 10:30:45] Application started
[2024-01-15 10:30:46] Connected to database
==> /home/user/logs/error.log <==
[2024-01-15 10:31:02] ERROR: Failed to process request
```
## How It Works
- When starting, `taildir` records the current size of all files
- When a file grows, it reads and displays only the new content
- New files created while watching will show their complete content
- Files that shrink (truncated) are tracked but don't produce output
- Hidden files (starting with `.`) are ignored
## Use Cases
- Monitor application logs across multiple files
- Watch output directories for generated content
- Track changes in data files
- Debug file-writing applications
## Requirements
- Node.js >= 14.0.0
## License
MIT