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

pipend-spy

v0.1.0

Published

[![Build Status](https://travis-ci.org/Pipend/pipend-spy.svg?branch=master)](https://travis-ci.org/Pipend/pipend-spy) [![Coverage Status](https://coveralls.io/repos/Pipend/pipend-spy/badge.svg?branch=master&service=github)](https://coveralls.io/github/

Downloads

34

Readme

Build Status Coverage Status

Spy

Spy is a database agnostic event recording library for node.js.

Install

  • npm install pipend-spy
  • (Optional) next, run npm run download-ip-country-db in the directory of this package which downloads the ip country database (IP-COUNTRY.BIN file) to the data directory of the said package, by default it uses the free lite version from http://download.ip2location.com/lite/, but you can use a licensed version for more accuracy instead, just make sure you rename the bin file to IP-COUNTRY.BIN

Usage

Spy exports a function with the signature [StorageDetails] -> Spy, i.e. it takes a collection of storage details (see the StorageDetails section for information about the different stores supported) and returns an object with 2 methods, record & recordReq.

  • livescript
{record, record-req} = (require \pipend-spy) do 
    * name: \mongo
      connection-string: \mongodb://localhost:27017/test
      connection-options: {}
      insert-into:
        collection: \events
    ...

event =  
    event-type: \visit
    user-id: 1234567890
    session-id: 1234567890

record event .then (inserted) ->
    console.log \event-inserted, inserted

app.get \/, (req, res) ->
    record-req req, event .then (inserted) -> console.log \event-inserted-with-req, inserted
    res.end \hello
  • javascript
spy = require("pipend-spy")([{
  name: "mongo",
  connectionString: "mongodb://localhost:27017/test",
  connectionOptions: {},
  insertInto: {
    collection: "events"
  }
}]);

event = {
  eventType: "visit",
  userId: 1234567890,
  sessionId: 1234567890
}

spy.record(event).then(function(inserted){
  console.log("event-inserted", inserted);
});

app.get("/", function(req, res){
  spy.recordReq("event").then(function(inserted){
    console.log("event-inserted-with-req", inserted);
  });
  res.end("hello");
});

Supported Stores

  • MongoDB :
{
    "name": "mongo"
    "connectionString": "mongodb://host:port/database"
    "connectionOptions": {} // passed directly to the node.js mongodb driver as connectionOptions
    "insertInto": {
        "collection": "collection" // name of the mongodb collection to insert data into
    }
}
  • Redis :
{
    "name": "redis"
    "connectionString": "redis://host:port/database"
    "connectionOptions": {}
    "insertInto": {
        "channel": "channel"
    }
}

Methods

| Name | Type | Description | |-------------|---------------------------------------|--------------------------------| | record | Event -> p [InsertedEvent] | spy.record({}), accepts any JSON object and returns a collection of objects inserted - one for each store - wrapped in a Promise | | recordReq | Request -> Event -> p [InsertedEvent] | spy.recordReq(req, {}), extends the JSON object - passed in as the last argument - with "useful" information from the node.js request object - passed in as the first argument - |

Information captured from the request object

When using Spy.recordReq method, Spy adds the following information to the event object (for example):

{
    "creationDate": "2015-01-01T00:00:00.000Z",
    "creationTime": 1420056000000,
    "ip": "127.0.0.1",
    "ipTokens": {
        "ip2": "127.0",
        "ip3": "127.0.0"
    },
    "country": "-",
    "headers": {
        "userAgent": "test"
    },
    "uaTokens": {
        "ua": "",
        "browser": {},
        "engine": {},
        "os": {},
        "device": {},
        "cpu": {}
    },
    "url": "http://://localhost",
    "queryTokens": {}
}

Note: creationTime & creationDate are also added by the Spy.record method.

Status

Needs more unit tests & stores.

Development

  • npm install
  • run npm run download-ip-country-db to download ip-country data
  • run gulp to build & watch
  • npm test & npm run coverage for unit testing and coverage reports