Offline Installation of npm Packages logo

Offline Installation of npm Packages

Free

Install npm packages offline with --cache-min or local-npm

FreeFree tier
Type
Open Source

About Offline Installation of npm Packages

This resource (a blog post by Addy Osmani) covers two primary methods for installing npm packages while offline: the built-in but incomplete --cache-min flag, and the more robust third-party solution local-npm. local-npm is an offline-first Node server that acts as a local npm mirror by caching modules and their dependencies in a PouchDB database. It listens for changes to the remote registry to keep packages up-to-date, and falls back to the network for any packages not yet cached. The blog provides step-by-step setup instructions, including installing local-npm, pointing npm to the local registry, and verifying offline installation works by disconnecting the network.

Key Features

Offline-first local npm mirror using PouchDB
Caches modules and their dependencies locally
Listens for remote registry changes to keep packages updated
Falls back to network for uncached packages
No need to wait for full registry replication before using
Easy setup with `npm set registry http://127.0.0.1:5080`

Pros & Cons

Pros
  • Robust offline solution that handles package staleness
  • Works with existing npm workflow after minor configuration
  • Supports incremental replication (doesn't require full download upfront)
  • Free and open-source (npm package)
  • Provides a local registry endpoint for transparent proxying
Cons
  • Requires initial setup and installation of local-npm
  • First install of a new package version still needs network access
  • Not a built-in npm feature; relies on third-party tool
  • Still uses network for metadata and tarballs on first encounter of a version

Best For

Installing npm packages during flights or in areas with poor connectivityRunning workshops or training sessions without reliable internetEnsuring consistent, repeatable builds in air-gapped environmentsCaching dependencies to speed up subsequent installs

FAQ

How do I install npm packages offline?
You can use the built-in `--cache-min` flag with a high value (e.g., `npm --cache-min 9999999 install`), but it has limitations. For a more robust solution, install and run `local-npm`, then set npm to point to the local registry: `npm set registry http://127.0.0.1:5080`.
What is local-npm?
local-npm is an offline-first Node server that acts as a local npm mirror. It caches npm modules and their dependencies in a PouchDB database, listens for changes to the remote registry to keep packages up-to-date, and falls back to the network for uncached packages.
Does local-npm require downloading the entire npm registry?
No, local-npm replicates only the skimdb metadata initially and downloads tarballs on first use. You do not need to wait for the full replication to start using it; it will fetch packages on demand.
How can I test if offline install is working?
After setup, run an npm install normally with network, then disconnect your wifi, clear the npm cache and node_modules, and run the same install again. If everything is cached, the install should succeed.