Before you start, you need to register your account on NPM website and remember your account number, password and email address (you will need to send the package).

1. View the login source

Before NPM is published, be careful to look at the login source. Switch to the local project (for example, test) in the root directory test/

npm get registry
Copy the code

You can switch to the NPM source or another source

npm set registry=http://registry.npmjs.org
Copy the code

or

npm config set registry https://registry.npmjs.org/
Copy the code

2, login

Viewing Login Information

npm whoami
Copy the code

The login

npm login
Copy the code

If you press Enter, you need to enter the user name, password, and email address in sequence

Logged in as username on http://registry.npmjs.org/.
Copy the code

Login successful

3, publish,

After successful login, you can publish

The test/directory

npm publish
Copy the code

Or publish the specified project test package

cd .. && npm publish test
Copy the code

4, check the

After successful publishing, you can go to www.npmjs.com/ to view publishing to the project. Also can…

View the released version number of test

npm view test versions
Copy the code

Install and publish to the Test project

npm i test
Copy the code

View the current project NPM dependencies

npm ls
Copy the code

5. Undo and update

Undo the published Test package

npm unpublish test --force
Copy the code

The undo command is used with caution. Once the undo command is executed, it means that the test package is discarded and the project package named “test” cannot be published again.

Modify the Version field in package.json to indicate an update

'version': 'A.B.C' 1. Bug fixes, minor changes, c+1 2. 3. Major changes, backward compatibility is not possible, A +1Copy the code

The publish directive is then executed to update the package

npm publish
Copy the code

6, use,

Enter the project root directory, project/, and download the test package

npm i test                  # yarn add test
Copy the code

If it fails, the project may not have NPM initialization, enter project/, perform initialization and then download

npm init && npm i test
Copy the code

The test package exists in node_modules/ of the project. If you want to use the previous version of the dependencies, you can query the package version and select the specified version

Example Query the version of the test dependent package

npm view test versions
Copy the code

Download the test package of the specified version

npm i [email protected]
Copy the code

You can also modify the version information of the test package in package.json in the project/ directory and execute it

npm i test
Copy the code