
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
file-dispatcher
Advanced tools
File Dispatcher is a high-performing Node.js library for file event monitoring and dispatching. It efficiently handles file creation or renaming events, providing real-time responses in both synchronous and asynchronous modes. Compact yet powerful, it's i
The File Dispatcher is a lightweight and high-performance Node.js library designed to monitor and dispatch file creation events. It provides real-time responses and effectively handles file system interactions without external dependencies. With support for both synchronous and asynchronous modes. It ensures reliable performance. Additionally, it is compatible with Linux, macOS, and Windows, offering seamless operation across multiple platforms.
The built-in fs module in Node.js had two issues, which have been addressed as follows:
The problem of not being able to read all files efficiently in situations of rapid file creation:
Treating file creations, modifications, and deletions as a single "rename" event, resulting in the inability to detect file creations accurately:
The native addon effectively resolves this by reading the content immediately upon receiving the path, thereby making the probability of encountering concurrency issues extremely low. Therefore, no lock processing, such as mutex, has been applied.
npm install file-dispatcher
Note: Versions lower than 3.0.0 are not recommended
import { FileDispatcher, FdMode, FdEventType } from 'file-dispatcher';
// Create a FileDispatcher instance
const dispatcher = new FileDispatcher({
path: './directory/path', // Optional. Default: current directory
mode: FdMode.Sync, // Optional. Default: FdMode.Async
interceptor: customInterceptor, // Optional
pattern: /binlog/, // Optional (file name pattern)
});
dispatcher.start(); // Start monitoring the directory
dispatcher.stop(); // Stop monitoring the directory
// Handle success and fail event
dispatcher.on(FdEventType.Success, (filePath, fileContent) => {
console.log('File dispatched successfully. Path:', filePath, '\nContent:', fileContent);
});
dispatcher.on(FdEventType.Fail, (error) => {
console.error('Failed to dispatch file.', error);
});
function customInterceptor(filePath: string, content: string): string {
return content.toUpperCase(); // Modify the file content here (example: convert to uppercase)
}
path (optional): The directory path to monitor for file events. Leave it empty to monitor the current code file directory.mode (optional): Use FdMode.Async for asynchronous mode or FdMode.Sync for synchronous mode. The default mode is FdMode.Async.interceptor (optional): A custom interceptor function that can modify the file content before dispatching. It takes the file path and content as input and returns the modified content.pattern (optional): A regular expression pattern to filter specific file types. Only files matching this pattern will be dispatched. Leave it empty to include all files.FdEventType.Success: Event type emitted when a file is successfully dispatched.FdEventType.Fail: Event type emitted when an error occurs during file dispatching.FdMode.Async: Enables parallel processing for faster execution speed, but does not guarantee the order of file processing.FdMode.Sync: Ensures the order of file processing but may have slower execution speed compared to the asynchronous mode.This library is licensed under the MIT License.
For more information and detailed API documentation, please visit the GitHub repository.
If you encounter any issues or have questions, please feel free to submit an issue.
FAQs
File Dispatcher is a high-performing Node.js library for file event monitoring and dispatching. It efficiently handles file creation or renaming events, providing real-time responses in both synchronous and asynchronous modes. Compact yet powerful, it's i
We found that file-dispatcher demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.