Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

How to Use js-crawler to Crawl Websites with Node.js

A practical Node.js guide to installing js-crawler, controlling crawl depth and URL scope, handling callbacks, and configuring request limits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install js-crawler from npm, create a crawler, and call crawl() with a starting URL. Set its depth and URL filters to control how far it follows links, then use callbacks to handle fetched pages, failures, and completion. The package documentation describes HTTP and HTTPS crawling; it does not establish that it runs page JavaScript like a browser.

Install js-crawler

The project README documents installation with npm:

As an Amazon Associate I earn from qualifying purchases.

npm install js-crawler

The examples below use CommonJS, matching the README’s documented import pattern. Save the script in a Node.js project where the package is installed, then run it with Node.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start a basic crawl

This example starts at one URL, follows links up to depth three, and prints each successfully fetched page’s URL:

const Crawler = require("js-crawler").default;

new Crawler()
  .configure({ depth: 3 })
  .crawl("https://example.com", function onSuccess(page) {
    console.log(page.url);
  });

configure() is optional. The documented default depth is 2, meaning the crawler follows links outward from the starting page to that depth. In the success callback, the page object includes the URL, response content (usually HTML), and HTTP status; the README also documents response-related fields and a referer.

Handle successes, failures, and completion

Use the options-based form when you need separate callbacks for successful pages, inaccessible pages, and the end of the crawl:

const Crawler = require("js-crawler").default;

const crawler = new Crawler();
crawler.configure({ depth: 2 });
crawler.crawl({
  url: "https://example.com",
  success(page) {
    console.log("Fetched:", page.url, "status:", page.status);
  },
  failure(response) {
    console.error("Could not access page:", response.url, "status:", response.status);
  },
  finished(urls) {
    console.log("Crawl finished. URLs:", urls);
  }
});

The completion callback receives the collection of crawled URLs. A failure response’s status may be undefined, so do not assume every failed request includes an HTTP status code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Control which URLs are visited

Depth limits how many links outward from the starting page are followed. For more precise scope, distinguish between whether a candidate URL may be requested and whether links on a fetched page should be added to the queue:

  • shouldCrawl(url) decides whether a candidate URL is requested.
  • shouldCrawlLinksFrom(url) decides whether links found on a fetched page are added to the crawl queue.

For example, the following restricts requests to URLs on the example.com host while allowing link discovery only from its main page:

const Crawler = require("js-crawler").default;

const crawler = new Crawler();
crawler.configure({
  depth: 4,
  shouldCrawl(url) {
    return new URL(url).hostname === "example.com";
  },
  shouldCrawlLinksFrom(url) {
    return new URL(url).pathname === "/";
  }
});
crawler.crawl("https://example.com", page => console.log(page.url));

These are separate controls: allow a URL to be fetched with shouldCrawl, and decide whether it can lead the crawler to more URLs with shouldCrawlLinksFrom. Choose filters that match the site’s URL patterns and the pages you actually need.

Set request limits and other options

The README documents these options and defaults:

Option Documented default Purpose
depth 2 How many links outward from the start page are followed.
ignoreRelative false Whether relative URLs are skipped.
userAgent crawler/js-crawler Request user-agent string.
maxRequestsPerSecond 100 Upper request-rate limit.
maxConcurrentRequests 10 Maximum number of active requests.

Request rate and concurrency limit different things: one caps the number of requests issued per second, while the other caps simultaneous active requests. The actual rate also depends on network speed. For a gentler crawl, the README shows setting a rate of two requests per second:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const Crawler = require("js-crawler").default;

const crawler = new Crawler();
crawler.configure({
  maxRequestsPerSecond: 2,
  maxConcurrentRequests: 2
});
crawler.crawl("https://example.com", page => console.log(page.url));

The rate setting is an upper limit, not a promise that the crawler will reach two requests per second. Set limits appropriate to the site and your use, and check applicable site terms and policies; technical throttling alone does not establish permission to crawl.

Reuse an instance deliberately

A crawler instance remembers URLs it has already crawled and, by default, will not crawl them again. To crawl those URLs again, clear that memory with forgetCrawled, as documented by the project, or create a new crawler instance. This matters when you run multiple crawl passes in the same process.

Know what js-crawler does—and what is not established

The project describes js-crawler as a Node.js web crawler supporting HTTP and HTTPS. Its documented callbacks expose response content, usually HTML. The README does not establish that it executes page JavaScript or renders browser-driven content. If important text or links appear only after client-side scripts run, the documented behavior is not enough to assume those elements will be available in the response.

For a page image rather than a link-and-content crawl, ScreenshotNeo is a separate option: it provides website screenshots through an API and MCP server. Learn more at ScreenshotNeo.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot common problems

  • The import is undefined or fails: Check that js-crawler is installed in the project from which you run Node and use the README’s CommonJS form, require("js-crawler").default.
  • The crawl finishes without the pages you expected: Check the configured depth and both URL-filter callbacks. Also check whether relative URLs are being skipped with ignoreRelative.
  • A failure has no status code: The documented failure response may have an undefined status. Treat failure as possible even when no HTTP status is available.
  • The crawl seems slower than the configured rate: maxRequestsPerSecond is a ceiling, not a target; network speed and the concurrency cap can limit throughput.
  • JavaScript-rendered content is missing: The README does not document browser execution. Do not assume the crawler renders scripts; determine whether the needed content is present in the HTTP response.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot rather than a crawl of links and response HTML, ScreenshotNeo takes a URL in one GET request. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status. Its MCP server offers screenshot tools for AI agents, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

Frequently Asked Questions

Does js-crawler support HTTPS?

Yes. The project describes support for both HTTP and HTTPS.

Can I crawl the same URLs again with the same instance?

Yes. Clear the instance’s remembered URLs with `forgetCrawled`, or make a new crawler instance.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.