# np — A Better npm Publish with Safety Checks > np is an interactive CLI tool that automates the npm package publishing workflow with version bumping, test runs, git tagging, two-factor auth prompts, and safety checks. ## Install Save as a script file and run: # np — A Better npm Publish with Safety Checks ## Quick Use ```bash # Install globally npm install -g np # Publish with interactive prompts np # Publish a specific version np patch ``` ## Introduction np wraps the entire npm publish workflow into a single interactive command. It runs your tests, bumps the version, creates a git tag, pushes to the remote, publishes to the npm registry, and creates a GitHub release draft. Each step includes safety checks to prevent common publishing mistakes like dirty working trees or skipped tests. ## What np Does - Runs the full test suite before allowing a publish to proceed - Verifies the working directory is clean with no uncommitted changes - Bumps the version in package.json using SemVer (patch, minor, major, or custom) - Creates an annotated git tag and pushes it to the remote repository - Publishes the package to npm with optional two-factor authentication prompts ## Architecture Overview np orchestrates a sequential pipeline of checks and actions. It starts with prerequisite validation (clean git state, correct branch, npm auth), then runs the test script from package.json. After tests pass, it prompts for the version bump type, updates package.json and lockfiles, commits, tags, pushes to git, and finally runs `npm publish`. Each step is guarded by error handling that aborts the pipeline cleanly if anything fails, preventing partial publishes. ## Self-Hosting & Configuration - Install globally with `npm install -g np` or run via `npx np` - Configure in package.json under the `np` key or in a `.np-config.js` file - Set `"tests": false` to skip test runs for projects without a test suite - Use `"yarn": true` to run Yarn instead of npm for installs and publishing - Set `"branch": "main"` to enforce publishing only from a specific branch ## Key Features - Interactive version selection: choose patch, minor, major, prepatch, or custom - Prerequisite checks: clean git state, correct branch, valid npm auth, up-to-date dependencies - Two-factor auth: prompts for OTP when your npm account requires it - GitHub releases: optionally opens a pre-filled GitHub release draft after publishing - Monorepo support: works with workspaces when run from a package directory ## Comparison with Similar Tools - **npm publish** — Raw publish command with no safety checks; np adds validation and automation around it - **release-it** — More configurable release pipeline; np is opinionated and requires less setup - **semantic-release** — Fully automated based on commit messages; np is interactive and developer-driven - **Changesets** — Designed for monorepo versioning workflows; np targets single-package publishing ## FAQ **Q: Does np work with Yarn?** A: Yes. Set `"yarn": true` in your np config and it will use Yarn for install and publish steps. **Q: Can I do a dry run?** A: Yes. Run `np --preview` to see what version would be published and which steps would execute without actually running them. **Q: Does it support scoped packages?** A: Yes. Scoped packages publish normally. For public scoped packages, ensure `publishConfig.access` is set to "public" in package.json. **Q: What happens if tests fail?** A: np aborts the entire pipeline and no version bump, tag, or publish occurs. ## Sources - https://github.com/sindresorhus/np - https://www.npmjs.com/package/np --- Source: https://tokrepo.com/en/workflows/asset-b692b6f9 Author: Script Depot