This script keeps an eye on a file hosted online and alerts you whenever its content changes!
Features:
- Cross-platform: Works on both Windows 🪟 and Linux/Mac systems!
- No external dependencies: No need to install extra libraries
- Robust error handling: Handles network issues and non-200 status codes
- Clear notifications: Shows both old and new content for easy comparison
- Graceful shutdown: Exits cleanly with
Ctrl+C
or errors
How to Use:
-
Save the script: Copy and paste the code below into a file named
monitor.ts
. -
Run the script:
-
Using Node.js (v14 or later):
node monitor.ts <your_url_here>
-
Using Bun (v0.1 or later):
bun run monitor.ts <your_url_here>
-
Example:
Let's say you want to monitor a configuration file at https://example.com/config.txt
.
Node.js:
node monitor.js https://example.com/config.txt
Bun:
bun run monitor.js https://example.com/config.txt
Explanation:
The script will initially fetch the content of the file and store it as a reference in the memory. Then, it checks for changes at regular intervals (default 20 seconds) and alerts you if the content differs from the previous version. The output uses ANSI escape codes for basic styling (may not work in all terminals).
Customization:
- You can change the check interval (in milliseconds) by modifying the value passed to
setInterval
.
Happy monitoring!