1. Register an NPM account

1.1 Register an account on NPM official website

Registration address: www.npmjs.com/signup Fill in Username, Email address, Password, and submit the form to complete the official website registration

1.2 Email confirmation

After the official website registration is submitted, an email will be sent to the registered email box, and the login email box will complete the verification, as shown below

Log in to the NPM account

npm login
Copy the code

Enter the login Username, Email address, and Password

3. Switch to the NPM source

Use NRM to switch to NPM official source, because we want to upload the package to NPM, not Taobao source or anything else

For details about how to use NRM, see NPM Series (3) – NRM Source Switchover Management

4. Initialize the NPM package

4.1 NPM Package Project Initialization

If you already have an NPM project, go to the root directory of the project from the terminal or from CMD. If the NPM project does not already exist, create the project folder and NPM init initializes the package.json package

4.1 NPM package README. Md

Create a readme. md file in the root directory of the project and write instructions. Later, upload the NPM package to the official NPM source and display the readme. md content on the front page of the NPM package, similar to the lodash description below

5. Publish the NPM package

npm publish
Copy the code

If the release is successful, the interactive information will look something like this. Log on to the NPM website and you will see the package just released

  1. The package name cannot be the same as an existing NPM package name
  2. The package name cannot contain uppercase letters, Spaces, or underscores

6. Update the NPM package

Change the package.json version number to NPM publish again

npm publish
Copy the code

The release number must be unique

7. Cancel publishing the NPM package

7.1 Canceling release of an NPM version

NPM unpublish packageName@version for example, NPM unpublish yanggc88-publish-test@1.02.
Copy the code

7.2 Canceling publishing the entire NPM Package

NPM unpublish packageName --force For example, NPM unpublish yanggc88-publish-test --forceCopy the code

8. NPM Other common commands

npm whoami // View the current login user of NPM
npm logout // Exit the current NPM user login
Copy the code