How to publish your own npm package using npm

Record the process of an npm package release:

  1. If you want to have your own dependency package on npm, then you must first have an npm account, if not, you need to register one on the npm official website ;
  2. Then you need to use the npm command to create a new project:
//1.进入一个文件夹,打开cmd,输入命令:
npm init

After that, the carriage return starts all the way, and the important tips are as follows:
write picture description here

The entry file index.js is the entry file of the package you want to publish; the
version number is very important. If you want to update your package, the version number you update this time cannot be the same as the previous one;

Write the code you want to upload, then the next step is to publish

The first step in publishing is to log in first. If you don’t know if you have logged in before, you can use:

npm  whoami

to check the login status

If you have not logged in, then you need to log in first:
If you have used the download link of the cnpm Taobao mirror before, you should set the download link back at this time:

npm config set registry http://registry.npmjs.org 

Then you npm logincan log in, you need to enter your registered account and password.
Another point to note is that you need to check whether your package name is occupied before publishing. For details, click here to check
and then you can publish:

npm public

Of course, you can also add read me and upload it together in the project directory

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325857580&siteId=291194637