Sometimes you’ll want to use npm to install a package that doesn’t exist in the official npm registry for some reason. Maybe you’re developing the package yourself. Maybe it’s an internal use-only package. Maybe the package writer never published it. Here are a few ways to install a local package with npm.
Link the Local Node Package
If you’re developing a package locally, you’re likely making lots of changes to the source. You don’t want to publish after each change in order to install this package as a dependency elsewhere. Npm has provided the link keyword.
This allows your put a global label on your package that tells your local npm cache about it:
And then go to the local project that you’re using the package in and point to the dependency by package name:
Now you have symlinked a directory called
<pkg_name> in the project’s node_modules directory. Changes you make in your package will appear and be usable from within your project.
Tarball the Local Node Package
This will create a tarball a la
<pkg_name>-<pkg_ver>.tgz. Now just store your new tarball somewhere like a local filesystem or server that is accessible when you run npm install on your dependant project.
You can ask for the tarball manually:
Or put the reference in your package.json for later:
1 2 3 4 5
You probably have a node package that’s only available locally for a reason. To guarantee that it’s not accidentally published to the world via the npm registry, add this beaut to your package.json:
1 2 3
Replicate the Npm Registry
If you’re going all out, like creating a corporate npm registry, you always have the option of replicating the Npm registry internally. It’s CouchDb, and ’replication’ is its Chinese neighbor’s middle name. You can publish your own packages there so they’re still private to your and your organization. And you also get local references to the public packages.
The Glory of Npm
Npm is great. The ability to install published or local packages is an example of its flexibility and usefulness. What are the other ways that you’ve found to make non-public packages installable – for instance, that package that the writer just never bothered to publish to npm?