# 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
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# 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("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=ef12/npm-package-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "NPM Package Scraper",
        "description": "Search npm packages, get package metadata, download counts, version history, and dependencies. Track trending packages by download volume using the npm registry API.",
        "version": "0.0",
        "x-build-id": "0B9BlEMeY4VhegGpC"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/ef12~npm-package-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-ef12-npm-package-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/ef12~npm-package-scraper/runs": {
            "post": {
                "operationId": "runs-sync-ef12-npm-package-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/ef12~npm-package-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-ef12-npm-package-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "mode": {
                        "title": "Mode",
                        "enum": [
                            "search",
                            "package",
                            "trending"
                        ],
                        "type": "string",
                        "description": "Scraping mode: search packages by query, fetch a single package's details, or get trending packages sorted by downloads",
                        "default": "search"
                    },
                    "query": {
                        "title": "Search Query",
                        "type": "string",
                        "description": "Search query to find packages (used in search mode only)",
                        "default": ""
                    },
                    "package_name": {
                        "title": "Package Name",
                        "type": "string",
                        "description": "Exact npm package name to fetch (used in package mode only, e.g. express, lodash)",
                        "default": ""
                    },
                    "period": {
                        "title": "Download Stats Period",
                        "enum": [
                            "last-day",
                            "last-week",
                            "last-month"
                        ],
                        "type": "string",
                        "description": "Time period for download statistics",
                        "default": "last-month"
                    },
                    "max_results": {
                        "title": "Max Results",
                        "minimum": 1,
                        "maximum": 250,
                        "type": "integer",
                        "description": "Maximum number of results to return (max 250)",
                        "default": 25
                    },
                    "include_downloads": {
                        "title": "Include Download Counts",
                        "type": "boolean",
                        "description": "Whether to fetch download counts for each package",
                        "default": true
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
