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

archivejs

v1.0.0

Published

Node module to archive entire websites.

Downloads

4

Readme

archivejs

A Node module to archive websites. The module attempts to scan websites and download as many pages as it can find.

const Archive = require('archivejs');
const site = new Archive('http://example.com', {
  threads: 2
});

site.start();

Installation

$ npm install archivejs

Example:

This module works by downloading as much of a website as possible. If a website existed with the following urls:

http://example.com

http://example.com/image.png

http://example.com/docs

http://example.com/docs/user.json

The website would be saved with the following folder structure:

  • example.com
    • image.png.archive
    • docs
      • user.json

archives\example.com\.archive

archives\example.com\image.png.archive

archives\example.com\docs\.archive

archives\example.com\docs\user.json.archive


For example, if reddit.com was archived, the page requested when visiting reddit.com would be saved in the folder reddit.com with the file name .archive (or index.archive).

The main limitation is that only pages that are linked can be archived. Any pages hidden or not referenced to from the main page or subsequent scraped pages are not downloaded.

Usage

Instantiate the archive class as per the example above (new Archive(url, options)).

To start archiving: site.start();

To stop archiving: site.stop();

To attach event listeners: site.on(eventName, callback);

For a full example, refer to example.js.

You can pass options when creating an archive by passing an object after the URL:

  • threads - the number of workers to scrape the site in parallel, defaults to 1
  • path - the root path of the directory to save the archives, defaults to __dirname
  • requestDelay - the time in milliseconds to wait before making another request after scraping a page, defaults to 50

Features

  • downloads pages to a given folder
  • scrapes pages for resources such as .css or .js files
  • downloads images and svg files from pages (from image elements)
  • find links between pages to repeat the download/scrape process

TODO:

  • video downloads
  • proxy support to prevent rate limiting

Events

Event listeners can be attached to the archive to monitor progress and get statistics.


scrape

  • url the url being requested/scraped

Emitted just before a page is scraped.


link

  • url - new url that was found when scraping, and will be added to the queue to be scraped

Emitted when parsing a page and a link is found.


saved

  • data - object containing data about the page saved
    • fileName - name of the file saved
    • path - path relative to the archive project root
    • fullPath - full path of the file on disk
    • size - size of the file in bytes
    • stats - object providing stats about the entire archive progress
      • size - total size in bytes downloaded and saved to disk
      • saved - number of pages saved so far

Emitted every time a page is downloaded and saved to disk.


error

  • message - message providing context
  • error - the errow that was thrown

Emitted every time an error occurs. An event listener needs to be set up for this event to prevent errors from being thrown.


debug

  • message - debug info