Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

hook-stdio

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hook-stdio

Hook process stdout and stderr.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

nodejs-hook-stdio Build Status

A simplified version of a great library: https://github.com/dpweb/loghooks-node. Allows you to grab the Node global process.stdout and process.stderr pipes and listen in.

Docs

The API is straightforward. Using either the stderr or the stdout function of the hook library, just pass in a handler function. The optional second argument is a true/false which controls whether or not the data is copied to the original destination or completely intercepted.

    //  Import the library.
var Hook = require('hook-stdio');

    //  Setup up a little container variable for stderr.
var errors = [];

    //  Intercept messages passed to the stderr pipe and add them to the array of errors.
Hook.stderr(errors.push, true);

process.stderr.write('Something catastrophic!');

//  Now errors == ['Something catastrophic!']

Or if you are running your javascript in the context of a node-webkit application:

    //  Import the library.
var Hook = require('hook-stdio');

    //  Intercept messages passed to the stderr and stdout pipes and display them graphically.
Hook.stdout(writeBlackTextToDOM, true);
Hook.stderr(writeRedTextToDOM, true);

function writeBlackTextToDOM (data) {
    document.getElementById('myconsole').innerHTML += '<p style="color:black;" >'+data+'</p>';
};

function writeRedTextToDOM (data) {
    document.getElementById('myconsole').innerHTML += '<p style="color:red;" >'+data+'</p>';
};

To restore the pipe to what it was, Hook.stdout and Hook.stderr return a function you can call:

    //  Import the library.
var Hook = require('hook-stdio');

var unhook = Hook.stderr(someFn, true);

	// Later, to restore the stream to what it was
unhook();

Keywords

stderr

FAQs

Package last updated on 16 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts