Install node and NPM

Download the node installation package from node.js official website and perform the installation

NPM has been included in the node. After the installation is completed, check whether the installation is successful by checking the version, and prompt that the output version number is successful

node -v
npm -v

Create and release packages

Create the package directory and finish NPM initialization

mkdir npm-test
cd npm-test
npm init

During initialization, NPM will prompt to create a configuration file package. json, including package naming and so on

Create an index.js file in the npm-test folder and write a simple plug-in

exports.hello = function (name) {
    console.log('hello' + name)
}

View package.json, as follows:

{
  "name": "npm-test", 
  "version": "1.0.0",
  "description": "", 
  "main": "index.js", 
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  }, 
  "author": "", 
  "license": "ISC"
}

Release package

After the above operations are completed, we need an NPM account to publish the package. This account will be added to the NPM local configuration for subsequent publishing.

If you have an account, you can query the local authentication information through the command

npm whoami

Without authentication information, you can log in by command

npm login

If there is no account, you can register the account by command

npm adduser

After successful login, issue NPM package

npm publish

After publishing successfully, get the NPM package

npm install npm-test

Using NPM package

let a = require('npm-test')
a.hello('npm')

Update the NPM package, modify the version number in package.json, and continue to publish

Client updates published update packages

npm update npm-test
Like The Article To View All

All Comments

Leave a Reply Cancel Reply

Tips: Your email address will not be disclosed!

If you can't see clearly,please click to change...