1 Register for an NPM account
- The first step to www.npmjs.com/
- Step 2 Log in with your account and password
- Part 3: Email verification (a verification button will be sent to the registered email, click the verification button)
2 Terminal Login
- Step 1 Open the terminal
- Step 2 Enter the following code
npm adduser
Copy the code
or
npm login
Copy the code
- Step 3 Enter username, password, and email as prompted
If you Logged in correctly, you get the message: Logged in as bamblehorse to scope @username on registry.npmjs.org/.
- The fourth step is to ensure that the NPM source is correct
Start developing the first package
- The first step is to create a folder called myFirst
- Step 2 Go to the folder and create an empty package.json file
- Step 3 Run NPM Publish. The following error information is displayed
Give our package a name in the package.json file
{"name": "@username /myFirst"}Copy the code
Tips: the NPM username is added to the beginning of the package. By using @own username/myFirst instead of myFirst, you will create a package under your own username scope. This is called the Scoped Package.
Try NPM Publish again with the following error
Each NPM package requires a version so that developers can update the package version safely without breaking the rest of the code.
{" name ":" @ own username/myFirst ", "version" : "1.0.0"}Copy the code
Run NPM Publish again
Scoped Packages will be automatically published as private packages. Change the NPM publish command NPM publish –access=public
We received a + sign, as well as the name and version number of the bag. We are very happy that there is no wood. You can also get it on NPM
4 Enrich our bags
Modify the package.json file
- Description: Description of the package
- Repository: You can write your GitHub address
- License: MIT authentication
- Main: The package entry file, located at the root of the folder
- Keywords: Add some keywords to facilitate package search (array format)
Add the index.js package entry file, create a GitHub link, and add the readme.md file to give you a better idea of how the package is used.