npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

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

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?

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.

There is also

Somewhat amusingly, the “manifest” link on goes to