Query npmjs registry via api

前端 未结 10 1549
走了就别回头了
走了就别回头了 2020-12-23 13:51

I find I\'m often unsatisfied with the ordering and expressiveness of searches on https://www.npmjs.com/. I guess there should be a way to programmatically query the server

相关标签:
10条回答
  • 2020-12-23 14:30

    You can use api-npm node module it directly queries the NPM registry and you can get all attributes of a module and download stat of any module of any time range https://www.npmjs.com/package/api-npm

    0 讨论(0)
  • 2020-12-23 14:31

    The docs are here now: https://github.com/npm/registry/blob/master/docs/download-counts.md

    Downloads endpoint

    Gets the total downloads for a given period, for all packages or a specific package.

    GET https://api.npmjs.org/downloads/point/{period}[/{package}]

    Examples

    All packages, last day:
    /downloads/point/last-day
    All packages, specific date:
    /downloads/point/2014-02-01
    Package "express", last week:
    /downloads/point/last-week/express
    Package "express", given 7-day period:
    /downloads/point/2014-02-01:2014-02-08/express
    Package "@slack/client", last 30 days:
    /downloads/point/last-month/@slack/client
    Package "jquery", specific month:
    /downloads/point/2014-01-01:2014-01-31/jquery
    0 讨论(0)
  • 2020-12-23 14:32

    If you can't find a package or are just hacking together a shell script the Registry API Docs in the registry's git repository include detailed information on Search API and search qualifiers.

    If you're looking for the most popular insecure package in the public registry run:

    wget -qO - "http://registry.npmjs.com/-/v1/search?text=is:insecure&popularity=1.0&size=1"
    

    The above uses the is:insecure search qualifier without any additional text criteria and grabs size=1 results where popularity=1.0 (the most popular).

    Check in the docs directory in the repo for a number of other useful things such as:

    • Detailed list of response Package Metadata.
    • Replicate API for scoped and unscoped packages.
    • Information on getting download counts.
    • Walkthrough on how to create a registry "follower".
    0 讨论(0)
  • 2020-12-23 14:45

    You can always use the NPM registry client: https://github.com/npm/npm-registry-client.

    If you look through this you can get the endpoints for the API. e.g to get the dist-tags for a package then you can go to /-/package/packageName/dist-tags'

    So to get the babel-core dist tags you would go to http://registry.npmjs.org/-/package/babel-core/dist-tags

    0 讨论(0)
  • 2020-12-23 14:46

    Take a look at sinopia registry interface: https://github.com/rlidwka/sinopia/blob/master/lib/index-api.js. The default registry for npm client is https://registry.npmjs.org (try it out on console: npm config ls -l). So you can try the following (referencing the sinopia API) to fetch data about react 15.0.2

    https://registry.npmjs.org/react/15.0.2

    0 讨论(0)
  • 2020-12-23 14:49

    There is a really good npm query site https://npms.io which I am using for years on my web project. It is an open-source project and supports advanced search with a better quality of the results for the keywords.

    They have a scoring system for each package using the collected information about the project. The final score is calculated based on four different aspects of Quality, Maintenance, Popularity, and Personalities.

    It also has very neat REST API.
    API Doc: https://api-docs.npms.io

    0 讨论(0)
提交回复
热议问题