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 🙏

© 2024 – Pkg Stats / Ryan Hefner

libnpmsearch

v8.0.0

Published

Programmatic API for searching in npm and compatible registries.

Downloads

2,892,128

Readme

libnpmsearch

npm version license CI - libnpmsearch

libnpmsearch is a Node.js library for programmatically accessing the npm search endpoint. It does not support legacy search through /-/all.

Table of Contents

Example

const search = require('libnpmsearch')

console.log(await search('libnpm'))
=>
[
  {
    name: 'libnpm',
    description: 'programmatic npm API',
    ...etc
  },
  {
    name: 'libnpmsearch',
    description: 'Programmatic API for searching in npm and compatible registries',
    ...etc
  },
  ...more
]

Install

$ npm install libnpmsearch

API

opts for libnpmsearch commands

The following opts are used directly by libnpmsearch itself:

  • opts.limit - Number of results to limit the query to. Default: 20
  • opts.from - Offset number for results. Used with opts.limit for pagination. Default: 0
  • opts.detailed - If true, returns an object with package, score, and searchScore fields, with package being what would usually be returned, and the other two containing details about how that package scored. Useful for UIs. Default: false
  • opts.sortBy - Used as a shorthand to set opts.quality, opts.maintenance, and opts.popularity with values that prioritize each one. Should be one of 'optimal', 'quality', 'maintenance', or 'popularity'. Default: 'optimal'
  • opts.maintenance - Decimal number between 0 and 1 that defines the weight of maintenance metrics when scoring and sorting packages. Default: 0.65 (same as opts.sortBy: 'optimal')
  • opts.popularity - Decimal number between 0 and 1 that defines the weight of popularity metrics when scoring and sorting packages. Default: 0.98 (same as opts.sortBy: 'optimal')
  • opts.quality - Decimal number between 0 and 1 that defines the weight of quality metrics when scoring and sorting packages. Default: 0.5 (same as opts.sortBy: 'optimal')

libnpmsearch uses npm-registry-fetch. Most options are passed through directly to that library, so please refer to its own opts documentation for options that can be passed in.

A couple of options of note for those in a hurry:

  • opts.token - can be passed in and will be used as the authentication token for the registry. For other ways to pass in auth details, see the n-r-f docs.

> search(query, [opts]) -> Promise

query must be either a String or an Array of search terms.

If opts.limit is provided, it will be sent to the API to constrain the number of returned results. You may receive more, or fewer results, at the endpoint's discretion.

The returned Promise resolved to an Array of search results with the following format:

{
  name: String,
  version: SemverString,
  description: String || null,
  maintainers: [
    {
      username: String,
      email: String
    },
    ...etc
  ] || null,
  keywords: [String] || null,
  date: Date || null
}

If opts.limit is provided, it will be sent to the API to constrain the number of returned results. You may receive more, or fewer results, at the endpoint's discretion.

For streamed results, see search.stream.

Example
await search('libnpm')
=>
[
  {
    name: 'libnpm',
    description: 'programmatic npm API',
    ...etc
  },
  {
    name: 'libnpmsearch',
    description: 'Programmatic API for searching in npm and compatible registries',
    ...etc
  },
  ...more
]

> search.stream(query, [opts]) -> Stream

query must be either a String or an Array of search terms.

If opts.limit is provided, it will be sent to the API to constrain the number of returned results. You may receive more, or fewer results, at the endpoint's discretion.

The returned Stream emits one entry per search result, with each entry having the following format:

{
  name: String,
  version: SemverString,
  description: String || null,
  maintainers: [
    {
      username: String,
      email: String
    },
    ...etc
  ] || null,
  keywords: [String] || null,
  date: Date || null
}

For getting results in one chunk, see search.

Example
search.stream('libnpm').on('data', console.log)
=>
// entry 1
{
  name: 'libnpm',
  description: 'programmatic npm API',
  ...etc
}
// entry 2
{
  name: 'libnpmsearch',
  description: 'Programmatic API for searching in npm and compatible registries',
  ...etc
}
// etc