npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hook-stdio

v1.0.0

Published

Hook process stdout and stderr.

Downloads

251

Readme

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();