当前位置:网站首页>NPM package [details] (including NPM package development, release, installation, update, search, uninstall, view, version number update rules, package.json details, etc.)
NPM package [details] (including NPM package development, release, installation, update, search, uninstall, view, version number update rules, package.json details, etc.)
2022-06-24 13:53:00 【Chaoyang 39】
npm package
npm Package is compliant npm Official website canonical js modular , It is usually published to npm In the official website , For everyone to download .
npm Package details
npm Package details are stored in npm Bag package.json In file , It usually contains the following information :
- name - Package name .
- version - Version number of the package .
- description - Package description .
- homepage - Bao's official website url .
- author - The name of the author of the bag .
- contributors - Name of other contributors to the package .
- dependencies - Dependency package list . If the dependency package is not installed ,npm Will automatically install the dependency package in node_module Under the table of contents .
- repository - The type of place where the package code is stored , It can be git or svn,git Can be found in Github On .
- main - main Field specifies the main entry file of the program ,require(‘moduleName’) It will load the file . The default value of this field is... Under the module root directory index.js.
- keywords - keyword
npm Version number of the package
npm The package version number is divided into X.Y.Z Three place , They represent the major version number 、 Minor version number and patch version number .
When the code changes , The version number is updated according to the following principles :
- Just fix bug, You need to update Z position .
- New features , But downward compatible , You need to update Y position .
- Major changes , Down incompatibility , You need to update X position .
View the version number of the specified package
grunt For the package name
npm list grunt
Installation package npm install
express Is the name of the dependent package ,npm install It can be abbreviated as npm i
Local installation
Download the installation package to ./node_modules in ( function npm The directory where the command is located ), If there is no node_modules Directory will be created
npm install express
When using , There is no need to specify a third-party package path .
var express = require('express');
Global installation
Will download the package to node.js In the installation directory of node_modules Directory , All projects can use globally installed packages
npm install express -g
Update package npm update
express Is the name of the dependent package
npm update express
Search package npm search
express Is the name of the dependent package
npm search express
Uninstall package npm uninstall
express Is the name of the dependent package
npm uninstall express
View all packages in the current directory
npm ls
View all packages installed globally
npm list -g
Development npm package
- New folder mypack-test
- use vscode Open folder mypack-test
- Terminal execution npm init Generate package.json file , Enter all the way , Last input y You can enter. .
The part in the blue box is the package information , You can input by yourself as required ( Or wait to generate package.json We'll change it later )
- package name Package name , The default is project name
- version Version number of the package , The default is 1.0.0
- description Package description information
- entry point Package entry file ( Everything in the package , To export this file ), The default is index.js
- test command The test command , The default is “echo “Error: no test specified” && exit 1”
- git repository Remote of package git Warehouse
- keywords keyword
- author The author of the package
- license Open source file protocol , The default is ISC
- New file index.js, The content is
The main points of : Defined function / Variables must be exported !
/* The functionality —— Sum up Parameters —— Two figures */
function sum(a, b) {
return a + b;
}
module.exports = {
sum: sum,
};
thus , Completed npm Package development , If you want to open download , Please continue to publish npm package
Release npm package
- register npm account number
npm adduser
Or go directly to the official website to register https://www.npmjs.com/
- Sign in npm account number
npm login
Enter... As prompted npm Account number 、 password 、 mailbox 、 One time verification code received in the email
3. Release
npm publish
In case of the following errors
npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/mypack-test - You do not have permission to publish "mypack-test". Are you logged in as the correct user?
shows npm The current package already exists on the official website .
Solution
take package.json The package name in name Change to a npm Package name that does not exist on the official website , Just publish it again .
For example, the final name of my package is mypack-test-999
After publishing successfully , You can find it on the official website
https://www.npmjs.com/package/mypack-test-999
Try the original npm package
- New folder test_mypack
- use vscode Open folder test_mypack
- Installation package
npm i mypack-test-999
4. New file index.js, The content is
import {
sum } from "mypack-test-999";
let result = sum(6, 2);
console.log(result);
- perform index.js
An error is reported in the figure , You need to in package.json Add
"type": "module",
Re execution index.js, Get expected results , Verify success !
边栏推荐
- kotlin 匿名函数 与 Lambda
- Kotlin asynchronous flow
- 详解kubernetes备份恢复利器 Velero | 深入了解Carina系列第三期
- 2022起重信号司索工(建筑特殊工种)复训题库及答案
- 码农版隐秘的角落:作为开发者最讨厌的5件事
- Docker installation redis
- kotlin 协程通道
- Golden age ticket: Web3.0 Security Manual
- Google Earth engine - Murray global tidal wetland change V1 data set from 1999 to 2019
- System status identifier 'hum' for SAP QM inspection lot
猜你喜欢
随机推荐
2022年施工升降机司机(建筑特殊工种)考试试题及在线模拟考试
杰理之检测 MIC 能量自动录音自动播放参考【篇】
万用表测量电阻图解及使用注意事项
HarmonyOS. two
杰理之开了多种解码格式插卡到播放等待的时间长【篇】
金鱼哥RHCA回忆录:DO447管理项目和开展作业--为ansible剧本创建一个项目
HarmonyOS-3
如何避免严重网络安全事故的发生?
Operation of simulated examination platform for examination questions of coal production and operation units (safety production management personnel) in 2022
2022年质量员-设备方向-岗位技能(质量员)复训题库及在线模拟考试
Promotion of Project Manager
杰理之TIMER0 用默认的 PA13 来检测脉宽【篇】
The research on the report "market insight into China's database security capabilities, 2022" was officially launched
Docker安装redis
**Puzzling little problem in unity - light and sky box
These default routes and static routes can not be configured and deployed. What kind of network workers are they!
工业物联网(IIoT)的八个主要趋势
【R语言数据科学】(十四):随机变量和基本统计量
Gatling performance test
Huawei PC grows against the trend, and product power determines everything