1.0.0 • Published 2 years ago
als-fs-events v1.0.0
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-eventsExample 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.
1.0.0
2 years ago