# NPM Package Scraper (`ef12/npm-package-scraper`) Actor

Search npm packages, get package metadata, download counts, version history, and dependencies. Track trending packages by download volume using the npm registry API.

- **URL**: https://apify.com/ef12/npm-package-scraper.md
- **Developed by:** [Daniel Wilson](https://apify.com/ef12) (community)
- **Categories:** Developer tools
- **Features:** Limited permissions
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 per results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## NPM Package Scraper

**Discover, analyze, and export npm package data** — metadata, download counts, version history, and dependencies — all through the public npm registry API. No browser, no HTML parsing, no authentication required.

This [Apify Actor](https://apify.com/actors) uses the official [npm registry API](https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md) and the [npm downloads API](https://github.com/npm/download-counts) to deliver structured JSON data about any npm package or set of packages. It supports three modes — **search**, **package details**, and **trending** — making it suitable for market research, dependency auditing, version tracking, and data integration pipelines.

### Why use NPM Package Scraper?

The npm registry is the largest software package registry in the world, hosting over 2 million packages. Whether you are a developer evaluating dependencies, a team lead auditing security posture, or a researcher analyzing the JavaScript ecosystem, this Actor gives you programmatic access to package data at scale. Instead of hitting the registry API ad-hoc with curl and stitching results together, you get a clean, repeatable pipeline that pushes data directly to Apify datasets for export, API access, or integration with tools like Zapier, Make, or Google Sheets.

### Features

- **Search mode** — Query the npm registry like you would on npms.io, getting structured results with keywords, author info, and download counts.
- **Package mode** — Fetch deep metadata for a single package: all version numbers, maintainers, dependency tree, full description, and the first 500 characters of its readme.
- **Trending mode** — Discover the most downloaded packages in any period, sorted by download volume. Ideal for monitoring ecosystem trends.
- **Download statistics** — Optionally include download counts for any period (last day, week, month, or year) using npm's official downloads API.
- **Batch download fetching** — Download counts are fetched in batches of up to 50 packages at a time for maximum efficiency.
- **PPE pricing** — The Actor uses Apify's pay-per-event model, charging only $0.002 per result after 10 free results per run.
- **No authentication** — The npm registry and downloads APIs are fully public. No token, API key, or login required.

### Use Cases

#### Dependency evaluation

When evaluating a new npm dependency for your project, run this Actor in **package mode** to get the latest version, license type, dependency tree, author, and download trends in one shot. Compare multiple packages side by side in the output dataset.

#### Ecosystem monitoring

Use **trending mode** on a schedule (e.g., weekly via Apify scheduler) to track which packages are gaining or losing traction. The download counts are pulled directly from the npm downloads API, so you get accurate, official numbers.

#### Security and license auditing

Export the license field and maintainer list for all your project dependencies. Run a **search** for packages in your dependency tree and push the structured output to a dataset for review. The Actor can be integrated with Apify's API to feed into your compliance pipeline.

#### Market research

Search for packages by keyword (e.g., "web framework", "state management", "testing") and get ranked results with download counts. Understand which libraries dominate each category, who maintains them, and how active they are.

#### Version history tracking

In **package mode**, the Actor returns the full list of versions ever published, plus the `last_modified` date from the package's time metadata. Use this to track release cadence or check if a package is actively maintained.

#### Data pipeline enrichment

The Actor's structured JSON output is easy to consume from scripts, tools, and APIs. Run it automatically with Apify's scheduler and feed the results into a database, dashboard, or notification system.

### How to use NPM Package Scraper

1. **Open the Actor** — Go to the Actor's page in Apify Console and click **Try** or **Run**.
2. **Configure input** — Select a mode and fill in the relevant fields. For a quick test, set mode to **search**, query to `"fast web framework"`, and max results to 5.
3. **Run the Actor** — Click **Start** and watch the results stream in. The Actor finishes in a few seconds since it's calling APIs, not rendering browsers.
4. **Export the data** — Once the run completes, download the dataset as JSON, CSV, Excel, or HTML from the **Output** tab. You can also access it programmatically via the Apify API.

#### Input

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| mode | string | `search` | One of `search`, `package`, or `trending` |
| query | string | `""` | Search query (required for search mode) |
| package_name | string | `""` | Exact package name (required for package mode) |
| period | string | `last-month` | One of `last-day`, `last-week`, `last-month`, `last-year` |
| max_results | integer | 25 | Maximum results (max 250) |
| include_downloads | boolean | true | Whether to fetch download counts |

#### Output

Each result is an object pushed to the dataset with the following fields:

```json
{
  "name": "express",
  "version": "4.21.2",
  "description": "Fast, unopinionated, minimalist web framework",
  "keywords": ["web", "framework", "http", "rest", "middleware"],
  "author": "TJ Holowaychuk",
  "date": "2024-12-05T17:33:38.618Z",
  "downloads": 18420342,
  "license": "MIT",
  "repository": "https://github.com/expressjs/express.git",
  "homepage": "https://expressjs.com",
  "readme": "# Express\n\nFast, unopinionated, minimalist web framework for Node.js...",
  "versions": [],
  "dependencies": {},
  "last_modified": ""
}
```

In **package mode**, the `versions`, `dependencies`, and `last_modified` fields are fully populated. The `readme` field is present in both modes but only filled in package mode (truncated to 500 characters).

### Pricing

This Actor uses Apify's **pay-per-event (PPE)** pricing model:

- **apify-actor-start**: $0.00005 per run
- **result**: $0.002 per result after the first **10 free results** per run

For example, a search returning 25 results costs 15 × $0.002 = $0.03 (plus the start event). Most runs complete in under 5 seconds.

### Performance tips

- **Prefer search mode** for broad discovery — it fetches results directly from the npm search index, which is fast and returns rich metadata without needing individual package API calls.
- **Use trending mode** with `last-year` to discover established popular packages, or `last-week` for what's gaining momentum right now.
- **Disable `include_downloads`** if you only need metadata — this skips the additional download API calls and speeds up the run by 30-50%.
- **Keep `max_results` under 100** for most use cases. The registry API limits search to 250, but larger result sets take proportionally longer to fetch download counts for.

### Limitations

- The Actor depends on the public npm registry API at `registry.npmjs.org` and the downloads API at `api.npmjs.org`. Both are rate-limited but generous; heavy concurrent usage may result in occasional 429 responses.
- The search endpoint returns a maximum of 250 results per query.
- Readme content is truncated to 500 characters to keep payload sizes manageable.
- Private npm packages behind authentication are not supported — the Actor uses public endpoints only.

### FAQ

**Do I need an npm token or API key?** No. Both the registry API and downloads API are fully public and require no authentication.

**Can I scrape all packages in an organization (@scope)?** Yes. In search mode, use a query like `@myorg` or `@scope` to find scoped packages. In package mode, use the full scoped name (e.g., `@angular/core`).

**Are download counts accurate?** Yes. The downloads API is the official npm download count service, maintained by the npm registry team. It returns exact per-day download numbers for the requested period.

**Can I run this on a schedule?** Yes. Deploy the Actor to Apify and use the **Scheduler** feature to run it daily, weekly, or monthly.

### Support

Found a bug or have a feature request? Open an issue on the [GitHub repository](https://github.com/apify/apify-web-scraper) or contact Apify support through the Console.

### Legal disclaimer

This Actor accesses the public npm registry API, which is an officially documented, rate-limited public API. Usage of the data obtained through this Actor is subject to npm's Terms of Service. The data retrieved is publicly available metadata about npm packages. The creators of this Actor are not responsible for how users utilize the extracted data.

# Actor input Schema

## `mode` (type: `string`):

Scraping mode: search packages by query, fetch a single package's details, or get trending packages sorted by downloads

## `query` (type: `string`):

Search query to find packages (used in search mode only)

## `package_name` (type: `string`):

Exact npm package name to fetch (used in package mode only, e.g. express, lodash)

## `period` (type: `string`):

Time period for download statistics

## `max_results` (type: `integer`):

Maximum number of results to return (max 250)

## `include_downloads` (type: `boolean`):

Whether to fetch download counts for each package

## Actor input object example

```json
{
  "mode": "search",
  "query": "",
  "package_name": "",
  "period": "last-month",
  "max_results": 25,
  "include_downloads": true
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("ef12/npm-package-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("ef12/npm-package-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call ef12/npm-package-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ef12/npm-package-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/SI5ePA4ITLTOFuSZD/builds/0B9BlEMeY4VhegGpC/openapi.json
