How to Publish an NPM Package with a Beta Tag

When developing an NPM package, you often need to share a version for testing without marking it as the “latest” stable release. While npm link is great for local development, sometimes you need to test the installation process or share the package with a small group of beta testers.

Here is how you can publish a beta version of your package to the NPM registry.

Step-by-Step Guide

  1. Prepare your build: Ensure your code is compiled and ready for distribution.

  2. Update the version: Use the prerelease identifier to automatically bump the version (e.g., from 1.0.0 to 1.0.1-0).
    npm version prerelease
    
  3. Publish with a tag: This is the most crucial step. By adding the --tag beta flag, you tell NPM not to update the latest tag that users get by default.
    npm publish --tag beta
    

How Users Install It

Since you didn’t publish to the latest tag, users simply running npm install package-name will still get the old stable version. To get your new beta, they have two options:

Option 1: Install by Tag This installs the most recent version tagged as “beta”.

npm install package-name@beta

Option 2: Install by Specific Version This installs the exact pre-release version you created.

npm install [email protected]