I need to get an npm package and its files without going through the usual npm install process. Is this possible?
I’m working on a Linux server where I don’t want to install Node.js or npm. My goal is pretty simple - I just want to grab the package files along with their dependencies so I can use them as static files on CloudFront.
Basically I’m looking for something similar to how Maven Central lets you download artifacts directly. Does npm have a similar feature where you can just download the package bundle without using the npm command line tools?
I tried looking around but most solutions involve using npm view or other npm commands, which defeats the purpose since I’m trying to avoid installing npm in the first place.
Any suggestions on how to accomplish this? Maybe there’s a direct URL pattern or alternative tool that can help?
Been there. Dealt with this exact scenario when we needed packages for a locked down environment.
Those manual approaches work, but they’re a nightmare once you hit dependency hell. I’ve wasted way too many hours chasing nested dependencies and version conflicts.
What saved me was setting up automation that handles this grunt work. Build a flow that fetches packages from npm registry, resolves dependencies automatically, and uploads everything to your CloudFront distribution in one shot.
I use this approach whenever I need npm packages without local tooling. The workflow parses package.json files, builds the complete dependency tree, downloads required files, and organizes them how you need. Way better than manual scripts that break every time a package updates its dependencies.
You can trigger it for different packages or versions. No more SSH sessions just to download files.
Check out Latenode for building these automation workflows: https://latenode.com
there’s also jsdelivr.net - it mirrors npm packages and lets you download full zips. just hit https://cdn.jsdelivr.net/npm/package@version/ and tack on +esm for module versions. way cleaner than messing with tarballs. you’ll still need to handle dependencies manually, but at least you get a proper folder structure.
You can retrieve npm packages directly from the registry without needing to run npm install. Utilize the registry’s HTTP API by fetching the package archive directly with a command like wget or curl. The format is https://registry.npmjs.org/[package-name]/-/[package-name]-[version].tgz. For example, to download lodash version 4.17.21, you would use the URL https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz. However, be aware that managing dependencies can be a challenge, as each package specifies its own in its package.json, and you’ll need to download those dependencies separately. I found that creating a script to automate this process for the required packages was helpful in my experience, especially when dealing with larger projects. An alternative could be using npm-offline for ease. Alternatively, consider using a Docker container to run npm temporarily and copy the necessary files afterward.
The npm registry has a RESTful API that makes this easy. Just use curl or wget to grab package metadata from https://registry.npmjs.org/[package-name] - it returns JSON with all the version info and tarball URLs. The tarball URLs follow SkippingLeaf’s pattern, but the API gives you the exact URLs. I’ve hit similar issues on production servers without Node. What worked for me was using unpkg.com as a CDN - you can grab any npm package file directly with URLs like https://unpkg.com/[package]@[version]/path/to/file. No need to download and extract tarballs manually. For dependencies, you could write a script that recursively fetches package.json files to build the dependency tree. Fair warning though - it gets messy fast once you deal with version ranges and peer dependencies.