当前位置:网站首页>NPM and yarn use (official website, installation, command line, uploading your own package, detailed explanation of package version number, updating and uninstalling package, viewing all versions, equ
NPM and yarn use (official website, installation, command line, uploading your own package, detailed explanation of package version number, updating and uninstalling package, viewing all versions, equ
2022-07-28 08:55:00 【YF-SOD】
Catalog
npm i [email protected] Version number
install git The package released on
npm config set registry https://registry.npm.taobao.org
yarn add [email protected] Version number
yarn upgrade [email protected] Version number
npm
NodeJS Package management and distribution tools .
Official website
npm install packageName
Install dependency packages .
--S(--save): default , Used to write package.json Production environment document .
-D(--save-dev): Used to write package.json Development environment file .
-g(-global): Global installation , Not -g All are locally installed . Here is -g The installation directory
![]()
mac The global installation directory is /User/ Your username /.nvm/versions/node/nvm edition /bin
window The global installation directory is C:\Users\ Your username \AppData\Roaming\npm\node_modules
Partial installation passed node_modulet/.bin/packageName Run non -g Downloaded module commands .
npm i [email protected] Version number
Automatically install the specified version of the package , Except for the specified version number , Other version numbers are automatically the latest .
Version number includes : The major version number . Sub version number . Patch number
package.json in ^ It refers to locking the major version number ,~ It refers to locking the major version number and minor version number , Empty finger locks the entire version number ,* Refer to the latest version .
install git The package released on
# This is suitable for the installation of... Within the company git The project on the server
npm install git+https://[email protected]:lurongtao/gp-project.git
# Or with ssh The way
npm install git+ssh://[email protected]:lurongtao/gp-project.git
The red box in the following figure is through git Installation of the package

npm ci
according to package-lock.json(npm i Post generated files , Used to lock versions and record dependencies ) File installation depends on . comparison npm i Speed increased significantly . Also support --production Parameters .
Be careful ( contrast npm i)
- npm ci Cannot be used to install a single dependency , Can only be used to install dependencies for the entire project
- npm ci Will detect if
node_modulesAlready exist , Delete first and then install - Will not update
package.jsonorpackage-lock.jsonfile , The whole installation process is locked . package-lock.json、npm-shrinkwrap.jsonIf the file does not exist, an error will be reported- lock And
package.jsonThe version in does not match ,npm ci Direct error reporting interrupt , Instead of updating lock file .
Recommended :npm ci --cache .npm --quiet --no-progress close log And progress , It can speed up the download .
npm outdated
Show package.json The other version bits under the locked version bit in are not the latest packages .

npm update
take package.json Other version bits under the locked version bit of the package become the latest .

npm init -y
Generate package.json Module profile .
At this point through npm run dev The command is equivalent to entering ./node_modules/.bin/gulp -v.
Note that the red box below can be removed , function npm run dev Command will automatically go to the global to find the corresponding file , If not, you will go to the current path node_modules Search for .

stay scripts The script written on , The environment to run from the command line is node Environment .
npm list
Check the versions of all installation packages and dependent installation packages .

npm list | grep packageName
View the version of the specified installation package and the dependent installation package
npm install --production
Install only package.json Production environment package in .
npm view packagename versions
View all versions of the specified package
npm cache clean --force
eliminate npm cache ( Use when you can't download after downloading errors )
npm config get registry
Get the remote warehouse Path .
npm config set registry https://registry.npm.taobao.org
Set the remote warehouse address to Taobao image path , The default remote warehouse address is http://registry.npmjs.org.
module.exports = Variable name
You can also directly exports Mount variables on ,exports by module.exports References on ( You can't give it directly to exports assignment )
require('./ route ') You cannot write the beginning of the file name directly , What is introduced is export References to .
npm install express-generator -g Command to install
express -h Option to list all available command line options
express -e Directly generate the server-side project
Upload your own package
land npm Official website , Password of registered account , Execute the following command . Note that the uploaded package should have packgage.json file .package.json in name For the uploaded package name ,version Version number ,description by readme Described in the .

npm adduser
Landing user . Note that the remote image warehouse should be http://registry.npmjs.org. If not, you need to reset the original address and log in again .
npm publish
Upload your own package .
yarn
Package management and distribution tools . Only partial and npm The command line has different commands .
Chinese official website
install
install | Yarn Chinese document
Command line
yarn add [email protected] Version number
Install dependency packages .
--dev(-D): Development environment dependency , Used to write package.json Development environment file .
--peer(-P): Equally dependent on , Or peer dependence ( When multiple packages depend on 1 A bag , Use when you need to unify the version of this package ).
--optional(-O): Optional dependency , If there are some dependent packages, even if the installation fails , Install alternate packages to keep the project running . You can use optionalDependencies. Be careful packageName in optionalDependencies Will be covered dependencies Dependency package with the same name in , So don't write in both places .
yarn|yarn install
Install all dependent packages .
yarn upgrade [email protected] Version number
Upgrade the dependent package to the specified version .
yarn remove packageName
Uninstall the specified dependent package .
yarn dlx mocha --version
need yarn2 Version of , amount to npx mocha --version. Used to call modules installed inside the project .
nvm、nrm、npx Use ( install 、 Basic commands 、 Parameters 、curl、wget)_YF-SOD The blog of -CSDN Blog
边栏推荐
- Service current limiting and fusing of micro service architecture Sentinel
- What content does the new version of network security level protection evaluation report template contain? Where can I find it?
- CAT1 4g+ Ethernet development board 232 data is sent to the server through 4G module TCP
- Recruiting talents, gbase high-end talent recruitment in progress
- 我来教你如何组装一个注册中心?
- JS inheritance method
- Simple use of unity queue
- Analysis of model predictive control (MPC) (IX): numerical solution of quadratic programming (II)
- NDK series (6): let's talk about the way and time to register JNI functions
- 49 opencv deep analysis profile
猜你喜欢
![Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]](/img/97/6c3662ef36b02bc42eec95abaa6bc5.png)
Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]

The current value of uniapp's swiper dynamic setting does not take effect solution

Shell编程规范与变量

Hcip day 9_ BGP experiment

Blog Building 9: add search function to Hugo

Completion report of communication software development and Application

Gb/t 41479-2022 information security technology network data processing security requirements map overview

客户至上 | 国产BI领跑者,思迈特软件完成C轮融资

Flink Window&Time 原理
![Detailed explanation of DHCP distribution address of routing / layer 3 switch [Huawei ENSP]](/img/9c/b4ebe608cf639b8348adc1f1cc71c8.png)
Detailed explanation of DHCP distribution address of routing / layer 3 switch [Huawei ENSP]
随机推荐
Pyspark writes data to iceberg
Will sqlserver CDC 2.2 generate table locks when extracting large tables from the source
Why can ThreadLocal achieve thread isolation?
Flink Window&Time 原理
Solution: indexerror: index 13 is out of bounds for dimension 0 with size 13
How to import and export Youxuan database
ciou损失
Let me teach you how to assemble a registration center?
SQL注入 ----前置基础
Three ways to create threads
PostgreSQL queries [table field type] and [all series] in the library
Image batch processing | necessary skills
模型预测控制(MPC)解析(九):二次规划的数值解(下)
Hcip --- LDP and MPLS Technology (detailed explanation)
看完这12个面试问题,新媒体运营岗位就是你的了
PostgreSQL: cannot change the type of column used by a view or rule
I use SqlClient normally, and dlink submission will report this error. What should I do?
Among China's top ten national snacks, it is actually the first
Redis basic knowledge, let's review it
bash-shell 免交互