montor v1.2.1
montor
montor allows you to monitor any Writable or Duplex - or any other interface that supports the _write functionality found in those - instance.
setup
setting up montor is as easy as installing it through npm and requiring it within your nodejs project
npm i montorconst montor = require("montor");and that's all you need to setup montor for use in your projects.
start(stream: Writable | Duplex, callback: Function, options?: {}): void
the montor.start function takes in three arguments
stream- the instance we will be monitoringcallback- the callback functionoptions(optional)- options to control the writes
the callback function can receive three arguments
chunk- the data sent through writeencoding- the encoding for the given chunknext(ifnextisfalse) - callback to continue to next write, see stream
the options object can have
default(optional, defaulttrue) - whether to continue normal writesbefore(optional, defaulttrue) - whether to call thecallbackbefore or after the normal write (no effect ifdefaultisfalse)next(optional, defaulttrue) - whether to automatically callnext(iffalse,nextis passed as the third argument tocallback)
here is an example of how the montor.start function is used, along with what the output from the callback looks like
// this is our normal output
console.error("hello"); // > hello
// now we start monitoring and only get the monitored write
montor.start(process.stderr, chunk => console.log("monitored: " + chunk), {default: false});
console.error("hello"); // > monitored: hellostop(stream: Writable | Duplex): void
the montor.stop function takes in only one argument
stream- this instance to stop monitoring
here we can see how the montor.stop function is used and how regular writes are brought back
// we start monitoring and only get the monitored write
montor.start(process.stderr, chunk => console.log("monitored: " + chunk), false);
console.error("hello"); // > monitored: hello
// then we stop monitoring and go back to regular writes
montor.stop(process.stderr);
console.error("hello"); // > hellolicence
MIT
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago