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

multiple-url-poller

v2.0.0

Published

Polls URLs and notifies upon changes

Downloads

4

Readme

URL Poller

Build Status Code Climate Test Coverage Issue Count npm npm

A fully customizable url poller and notifier

Features

  • polls multiple urls
  • customizable poll interval
  • creates a diff between the previous and current version upon changes
  • handles HTTP authentication and any other option from the request library
  • emits changes and notifies using RxJS giving you lots of possibilities to fit your needs

Set up

In the console run:

npm install multiple-url-poller

Include the poller:

const Poller = require('multiple-url-poller').Poller;

Example

Polling a website that displays current time and log diffs to the console

const Poller = require('multiple-url-poller').Poller;

let interval = 5 * 1000;  // time in miliseconds
let urls = ['https://time.is/'];
let poller = new Poller({ interval, requests: urls });
let diffs$ = poller.getDiffObservable();
let subscription = diffs$
  .subscribe(changesNotification => console.log('New diff', changesNotification.diff));

poller.start();

Polling a website that requires user authentication

const Poller = require('multiple-url-poller').Poller;

let interval = 5 * 1000;  // time in ms
let requests = [{
  url: 'https://supersecurewebsite.com/guarded-resource',
  auth: {
    user: 'username',
    pass: 'secretpassword'
  }
}];
let poller = new Poller({ interval, requests });
let diffs$ = poller.getDiffObservable();
let subscription = diffs$
  .subscribe(changesNotification => console.log('New diff', changesNotification.diff));

poller.start();

Documentation

The idea of this poller is to fetch contents of websites in certain intervals and compare consecutive ones to check whether any changes were introduces to those websites.

One use case of such a package is an email notifier for college test results. In my college we usually do not get notified at all about the results from tests, so by setting up this poller to query lectrers' websites I can send myself (and other people from my class) email (using nodemailer) about the results.

The only thing exposed in this package is the Poller class:

  • new Poller(options) - creates a new poller instance. It has to be started with the start method.

    Possible options:

    • interval (optional) - number of miliseconds between two consecutive polls. The default is 60 seconds.
    • requests - array of urls/request options that will be polled. It may contain either urls as strings or options objects that comply with the format expected by the request library (see [request library documentation] for more information)

Poller instance methods:

  • start() - begins polling. First batch of requests is sent immediately, each following batch of requests will be sent after the interval specified in the options provided when creating a poller.

  • stop() - stops the poller and clears the cache.

  • pause() - pauses the poller, resetting the interval.

  • resume() - resumes the poller after it has been paused. Same as with start, initial requests are sent immediately.

  • getDiffObservable() - returns the RxJS observable that all diffs will be emitted to.

    Objects in the observable implement the following interface:

    interface ChangesNotification {
      isInitialDiff: boolean;
      requestOptions: string | Object; // the url/options that those changes came from
      url: string; // the url extracted from requestOptions
      diff: SingleDiff[]; // array of single diffs (see below)
      body: string; // contents of the website
    }

    The SingleDiff object is the same as the diff object from js-diff library.

  • getErrorObservable() - returns the RxJS observable that emits error upon request errors.

    Objects in the observable implement the following interface:

    interface RequestError {
      url: string;  // same as in ChangesNotification
      requestOptions: string | Object;  // same as in ChangesNotification
      error: Object;  // error emitted by the `request` library
    }

Contributing

If you would like to suggest a feature or report a problem please use the Issues tab on GitHub.

All pull requests are welcome! Before creating one, make sure there are no problems by running the following commands:

npm run lint
npm test

Creating unit tests for new features in your pull requests would also be splendid, although it is not required.

Author

The author of this project is Grzegorz Rozdzialik.