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 montor
const 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
(ifnext
isfalse
) - 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 thecallback
before or after the normal write (no effect ifdefault
isfalse
)next
(optional, defaulttrue
) - whether to automatically callnext
(iffalse
,next
is 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: hello
stop(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"); // > hello
licence
MIT
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago