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
, andemail
via prompt and hope they see something likeLogged 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!