Publish npm package process

The steps to publish an npm package are as follows:

  1. npm initCreate a new npm package through the command in the terminal , and fill in the package information according to the prompts, such as package name, version, description, author, license, etc.

  2. Create a file in the root of the package index.jsand write your code.

  3. Make sure you have registered an npm account, go to the npm official website to log in, if not, register one.

  4. Log in to the npm account through the command in the terminal npm login, and enter your user name, password, and email address. If it is the first release, you may be asked to enter a one-time verification code, and an email will be sent to your mailbox. Click to check the mailbox, and enter it according to the prompt. If you are currently using a mirror image, you may fail to log in
    insert image description here
    . , the solution can look at npm login failure solution

  5. At this time, we can enter npm whoamito check the current account number, but this step can be ignored
    insert image description here

  6. Verify that your code is free of security holes and bugs, which can npm auditbe checked with the command.

  7. To publish your package, use npm publishthe command to upload the package to the npm server. If you are releasing a package for the first time, you may need to confirm the email in the registered email.
    insert image description here
    When you see the following prompt, the release is successful
    insert image description here

  8. You can now share your package, and others only need to use npm install <package name>the command in the terminal to install and use your package.

At this time, we can go to the npm official website, click on our avatar, select packages, and view the newly released package.
insert image description here
insert image description here
Click this package, which provides us with a download command, as shown in the figure below
insert image description here

Precautions

  1. Make sure your package name is not taken, and don't use npm reserved names.

  2. Remove any sensitive information in your code before uploading the package.

  3. Make sure your packages are properly versioned, usually with Semantic Versioning.

  4. If you need to update the package, just modify the code and increase the version number, and run npm publishthe command again.

Summary : Publishing an npm package requires preparing an npm account, writing code and documentation, uploading the code and confirming the package name, version and license, and finally installing and testing through the npm install command.

Guess you like

Origin blog.csdn.net/jieyucx/article/details/131900509