Publish a simple NPM package
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
- 本文链接: https://www.zdyla.com/en/post/publish-npm-package.html
- 版权声明: 本博客所有文章和照片除特别声明外,转载请联系作者获取授权,并请注明出处!