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

hapi-console

v1.0.2

Published

Lightweight colored console output for hapi

Downloads

10

Readme

Hapi Console

so colours
much lightweight
such better
wow

~ Eek 2016


console output

Install

npm

npm i --save hapi-console

Quick Example

const Hapi = require('hapi');
const server = new Hapi.Server({ debug: false });
const hapiConsole = require('hapi-console');

server.register({
    register: hapiConsole,
    options: {
    
        // ignore /ignore/me route
        ignore: ['/ignore/me'],

        // show custom data about the request
        custom: {
            // shows custom data about auth.credentials.uid as 'uid: <>'
            'auth.credentials.uid': true,  
            
            // shows a JSON.stringify version of query
            'query': true, 
            
            // executes the function and uses the output where x is request.headers
            'headers': (x) => JSON.stringify(x).replace(/"/g, '') 
        },
        
        // if true it uses the full path of the key to display the data 
        // if false it uses just the last property key to display data
        customFullLengthKey: false
    }
}, () => {
    if (err) {
        console.error(err);
    }
    
    server.route({
        path: '/',
        method: 'get',
        handler: (req, res) => {
        
            // will show an error
            req.log('error', 'err');
             
            // will also show an error with stack
            req.log('error', new Error()); 
            
            // will log on request
            req.log('log', 'log 1');  

            // will log on server
            server.log('log', 'this is a server log'); // we
            
            // will show an unexpected error
            setTimeout(() => {throw new Error('up')}, 100);
        }
    });  
  
    server.start();
});

Note: userFilter has been deprecated in favour of custom since 0.6.0

Options

options.ignore {Array.<String>}

Will not write to console output from the route's context but will log errors

options.ignoreSyscall {Boolean}

Will not write to console output any syscall errors

options.userFilter {Object.<String, Boolean>}

Will filter what data from request.auth.credentials is shown in the output

Interpreting the output

Server start

Example:

SERVER test/2 STARTED
    ID:         Stefan:26747:itfodt15
    PORT:       8081
    HOST:       Stefan
    PROTOCOL:   http
    URI:        http://Stefan:8081

Explanation:

SERVER {connection assigned labels split by /} STARTED
       ID:         {connection id}
       PORT:       {port}
       HOST:       {host}
       PROTOCOL:   {protocol}
       URI:        {full uri}

Server Log

server.log(['log', 'test'], 'this is a server log');

Example: 
1474629596922:Stefan:26747:itfodt0w       | [log/test] this is a server log
Explanation: 
{ timestamp }:{host}:{pid}:{ts base64}    | [{tags}] {message}

Request Log

req.log(['log', 'test'], 'request log');

Example: 
1474629596915:Stefan:26747:itfodt0w:10000:8080 [test|1] 127.0.0.1 [{uid: 12345}] [log/test] log 1
Explanation: 
{ timestamp }:{host}:{pid}:{ts base64}:{counter}:{port} [{connection labels}] {ip} [{user data}] [{tags}] {message}

Request Error

req.log('error', new Error('¯\\_(ツ)_/¯')

Example:
1474629596915:Stefan:26747:itfodt0w:10000:8080 [test|1] 127.0.0.1 [null] [ERROR] Error ¯\_(ツ)_/¯ \n {stack}
Explanation: 
{ timestamp }:{host}:{pid}:{ts base64}:{counter}:{port} [{connection labels}] {ip} [{user data}] [ERROR] {error stack trace}

Reply

res({success: true}}

Example:
1474629596915:Stefan:26747:itfodt0w:10000:8080 [test|1] 127.0.0.1 [{uid: 1234}] 200 GET:/ 0.74[0.02~0+0.28~0.42]
Explanation:
{ timestamp }:{host}:{pid}:{ts base64}:{counter}:{port} [{connection labels}] {ip} [{user data}] {status code} {method}:{path} {total time ms}[{traffic in time + hapi head}~{auth time ms}+{handler time ms}~{traffic out time + hapi tail}]
Info: if the times don't add up that's because there's also time spent inside the `HAPI` server code 

Unexpected Error

throw 'up'

Example:
1474629596915:Stefan:26747:itfodt0w:10000:8080 [test|1] 127.0.0.1 [null] [ERROR] Error: Uncaught error: up
Explanation: 
{ timestamp }:{host}:{pid}:{ts base64}:{counter}:{port} [{connection labels}] {ip} [{user data}] [ERROR] {error stack trace}

Colors:

Colors will enable automatically

Force colors off

Use --no-color or --color=false

Force colors on

Use --color, --color=true or --color=always

License

Please see license.md