13

I'm looking for a way to query npm package versions from the npm registry api. All I found until now is that I need to query the whole package metadata and filter the versions from there, Example: https://registry.npmjs.org/react-chuck/

It's ok for package with small amount of versions but for large amount of versions it's just too much time to query.

I thought that maybe there is something like the dist-tags api that query only the dist-tags, Example: https://registry.npmjs.org/-/package/react-chuck/dist-tags , the dist-tags are in the same scope as versions... enter image description here

I don't mind to do it cli also npm view react-chuck versions but this returns array as a string and array of strings.

I looked at those two links:

Anyone has a tip of champs maybe?

yershalom
  • 786
  • 1
  • 8
  • 19

3 Answers3

8
npm show react-chunk time --json
jbachman
  • 249
  • 2
  • 6
  • 5
    Any way I can do this using HTTP API ? – Salathiel Genese Feb 08 '19 at 07:20
  • sure, but like the `npm show` command the HTTP API will return all the metadata for the package so you'd need to filter out the data you want. For example: `curl https://registry.npmjs.org/react-chunk | jq .time` – jbachman Feb 26 '19 at 09:37
  • `graph-ql` was an ingenious invention, do they know it ? – Salathiel Genese Feb 26 '19 at 17:17
  • @jbachman what you suggest return `Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.` – KpsLok Oct 09 '19 at 09:17
3

Check https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md

You need to vary the Accept header to return abbreviated package metadata. Request the NPM registry directly, not with the npm CLI.

Jed Richards
  • 12,244
  • 3
  • 24
  • 35
1

As far as I know there's no command that will fetch only part of the data.

The npm view react-chunk versions command still fetches from https://registry.npmjs.org/react-chuck and then parses it on the client side. It's indeed not very efficient for packages with a lot of versions, but that's the api.

silyevsk
  • 4,021
  • 3
  • 31
  • 30