Search code examples
javascriptnode.jsnpmcdn

NPM registry API, view a package's internal structure and file's through a JSON response


Is it possible using the NPM registry API to request an endpoint such as

https://registry.npmjs.org/jquery

And view the Tarbells structure and internal files without having to actually download the package in a JSON response such as:

{
  files: {
   js: registry.npmjs.org/v1/jquery@3.1.1/jQuery.min.js,
  },
}

I am trying to understand how CDN's work and I am confused on how jsdelivr is able to actually list out all the actual .js, and other file extensions to a permanent URL such as:

https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js.

Is jsdelivr actually downloading all these Tarbells and storing them? Is there a way to view the actual jQuery.min.js file through the NPM registry endpoint? I have read many resources, and can't for the life of me figure it out.


Solution

  • Yes, jsDelivr actually stores the files locally. For the files that they don't have cached locally, every file they have ever served is stored in a global S3 storage, which can be fetched upon demand [source].

    jsDelivr also has a neat infographic showing how files are fetched.

    infographic