Query npmjs registry via api
Solution 1
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
NOTE:- Seems like the data receiving is few days old, if you want live/recent data this API may not suit.
Solution 2
https://skimdb.npmjs.com/registry/_all_docs
This is a current method to pull all the package names.
The URL search is http://registry.npmjs.com/-/v1/search?text=<searchstring>&size=20
Edit1: 3 years later (Mar 2021) and this endpoint still works. Glad it's still being helpful to folks :)
Edit2: Still working in April of 2022
Solution 3
Of course there is at least one tool designed to talk to that registry, and that is the npm
command line tool itself. Its search for example starts by updating a local cached copy of the index, filtering that. In update-index one can read that the URL ending in /-/all
is apparently special. And indeed, appending that to registry.npmjs.org
(deliberately not formatted as a link) will fetch a 125M file which might be too much for your browser. Luckily the cached version is stored available in ~/.npm/registry.npmjs.org/-/all/.cache.json
. From there one can read a list of all nown packages. One could then continue to query each such package in more detail.
The fact that npm search
apparently uses no more elaborate scheme suggests that there is not much of a server-side api here.
Searching the web for pages mentioning api.npmjs.org
I found that the download counts can be retrieved from there. All other documents I found make use of that single facility.
Looking for alternatives, I also stumbled upon npmsearch.com which offers some more versatile searching facilities and has a somewhat documented API.
Solution 4
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
Solution 5
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".
MvG
Dr. Martin von Gagern. Studied computer sciences, obtained a PhD in mathematics, currently a Google site reliability engineer.
Updated on July 09, 2022Comments
-
MvG almost 2 years
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 using https://api.npmjs.org/ or http://registry.npmjs.org/. But how? Where is the documentation?
(Or are there node packages to faciliate that? I know SO isn't about tool or package recommendations, so perhaps I shouldn't be asking about this as well, but if there were some tool, I could likely read the API from that as well.)
-
Jakub Žitný over 7 yearsThis looks like a nice start, but there is a lot more data one can wish for. Are you planning on improving the package?
-
Mark Amery over 6 yearsregistry.npmjs.org/-/all just returns
{"message":"deprecated"}
nowadays. I suggest unaccepting this answer. -
Nguyen Tran over 3 yearsFor specify package: registry.npmjs.org/core-js/latest
-
Julian Knight over 3 yearsThis definitely doesn't work any more. and the referenced file doesn't exist.
-
Mehdi Golzadeh about 3 yearsThanks for your response, my problem is that Libraries.io is not up to date and latest dump is for January 2020, do you have any similar solution?
-
Maytha8 over 2 yearsIt still works but npm say it's now deprecated. Use registry.npmjs.com instead
-
Onkeltem over 2 yearsSeems a little abandoned for now.
-
Onkeltem over 2 yearsIt's worth providing a link to the API: github.com/npm/registry/blob/master/docs/REGISTRY-API.md
-
Drazisil about 2 yearsIt's always been depreciated.
registry.npmjs.com
is not usable the same way, nor is the documented API. -
Sampgun almost 2 yearsAgree, abandoned probably. Also I tried it, but returns outdated data.