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

global-json-request-logger

v1.0.0

Published

This module configures the http and https modules to raise logging events for every outgoing request.

Downloads

2

Readme

Node.js Global Request Logger

This is a publicly available library published by Earnest.

This public module configures the http and https modules to raise logging events for every outgoing http request.

Any library or module that uses the default http and https modules will be captured. The primary use case is for centrally adding logging to all outbound api calls to third-party services without needing to manipulate those modules.

The logger will capture request and response arguments as well as the body sent or received.

Example

An example log object for a call to https://www.google.com:

Request

{ protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'www.google.com',
  port: null,
  hostname: 'www.google.com',
  hash: null,
  search: null,
  query: null,
  pathname: '/',
  path: '/',
  href: 'https://www.google.com/',
  method: 'GET',
  headers: { host: 'www.google.com' },
  body: '' 
}

Response

{ statusCode: 200,
  headers:
   { date: 'Sun, 17 Aug 2014 20:03:02 GMT',
     expires: '-1',
     'cache-control': 'private, max-age=0',
     'content-type': 'text/html; charset=ISO-8859-1',
     'set-cookie':
      [ 'PREF=ID=29ba00825c529e14:FF=0:TM=1408305782:LM=1408305782:S=7FwX1DADc9nIkUE1; expires=Tue, 16-Aug-2016 20:03:02 GMT; path=/; domain=.google.com',
        'NID=67=qAT-ji1lswEweR4BMbdLhdZHczj54O6s-OSFgH_rcjXLpOtjej9OR8ADiptMVjARY1hTWPadfixc3lZkfX41XuLFKK_B2J-hsEFHEdxkiL2IAW_AUyZ1MDYUs-Z8_l8q; expires=Mon, 16-Feb-2015 20:03:02 GMT; path=/; domain=.google.com; HttpOnly' ],
     p3p: 'CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."',
     server: 'gws',
     'x-xss-protection': '1; mode=block',
     'x-frame-options': 'SAMEORIGIN',
     'alternate-protocol': '443:quic',
     'transfer-encoding': 'chunked' },
  trailers: {},
  httpVersion: '1.1',
  url: '',
  method: null,
  body: '<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en">...</html>' }

Usage

To enable logging events initialize the global logger:

var globalLog = require('global-request-logger');
globalLog.initialize();

This will now raise success and error events for every http or https request:

globalLog.on('success', function(request, response) {
  console.log('SUCCESS');
  console.log('Request', request);
  console.log('Response', response);
});

globalLog.on('error', function(request, response) {
  console.log('ERROR');
  console.log('Request', request);
  console.log('Response', response);
});

You may optionally disable logging using the end function:

globalLog.end();

Options

The initialize function accepts an options argument that can configure logging.

  • maxBodyLength - The maximum length (in bytes) to log for a request or response body.

Contributing

To get started, take a look at the output of ./go help. Then, run ./go to configure the environment and dependencies.

Getting Started:

Usage: ./go

Available commands are: help Show this help exec Execute any command inside the dev image nuke Destroy all your running containers prepush Run prepush checks (e.g. test, lint) test Run all tests test:watch Run tests in watch mode install Install dependencies lint Lint the repository lint:fix Lint in fix mode

You can pass any of those as an argument to run the related task in this repository.

Testing

Use either ./go test or ./go test:unit to run