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 🙏

© 2025 – Pkg Stats / Ryan Hefner

googlesearch-js

v1.1.0

Published

A JavaScript library for searching Google, easily

Readme

googlesearch-js

A JavaScript library for searching Google, easily.

Installation

npm install googlesearch-js

Usage

Basic Usage

const { search } = require('googlesearch-js');

// Using async/await with for-await-of
async function searchGoogle() {
  // Get just the URLs (default behavior)
  for await (const url of search('javascript tutorials')) {
    console.log(url);
  }
}

searchGoogle();

Advanced Usage

const { search } = require('googlesearch-js');

async function searchGoogleAdvanced() {
  // Get full search results with title and description
  for await (const result of search('javascript tutorials', { advanced: true })) {
    console.log(`URL: ${result.url}`);
    console.log(`Title: ${result.title}`);
    console.log(`Description: ${result.description}`);
    console.log('---');
  }
}

searchGoogleAdvanced();

With Options

const { search } = require('googlesearch-js');

async function searchWithOptions() {
  const options = {
    numResults: 5,         // Number of results to fetch
    lang: 'fr',            // Language setting (e.g., 'en', 'fr', 'es')
    proxy: null,           // Proxy URL (e.g., 'http://user:pass@host:port')
    advanced: true,        // Return SearchResult objects with title and description
    sleepInterval: 1,      // Sleep 1 second between pagination requests
    timeout: 10,           // Request timeout in seconds
    safe: 'off',           // Safe search setting ('active', 'moderate', 'off')
    sslVerify: true,       // Verify SSL certificates
    region: 'fr',          // Region setting (e.g., 'us', 'uk', 'fr')
    startNum: 0,           // Start index for pagination
    unique: true           // Filter out duplicate results
  };

  for await (const result of search('javascript tutorials', options)) {
    console.log(result.toString());
  }
}

searchWithOptions();

Using with Promise.all

const { search } = require('googlesearch-js');

async function searchMultipleTerms() {
  const terms = ['javascript', 'node.js', 'react'];
  const searchPromises = terms.map(async (term) => {
    const results = [];
    for await (const url of search(term, { numResults: 3 })) {
      results.push(url);
    }
    return { term, results };
  });
  
  const allResults = await Promise.all(searchPromises);
  console.log(allResults);
}

searchMultipleTerms();

API

search(term, options)

Performs a Google search and returns results as an async generator.

Parameters:

  • term (string): The search query term
  • options (object, optional): Configuration options
    • numResults (number): Number of results to return (default: 10)
    • lang (string): Language code (default: 'en')
    • proxy (string|null): Proxy URL (default: null)
    • advanced (boolean): Whether to return advanced results (default: false)
    • sleepInterval (number): Sleep interval between requests in seconds (default: 0)
    • timeout (number): Request timeout in seconds (default: 5)
    • safe (string): Safe search setting ('active', 'moderate', 'off') (default: 'active')
    • sslVerify (boolean): Whether to verify SSL certificates (default: true)
    • region (string|null): Region code (default: null)
    • startNum (number): Start index (default: 0)
    • unique (boolean): Whether to return unique results (default: false)

Returns:

An async generator that yields either:

  • URL strings (if advanced is false)
  • SearchResult objects (if advanced is true)

SearchResult

A class representing a Google search result.

Properties:

  • url (string): URL of the search result
  • title (string): Title of the search result
  • description (string): Description of the search result

Methods:

  • toString(): Returns a string representation of the search result

getUserAgent()

Generates a random user agent string.

Returns:

A randomly generated user agent string.

Disclaimer

This library is for educational purposes only. Please be aware that scraping Google may violate their terms of service. Use responsibly and at your own risk.

License

MIT