Installing local NPM packages without publishing to public registry

I created a custom NPM package with some shared utilities that I want to keep private and not publish to the main NPM registry. I’m trying to figure out the best way to use this package in my other projects.

Setting up a private registry seems like overkill for just a few packages. I’m wondering if there are simpler alternatives like installing directly from my local file system or maybe pulling it from a git repository.

Is there a way to install packages using something like this approach?

npm install --local-path /path/to/my/package

Or maybe from a git source directly? What are the available options for handling private packages without the complexity of running my own registry server?

Another solid approach is npm link during development. Go to your package directory, run npm link, then jump to your consuming project and run npm link package-name. Creates a global symlink that’s super convenient for active development - changes show up immediately without reinstalling. Don’t use this in production though, since it relies on global state. For production, stick with the git approach using specific tags or commits. You can also use private GitHub repos with personal access tokens in your package.json dependencies: git+https://[email protected]/user/private-repo.git#v1.0.0. Keep those tokens secure and use environment variables for CI/CD pipelines.

Try npm workspaces if you’ve got multiple related projects. I manage several private utilities this way and it works great. Just create a packages folder for your shared code, then reference it in your main project’s package.json with workspace syntax. The git method works too, but use specific commit hashes or tags instead of pointing to master - saves you from unexpected updates breaking your builds. Watch out for file: references though - they create symlinks by default, which can mess with bundlers. If that happens, use npm pack to create a tarball and install from that instead.

for sure! you can do npm install file:../path/to/package for local paths. and for git, just go with npm install git+https://github.com/user/repo.git. it’s super handy during dev, makes life a lot easier!