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

@unumux/spiderpig

v1.2.0

Published

SpiderPig is a node library used to crawl websites to provide a list or URLs. It also supports logging in to password protected sections

Downloads

2

Readme

SpiderPig

SpiderPig is a node library used to crawl websites to provide a list or URLs. It also supports logging in to password protected sections

Installation

  • npm install @unumux/spiderpig

Usage

  1. Import or require the library
    • import Crawler from "@unumux/spiderpig";
    • or const Crawler = require("@unumux/spiderpig");
  2. Create a crawler instance, and pass in crawler options
    const crawler = new Crawler({
        url: "http://localhost:3000",
        concurrent: 1,
        delay: 300
    });
  3. Listen for crawler events
    crawler.on("passing_link_found", (item) => {
        console.log(item);
    });
    
    crawler.on("finished", () => {
        console.log("Finished!");
    });
  4. Start the crawler
    crawler.start();

Crawler Options

The crawler can receive the following options:

  • url (required): string or array of strings for the URL. Currently all links that include this in it will be scanned. So if url is http://localhost:3000, http://localhost:3000/test1/subtest1 and http://localhost:3000/test2/subtest2 would be found. If it was set to http://localhost:3000/test1, only http://localhost:3000/test1/subtest1 would be found.
  • concurrent (default: 2): Number of concurrent scans (or threads) to run. It's useful to run 2+, as running a single thread can cause the entire scan to hang if the page takes a long time to load. Just don't use so many that it puts unnecesary load on your web server
  • delay (default: 300): Delay between requests. This is useful to prevent putting unnecessary load on the webserver
  • login (default: false): If the site you're working on requires a login, the following items should be set. This feature may or may not work, depending on your login system. The key values in the form object should map to the name properties of the inputs on the login screen.
login: {
    url: "https://localhost:3000/my-login-url",
    form: {
        username: "testLogin",
        password: "testPassword",
        RememberMe: true
    }
}
  • exclude (default: []): Array of exclusion patterns of pages that should not be scanned. These should be RegExp patterns:
exclude: [
    new RegExp(".*\.pdf$"),
    new RegExp(".*\.(mp4|mp3|pptx|doc|docx|ppt|mp3|png|jpg|xls|xlsx|ppsx)$"),
    new RegExp(".*Logout.*"),
]

Crawler Events

The following events are availble on the crawler instance

  • queue_updated - fired when an item is added to the queue. Passes the entire queue as an argument
  • request_start - fired when an attempt to load a queue item starts. Passes the individual queue item
  • passing_link_found - fired when a link in the queue loads. Passes the individual queue item (URL) that passed, and an object containing the entire response (in the format of { response })
  • failing_link_found - fired when a link in the queue fails to load. Passes the individual queue item that failed
  • finished - fired when the entire queue has been processed