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

sight

v0.1.0

Published

Provide vision into a running instance of node

Downloads

8

Readme

But it works at my desk

Running connect/express based application is fast, and easy to configure. Once your app is up and running, debugging can get challenging.

The most difficult issues to solve are the distinct user based failures. These are issues that only show up in a production environment, for a certain set of users.

We need a way to dynamically debug individual user seesions, while on a production environment.. sight to the rescue.

How does Sight help?

sight is a connect/express middleware plugin, which allows a distinct per session view of web activity.

The session visibility is turned on by a cookie, and uniquely identified in your logs by an identifier for the life of that session.

There are built in plugins from sight to do some core logging to stdout, but can easily be configured to add in your own plugins for anything you can think of!

To start a session, have the target user hit a specific endpoint to drop a cookie. This endpoint can be used enable or disable sight for a session.

http://localhost:3000/sight_diagnostic?enabled=true&session=user1

This would give log entries such as this:

5 Aug 14:10:39 - Sight Trace user1: /javascripts/two.js

Now use that 'live' feedback data from that problematic user session to diagnose the failure scenario, while not affecting any other user session.

Setup

The first step is to install the package:

'npm install sight'

sight requires the connect 'cookieParser' middleware, so that must be included before the sight middleware is registered.

var sight=require('sight');

//.... setup express site here ...

// Cookie Parser is required middleware
app.use(express.cookieParser());
// Add in the main sight handler
app.use(sight.sight_handler);

sight defaults to include a per request logger to console out. See for advanced configuration options.

Usage

Once the middleware is configured, you can turn on sight session tracking by hitting the configured sight url (defaulting to /sight_diagnostic).

http://localhost:3000/sight_diagnostic?enabled=true&session=user1

To turn off the sight handling for a session, either clear the cookies on the client side or disable sight for this session:

http://localhost:3000/sight_diagnostic?enabled=false

To see a fully configured and running sample, fire up the example express application under the examples folder.

Custom sight plugins

To add a custom sight plugin, all that is needed is a function that takes a session id, the request object , and the response object. The registered plugins are chained together, allowing multiple actions for each sight session.

// custom diagnostic for sight to use
function my_sight_handler(session_id,req,res){
  // Add custom handler here!
  // Extra logs, email, post to another system, add cookies..all good!
  util.log("my_sight_handler for id: "+session_id+" on req: "+req.path);
}

The complete plugin chain must then be registered on the configuration method.

// If you want to override the default url end point and handlers, call the configure method 
// This case we will add 3 handlers:
//  1. sight url trace
//  2. sight url counter
//  3. Your own custom handler
sight.configureSight('sight_diagnostic',[sight.show_url_trace,sight.show_url_count,my_sight_handler]);

Anything else?

The sight diagnostic endpoint will take any query params, and drop them as cookies with a 'sight_' prefix. Leverage this to drop your own debuging cookies to use in your sight handlers orleverage on the client side for some more custom diagnostics.

http://localhost:3000/sight_diagnostic?my_tracker=verbose

Drops a cookie 'sight_my_tracker' with a value of verbose.