https://github.com/beyondjs/watchers
A file watching utility designed for BeyondJS applications. This package provides efficient file system monitoring capabilities, enabling real-time detection of file changes, additions, and deletions. Ideal for developers working with BeyondJS projects requiring dynamic file observation and event-driven responses to file system modifications.
https://github.com/beyondjs/watchers
Last synced: about 1 year ago
JSON representation
A file watching utility designed for BeyondJS applications. This package provides efficient file system monitoring capabilities, enabling real-time detection of file changes, additions, and deletions. Ideal for developers working with BeyondJS projects requiring dynamic file observation and event-driven responses to file system modifications.
- Host: GitHub
- URL: https://github.com/beyondjs/watchers
- Owner: beyondjs
- License: mit
- Created: 2022-12-01T13:34:35.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-31T10:11:02.000Z (over 1 year ago)
- Last Synced: 2025-03-21T19:45:04.685Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @beyond-js/watchers
A powerful and flexible file watching utility for Node.js applications, designed to work seamlessly with BeyondJS
projects.
## Installation
```bash
npm install @beyond-js/watchers
```
## Usage
```javascript
const Watcher = require('@beyond-js/watchers');
const container = {
path: '/path/to/watch'
// other container properties
};
const watcher = new Watcher(container);
watcher.start().then(() => {
console.log('Watcher started');
const listener = watcher.listeners.create('/path/to/watch', {
includes: ['*.js'],
excludes: ['node_modules'],
extname: ['.js', '.ts']
});
listener.on('change', file => {
console.log(`File changed: ${file}`);
});
});
// Later, when you're done watching
watcher.destroy();
```
## API
### Watcher
- `constructor(container: object)`: Creates a new watcher instance
- `start(): Promise`: Starts the watcher
- `destroy(): void`: Stops the watcher and cleans up resources
### Listener
- `create(path: string, filter: object): Listener`: Creates a new listener
- `on(event: string, callback: Function): void`: Attaches an event listener
- `destroy(): void`: Removes the listener
## Features
- Efficient file watching using chokidar
- Support for multiple watchers and listeners
- Configurable file filters (includes, excludes, extensions)
- Event-based architecture
- Integrated with BeyondJS IPC for cross-process communication
## Implementation Details
- Uses chokidar for file watching
- Implements a client-server architecture for distributed watching
- Supports chained exceptions for better error handling
- Utilizes Promises for asynchronous operations
## License
MIT © [[BeyondJS](https://beyondjs.com)]