Skip to content
AravindRajeshkannaPublic

About

Node.js web crawler to crawl the entire web

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

arkrawler

CI

A small Node.js web crawler that starts from a list of ~1,000,000 seed URLs (seed.json), stores the frontier in Redis, and keeps crawling by respawning a worker process that pulls a random batch of URLs, fetches them, extracts outbound links, and feeds them back into the seed set.

How it works

  • index.js loads seed.json into a Redis set (seeds), then spawns crawler.js as a child process and respawns it every time it exits, so the crawl continues indefinitely.
  • crawler.js pulls a random batch of URLs out of the seeds set, crawls them with crawler, parses each page with Cheerio, and adds every absolute http(s) link it finds back into seeds. Once it has crawled PAGES_PER_RUN pages it exits cleanly, which triggers the next respawn from index.js.
  • lib/ holds the small, dependency-light pieces of logic (config, seed-file parsing, link extraction) that are covered by unit tests in test/; test/integration/ covers the crawl loop end-to-end against a real Redis instance.

Prerequisites

Setup

npm install

Configuration is read from environment variables (see .env.example for the full list and defaults):

cp .env.example .env
# edit .env if you need to point at a non-default Redis instance, etc.

Usage

npm start
# or, to load .env automatically:
node --env-file=.env index.js

This seeds Redis from seed.json and starts the crawl loop. Stop it with Ctrl+C.

Variable Default Description
REDIS_URL redis://127.0.0.1:6379 Redis connection string
SEED_FILE ./seed.json Path to the seed URL JSON file
SEEDS_KEY seeds Redis set used to store the crawl frontier
PAGES_PER_RUN 1000 Pages crawled per crawler.js run before exit
MAX_CONNECTIONS 100 Max concurrent HTTP connections while crawling

Development

npm test               # run the unit test suite (node:test, no external deps)
npm run test:integration  # run crawler.js end-to-end against a real Redis instance
npm run test:coverage     # unit tests with Node's built-in coverage report
npm run lint            # lint with ESLint
npm run format           # format with Prettier

npm run test:integration requires a reachable Redis (it uses REDIS_URL, same as the app) and spins up a throwaway local HTTP server as the crawl target — it doesn't hit the network. It writes to a randomly-named Redis set (via SEEDS_KEY) and deletes it afterwards, so it's safe to run against a Redis instance you're also using for local development. If Redis isn't reachable, the test is skipped rather than failing.

CI (see .github/workflows/ci.yml) runs lint, formatting, unit tests, and the integration test (with a Redis service container) on every push and pull request.

See CONTRIBUTING.md for the full contribution workflow.

Project docs

About

Node.js web crawler to crawl the entire web

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages