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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@phukon/duckduckgo-search

v1.2.0

Published

Search for text using DuckDuckGo's search engine with support for multiple backends, proxies, and region-specific results.

Readme

DuckDuckGo Search

Search for text using DuckDuckGo's search engine.

Features

  • 🔍 Text search functionality with rich results
  • 🌍 Region-specific searches
  • 🛡️ SafeSearch options
  • ⏰ Time-limited searches
  • 🔄 Multiple backend support (HTML and Lite)
  • 🌐 Proxy support
  • 📝 Comprehensive logging
  • 🔒 Optional SSL verification
  • 🎭 Random User-Agent rotation

Installation

npm install @phukon/duckduckgo-search
# or
pnpm add @phukon/duckduckgo-search

API Reference

DDGS Class Options

| Option | Type | Default | Description | | ------- | ------- | ------- | ------------------------------- | | headers | Object | {} | Custom HTTP headers | | proxy | string | null | Proxy server URL | | timeout | number | 10000 | Request timeout in milliseconds | | verify | boolean | true | Enable/disable SSL verification |

Search Options

| Option | Type | Default | Description | | ---------- | ------ | ---------- | ----------------------------------- | | keywords | string | Required | Search query | | region | string | 'wt-wt' | Region code (e.g. 'us-en', 'uk-en') | | safesearch | string | 'moderate' | SafeSearch level ('on', 'moderate', 'off') | | timelimit | string | null | Time restriction ('d', 'w', 'm', 'y') | | backend | string | 'auto' | Search backend ('auto', 'html', 'lite') | | maxResults | number | null | Maximum results to return |

Usage

Basic Search

import { DDGS } from "@phukon/duckduckgo-search";

const ddgs = new DDGS();
const results = await ddgs.text({
  keywords: "TypeScript tutorial",
  maxResults: 10,
});
console.log(results);

Advanced Options

import { DDGS, type SearchResult } from "@phukon/duckduckgo-search";

const ddgs = new DDGS({
  headers: { "Accept-Language": "en-US,en;q=0.9" },
  proxy: "http://proxy.example.com:8080",
  timeout: 15000,
  verify: false, // Disable SSL verification
});

const results: SearchResult[] = await ddgs.text({
  keywords: "TypeScript tutorial",
  region: "us-en",
  safesearch: "on",
  timelimit: "y", // Past year
  backend: "html",
  maxResults: 25,
});

CommonJS

const { DDGS } = require("@phukon/duckduckgo-search");

const ddgs = new DDGS();
const results = await ddgs.text({ keywords: "hello world" });

Error Handling

All error classes are exported and can be imported directly:

import {
  DDGS,
  DuckDuckGoSearchError,
  RatelimitError,
  TimeoutError,
} from "@phukon/duckduckgo-search";

try {
  const results = await ddgs.text({ keywords: "test" });
} catch (error) {
  if (error instanceof TimeoutError) {
    // Request timed out
  } else if (error instanceof RatelimitError) {
    // Rate limited or CAPTCHA — wait and retry
  } else if (error instanceof DuckDuckGoSearchError) {
    // General search error (base class for all the above)
  }
}

Exported Types

import type {
  SearchResult,
  Region,
  SafeSearch,
  TimeLimit,
  Backend,
} from "@phukon/duckduckgo-search";

Examples

See the examples/ directory for runnable examples covering every feature:

| Example | Feature | | ------- | ------- | | 01-basic-search.ts | Simplest usage | | 02-limit-results.ts | Limiting result count | | 03-region-search.ts | Region-specific results | | 04-safesearch.ts | Content filtering | | 05-time-filter.ts | Time-limited results | | 06-backend-selection.ts | HTML vs Lite backend | | 07-custom-timeout.ts | Timeout configuration | | 08-proxy-support.ts | Proxy routing | | 09-ssl-verification.ts | SSL verification toggle | | 10-custom-headers.ts | Custom HTTP headers | | 11-error-handling.ts | Typed error handling | | 12-all-options.ts | All options combined | | 13-commonjs-usage.cjs | CommonJS require() |

Roadmap

  • [x] Implement keyword search with HTML backend
  • [x] Random User-Agent rotation with browser impersonation
  • [x] Proxy support
  • [x] Custom timeout handling
  • [x] Region-specific searches
  • [x] Comprehensive logging system
  • [x] Error handling with custom errors
  • [x] SSL verification toggle
  • [ ] HTTP client that can impersonate web browsers (TLS fingerprinting)
  • [x] Lite backend implementation
  • [ ] News search functionality
  • [ ] Image search functionality
  • [ ] Video search functionality
  • [ ] Cookie management
  • [x] CI/CD Pipeline
  • [ ] Comprehensive test suite
    • [ ] Unit tests
    • [ ] Integration tests
    • [ ] E2E tests

Acknowledgments

Duckduckgo_search takes inspiration from the following projects:

📢 Disclaimer

This library is not affiliated with DuckDuckGo and is for educational purposes only. It is not intended for commercial use or any purpose that violates DuckDuckGo's Terms of Service. By using this library, you acknowledge that you will not use it in a way that infringes on DuckDuckGo's terms. The official DuckDuckGo website can be found at https://duckduckgo.com.