


[Compilation and Sharing] Common npm commands necessary for front-end development
Aug 09, 2022 am 11:29 AMnpm is node's default package management tool. In front-end development, being familiar with npm's common commands will be of great help to us in solving problems. The following article will share with you some common npm instructions. I hope it will be helpful to you!
npm source settings
- ##Query the current source configuration
npm get registry
- Set Taobao mirror source (Taobao mirror new domain name)
npm config set registry https://registry.npmmirror.com
npm config set registry http://registry.npm.taobao.org
- Restore the default source
npm config set registry https://registry.npmjs.org
- Use nrm to manage the source
# 全局安装nrm npm install -g nrm # 查看nrm源列表(支持默认源,淘宝源,腾讯源等) nrm ls # 切换源(镜像源的名称nrm ls是可以看到的) nrm use taobao
- Add the .npmrc file in the project root directory, content Taobao mirror address:
registry = https://registry.npmmirror.com
Installation dependencies
- Global installation
# 安装最新版本 npm install -g xxx # 安装指定版本 npm install -g xxx@1.0.0
- Local installation (current file folder)
npm install xxx
- Project dependencies are installed and written into
- dependencies of package.json:
npm install –S xxx # 和上面效果一样,默认: npm install xxx
- Project dependencies are installed and written into
- devDependencies of package.json:
npm install –D xxx
- Specify the version number
npm install vue@3.0.0
- This project installs dependencies. Temporarily use the Taobao image
npm install --registry=https://registry.npmmirror.com
- to install a certain dependency package (the following command specifies version @1.0.0). Temporarily Use Taobao mirror:
npm install XXX@1.0.0 --registry=https://registry.npmmirror.com
Uninstall dependencies
- ##Uninstall
-
npm uninstall <package-name></package-name>
Copy after login
- Using the -S or --save flag, this operation will also remove the reference in the package.json file;
- If the package is development Dependencies (listed in devDependencies in the package.json file) must be removed from the file using the -D or --save-dev flag.
npm uninstall -S <package-name> npm uninstall -D <package-name></package-name></package-name>
Copy after login
npm uninstall -g <package-name></package-name>
Copy after login
- Alias for uninstall: remove, rm, r, un, unlink these They are all aliases of npm uninstall.
npm uninstall -S <package-name> # 等价 npm remove -S <package-name> # 等价 npm rm -S <package-name></package-name></package-name></package-name>
Copy after login
- Check for updates first
-
npm outdated
Copy after login
The packages marked in red are those that can be updated, and those marked in yellow are those that cannot be updated.
- If you are not sure about the major and minor versions, there is a version number description below, please pull down.
-
npm update
Copy after login
# 1.安装"npm-check-updates"模块 npm install -g npm-check-updates # 2.检查可更新的模块 ncu npm-check-updates # 以上两条命令都可检查可更新模块。接下来更新package.json的依赖包到最新版本: #升级 package.json 文件的 dependencies 和 devDependencies 中的所有版本 ncu -u #以上命令执行,更新全部模块。但在实际开发中不建议一次全部更新,可以根据实际需要,更新指定的模块,并且可以根据作用范围在后面加上 -D、-S 或 -g
Copy after loginMethod 2:
# 全局安装 npm-check npm install -g npm-check # 查看可更新的依赖 npm-check # 更新依赖 npm-check -u
# 更新主版本的另一种方式就是先卸载,再重新安装 # 卸载 npm uninstall xxx # 重新安装-最新版本 npm install xxx # 重新安装-制定版本 npm install xxx@2.0.0
- View npm version
-
npm -v
Copy after login
- View installed package version
npm 套件名称 -v
Copy after login
- View npm help
npm help
Copy after login
- View all folders used by npm
npm help folders
Copy after login
- View the module list (view the list of locally installed modules)
npm list # 也可以使用缩写 ls npm ls
Copy after login
- View the globally installed packages
npm list -g --depth 0
Copy after login
npm list vue-cli
Copy after login
- View the package.json folder of the node module
npm view moduleNames
Copy after login
npm view moudleName dependencies
Copy after login
- View the source file address of the package
npm view moduleName repository.url
Copy after login
- Check the version of Node that the package depends on
npm view moduleName engines
Copy after login
- Check the installation path of the current package
npm root
Copy after login
- View the installation path of the global package
npm root -g
Copy after login
- Check whether the package is outdated
This command will list all outdated packages , you can update the package in time
npm outdated
Copy after login
- Access npm's json folder
An npm package is a folder that contains package.json , package.json describes the structure of this folder. The method of accessing npm's json folder is as follows
npm help json
Copy after loginThis command will open a web page in the default way. If the default opening program is changed, it may not open as a web page.
- Check whether the package name already exists
When publishing an npm package, you need to check whether a certain package name already exists
npm search packageName # 也可以使用縮写 s 來替代 search npm s packageName
Copy after login
npm cache clean # 清除npm的缓存
npm prune # 清除项目中没有被使用的包
npm outdated # 检查模块是否已经过时
npm repo jquery # 会打开默认浏览器跳转到github中jquery的页面
npm docs jquery # 会打开默认浏览器跳转到github中jquery的README.MD文件信息
npm home jquery # 会打开默认浏览器跳转到github中jquery的主页
Copy after login
npm cache clean # 清除npm的缓存 npm prune # 清除项目中没有被使用的包 npm outdated # 检查模块是否已经过时 npm repo jquery # 会打开默认浏览器跳转到github中jquery的页面 npm docs jquery # 会打开默认浏览器跳转到github中jquery的README.MD文件信息 npm home jquery # 会打开默认浏览器跳转到github中jquery的主页
npm dependent package version number
##npm version number format X.Y.Z
means: major version number. minor version number. revision number. The increment rules of the version number are as follows:
X. Major version number: when you do Incompatible API modification,- Y. Minor version number: When you make a backward compatible functional addition,
- Z . Revision number: when you make a backwards compatibility fix.
依赖库版本号、符号
- 没有任何符号
1.0.0 完全百分百匹配,当前库/项目必须使用当前版本号,如果和其他依赖使用了相同库不同版本,会在库的文件夹下建立一个 node_modules 文件夹存放它需要依赖的版本文件。
- ~ 号
不改变主版本号和次版本号,修订号可以随意更改 例如 ~2.0.0 ,可以使用 2.0.0、2.0.2 、2.0.9 的版本。
- ^ 号
不改变主版本号(主版本号非0),此版本号和修订号可以随意更改 例如 ^2.0.0 ,可以使用 2.0.1、2.2.2 、2.9.9 的版本。
- *号
*表示任意版本 对版本没有限制, 一般不用 "base": "*"
- > 号
大于某个版本,表示只要大于这个版本的安装包都行 例如:"node": "> 4.0.0"
- >= 号
大于某个版本,表示只要大于或等于这个版本的安装包都行 例如:"node": ">= 4.0.0"
- < 号
小于某个版本,表示只要小于这个版本的安装包都行 例如:"http-proxy-middleware": "<0.17.3"
- <= 号
小于或等于某个版本,表示只要小于或等于这个版本的安装包都行 例如:"http-proxy-middleware": "<=0.17.3"
- - 号
-表示两个版本号之间的版本 "base": "1.0.1-1.5.9" 例如 1.0.1-1.5.9 可以使用 1.0.1到1.5.9之间的任意版本
更多node相关知识,请访问:nodejs 教程!
The above is the detailed content of [Compilation and Sharing] Common npm commands necessary for front-end development. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What to do if npm react installation error occurs

How to use express to handle file upload in node project

What should I do if node cannot use npm command?

An in-depth analysis of Node's process management tool 'pm2”

Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node?

How to solve the problem of dependent library installation in C++ development

Let's talk about how to use pkg to package Node.js projects into executable files.
