als-fs-events
v1.0.0
Published
Node module that enhances the fs module by emitting events for each file system operation, facilitating real-time monitoring and logging of file interactions.
Downloads
57
Maintainers
Readme
als-fs-events
als-fs-events
is a Node.js module that wraps the standard fs
module to add event emitting capabilities for each file system operation. This allows easy integration of file operation logging and monitoring in your application.
Installation
Install the module using npm:
npm install als-fs-events
Example Usage
Import the module in your project and start using the proxied versions of fs
or fs.promises
:
const fs = require('als-fs-events');
// Subscribe to a writeFile event
fs.emitter.on('writeFile', (event) => {
const {prop,args,error,result} = event
console.log(`File ${args[0]} has been written.`);
});
// Write a file asynchronously
await fs.promises.writeFile('example.txt', 'Hello, world!');
API
The module exports proxied versions of fs
and fs.promises
, which support all standard methods and properties, but also emit events for each operation:
- writeFile
- readFile
- unlink
- and others...
Events are emitted through emitter
, which supports the following events:
- all: an event for any operation
- errors: an event for operation errors
- operation name (e.g.,
writeFile
): an event for a specific operation
Each event returns an object with the following structure:
prop
: name of the operationargs
: arguments of the operationerror
: error (if any)result
: result of the operation (if no error)
License
als-fs-events
is released under the MIT License.