als-fs-events

1.0.0 • Public • Published

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 operation
  • args: arguments of the operation
  • error: error (if any)
  • result: result of the operation (if no error)

License

als-fs-events is released under the MIT License.

Package Sidebar

Install

npm i als-fs-events

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

8.62 kB

Total Files

5

Last publish

Collaborators

  • alexsorkin