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

sitesampler

v4.0.5

Published

Sample website text content over time.

Downloads

48

Readme

node-sitesampler

npm version Build Status Dependency Status devDependency Status

Data collection sometimes includes collecting the same data over time. This module, which is basically a wrapper around needle-schedule, enables you to collect e.g. the html content of websites over time and (optionally) store the data with the chronostore module, thus sampling sites. On top of storing the results as files, it also emits the results when collected, enabling you to further process the data, e.g. pushing the data to a database.

A heavy emphasis is put on stability and logging. Everything, even the logging provided by bunyan, is covered with tests. It also allows you to forward your logging to the console, loggly, logentries and slack.

Linted with ESLint, tested with tape and 100% coverage with covert.

Installation

npm install sitesampler

Logging

Logging is performed by bunyan and all logging is enabled with env vars. For instance, to run the example with logging turned on, run the command SITESAMPLER_LOG=1 node example.js.

loggly

Logging can be posted to loggly by setting the following env vars:

  • SITESAMPLER_LOGGLY_SUBDOMAIN: your loggly subdomain.
  • SITESAMPLER_LOGGLY_TOKEN: your loggly token.
  • SITESAMPLER_LOGGLY_LEVEL: the level to log. Defaults to info.

logentries

Logging can be posted to logentries by setting the following env vars:

  • SITESAMPLER_LOGENTRIES_TOKEN: your logentries token.

slack

Logging can be posted to slack by setting the following env vars:

  • SITESAMPLER_SLACK_WEBHOOKURL: your slack webhook url.
  • SITESAMPLER_SLACK_CHANNEL: your slack channel. Defaults to the channel of the webhook.
  • SITESAMPLER_SLACK_LEVEL: the level to log. Defaults to info.
  • SITESAMPLER_SLACK_USERNAME: the username to post with. Defaults to sitesampler.

Methods

sitesampler([settings])

When instantiating the sitesampler, it requires settings to work. Settings is thus either an object or a path to a json file containing the settings.

settings (object | string): object with settings or path to settings. Defaults to ./sitesampler.json. Properties:

  • targets (object) - an array of targets for the schedule-schedule module under the hood.
  • options (object) - default options that will be passed through to schedule-schedule. See example below or sitesampler.default.json.
  • chronostore (object) - default options that will be passed through to chronostore. If not defined, nothing will be written to disk. To use chronostore defaults, pass an empty object {}.
  • rethrowErrors (object) - whether sitesampler should rethrow eerrors from goldwasher and chronostore. Defaults to true.

sitesampler.start()

Starts the sitesampler.

sitesampler.stop()

Stops the sitesampler.

Events

Sitesampler is an event emitter that will emit collected results or when an error is encountered. See the example below. Remember to handle errors or your program will crash if an error is encountered. This will, however, usually only happen if you point it at something that isn't HTML.

Example

var sitesampler = require('sitesampler');
var ss = sitesampler('sitesampler.default.json');

ss.on('response', function(result) {
  console.log(result);
});

ss.on('error', function(error) {
  console.log(error);
});

ss.start();

sitesampler.default.json

{
  "targets": [
    {
      "url": "http://www.github.com",
      "rule": { "second": [15, 35, 55] }
    }
  ],
  "options": {
    "rule": { "second": [1] },
    "needleRetry": {
      "retries": 10
    }
  },
  "chronostore": {
    "root": "./chronostore"
  }
}