What's the "official" way to download packages programmatically?

(James Alexander Rosen) #1

I’m building an internal application that will use npm to resolve modules, then perform some transforms. Given a package name, "@my/module", and a version string, "^3.2.0", what’s the best programmatic way to fetch @my/module@^3.2.0? I need the actual contents on disk somewhere, though I don’t necessarily want to install them to ./node_modules since that might interfere with the modules that run the app.

This StackOverflow question suggests that the only officially supported API is the CLI, so I should shell out to that. But both the question and the answer are from 2013. Is that still the correct answer?

(Lars Willighagen) #2

Perhaps pacote? It’s currently the package used by npm itself for downloading package metadata and tarballs, and I think it could fit your needs.

(Markus Tacker) #3

There is also https://www.npmjs.com/package/libnpm

(James Alexander Rosen) #4

Somewhat amusingly, the “manifest” link on https://www.npmjs.com/package/libnpm goes to https://www.npmjs.com/package/pacote#manifest

(system) #5

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.