Skip to content

Instantly share code, notes, and snippets.

@bulletinmybeard
Last active April 10, 2023 10:04
Show Gist options
  • Save bulletinmybeard/cfcac7221671868e2fd30441148695fb to your computer and use it in GitHub Desktop.
Save bulletinmybeard/cfcac7221671868e2fd30441148695fb to your computer and use it in GitHub Desktop.
Quick guide to publish and unpublish NPM packages

Quick guide to publish and unpublish NPM packages

To publish packages, you need to have an NPM user account with an organization set up. If you don't have an NPM account, create one here https://www.npmjs.com/signup, and don't forget about the organization! Mind you, once the organization is set up, you have to contact customer support to make them apply changes to the organization!

  • Open a terminal, type npm login and press enter
  • Provide your account username, password, and email via prompt and hope they see something like Logged in as <your_username> on https://registry.npmjs.org/.

I assume you managed to log into your NPM account via terminal!

  • Install npmrc globally with npm install -g npmrc (npmrc creates configuration files for NPM which define the settings on how NPM should behave when running commands

  • Run npmrc without arguments to use the default profile or create and use a custom profile

  • Create custom profile npmrc -c <profile_name>

  • Switch from default profile to custom profile npmrc <profile_name>

Now you can publish your package with or without scope.

  • Without scope
    • npm publish will publish your package under the URL: https://www.npmjs.com/package/<package_name>
  • With scope
    • npm publish --scope=@<your_organization> will publish your package under the URL: https://www.npmjs.com/package/@<your_organization>/<package_name>
    • npm publish --scope=@<your_username> will publish your package under the URL: https://www.npmjs.com/package/@<your_username>/<package_name>

That's it. Your package should be fully published and available within no time.

Bumping up a package version can be done by running npm version followed by a SemVer version number (e.g., npm version 1.0.1), which will also bump up the version in your package.json. More about npm version can be found here https://docs.npmjs.com/cli/v6/commands/npm-version/

If you want to unpublish packages, run npm unpublish <package_name> -f for a single package or npm unpublish --force to unpublish all your packages. Mind you, NPM will block the names of unpublished packages for at least a day or so. Till then, you are not allowed to publish packages under the same name again.

cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment