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

cron-webhook

v1.2.0

Published

Cron for querying data and triggering webhooks

Downloads

3

Readme

This module lets you set a cron job that notifies your webhook when data queried changes.

Setup

npm i --save cron-webhook

Minimal import and usage

const cronWebhook = require('cron-webhook').startCronWebhook

cronWebhook({
    querySettings: {
        query: url,
        webhook: webhookUrl
    }
})

This will perform every minute a get on the provided url and when data changes perform a get on webhookUrl.

Params

Additional parameters and configurations can be set.

import {
    CronWebHook, //class
    TYPE_XML, //facility for setting the CronWebHook to convert XML response to object
    TYPE_JSON, //facility for setting the CronWebHook to convert JSON response to object
    TYPE_PLAIN_TEXT, //facility for setting the CronWebHook to convert PLAIN_TEXT response to object
    startCronWebHook //facility if you don't care using the class
} from 'cron-webhook'

new CronWebHook({
    querySettings: {
        query: { // this can either be a url or an object made of method, url, parameters and body
            method: httpMethod, //'get', 'post'
            url: url,
            //...
        },
        webhook: { // this can either be a url or an object made of method, url, parameters and body
            method: httpMethod, //'get', 'post'
            url: url,
            //...
        },
    },
    objectParser: TYPE_XML | TYPE_JSON | TYPE_PLAIN_TEXT | (string) => JSON.parse(string), //optional, defaults to plain text, function that converts queried response to an object,
    objectTransformer: (bject) => object, //optional, defaults to identity, use it to filter out only part of the object you want to test for changes
    stateFilePath: stringStateFilePath, //optional, defaults to __tempState.json
    onStart: true, //optional, defaults to false, to make the webhook be notified on the first time,
    state: null, //optional, initial state. if not provided, it is read from stateFilePath
    equal: (s1, s2) => false, //optional, defaults to deepEqual, function that is called to check
    cronPattern: '* * * * *', //optional, defaults to * * * * *, that is every minute
})

Visit cron github project for cronPattern. Axios is used for http, so check its docs.