当前位置:网站首页>Recognize pnpm: faster, higher performance NPM
Recognize pnpm: faster, higher performance NPM
2022-06-26 06:58:00 【Code Taoist】
What is? PNPM?
PNPM yes Node.js Used in substitution NPM Another package manager for , representative “Performant NPM”.
PNPM The main purpose of is to keep all packages in one global ( Centralized ) In storage , And use them when other projects need them by creating hard links .
Use PNPM be better than NPM The advantages of
- Save a lot of disk space .
- Installing software packages takes more time .
- It is right. mono Built in support for repositories .
Now? , Let's try to understand PNPM How it actually works .
So , I need two applications to understand PNPM Use the concepts behind the scenario .
These are two applications package.json file :
{
"name": "application1",
"version": "0.0.0",
"private": true,
"main": "app.js",
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"csurf": "^1.10.0",
"debug": "~2.6.9",
"ejs": "~2.6.1",
"express": "~4.16.1",
"express-session": "^1.17.0"
}
}
{
“name”: “application2”,
“version”: “0.0.0”,
“private”: true,
“main”: “app.js”,
“scripts”: {
“start”: “node ./bin/www”
},
“dependencies”: {
“cookie-parser”: “~1.4.4”,
“csurf”: “^.10.0”,
“debug”: “~2.6.9”,
“powerbi-client”: “^.16.5”,
“rxjs”: “^.5.3”
}
}install
First , I use... By running the following command npm Installed pnpm:
npm install -g pnpmBe careful : My system has been installed with Nodejs v16.13.2 and NPM v6.28.0.
We can test by running the following instructions PNPM Is the installation successful :
pnpm -vThe above command is used to check which version of pnpm.
PNPM And NPM What's the difference? ?
In order to understand their working differences , I am for npm and pnpm Two directories are created respectively , Both use two sample applications , And use npm and pnpm Install the software packages in different directories .
npm
application 1:
[email protected]:~/npm-demo$ npm install
added 71 packages, and audited 72 packages in 1s
found 0 vulnerabilitiesapplication 2:
[email protected]:~/npm-demo2$ npm install
added 27 packages, and audited 28 packages in 9s
found 0 vulnerabilitiesad locum , As you can see ,npm In the application 1 Installed in 71 A package , In the application 2 Installed in 27 A package , This is very good .
however , If you look at these two applications from the front package.json file , You will find that both have something in common Three bags .
Even if the application 2 Need some installed dependencies ( In the application 1 in ), We can't reuse what has been npm Dependencies installed by another project in .
pnpm
application 1:
[email protected]:~/pnpm-demo$ pnpm install
Packages: +67
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are hard linked from the content-addressable store to the virtual store.
Content-addressable store is at: /home/rach/.pnpm-store/v3
Virtual store is at: node_modules/.pnpm
Progress: resolved 67, reused 0, downloaded 67, added 67, done
dependencies:
+ cookie-parser 1.4.6
+ csurf 1.11.0
+ debug 2.6.9 (4.3.3 is available)
+ ejs 2.6.2 (3.1.6 is available)
+ express 4.16.4 (4.17.2 is available)
+ express-session 1.17.2application 2:
[email protected]:~/pnpm-demo2$ pnpm install
Packages: +27
+++++++++++++++++++++++++++
Packages are hard linked from the content-addressable store to the virtual store.
Content-addressable store is at: /home/rach/.pnpm-store/v3
Virtual store is at: node_modules/.pnpm
dependencies:
+ cookie-parser 1.4.6
+ csurf 1.11.0
+ debug 2.6.9 (4.3.3 is available)
+ powerbi-client 2.19.1
+ rxjs 6.6.7 (7.5.2 is available)
Progress: resolved 27, reused 18, downloaded 9, added 27, doneFrom output , We can notice that pnpm In the application 1 Installed in 67 A package , In the application 2 Installed in 27 A package . however , If you look at the last line in the output —— speed of progress , You will find that it reuses what has been done for the application 1 Installed 18 A package .
“ stay pnpm in , If you have installed a package for another project , Then they will always be reused , This saves a lot of disk space , This makes it more than npm faster 、 More efficient .”
This is amazing !
But where are these packages stored ?
Use pnpm install, Especially this line in the output ,“Packages are hardlinked from the content-addressable store to the virtual store”, Shows how it works .
Content addressed storage is a storage mechanism , The data is stored on the hard disk by assigning a permanent location and addressing it with a unique identifier .

In the screenshot above , You can see that a file named “.pnpm-store” Hidden directory for .
Hidden files can be system or application files stored on a hard disk drive with a permanent location , And hidden to prevent any accidental changes .
This hidden directory —— .pnpm-store go by the name of “ Content addressable storage ”, All downloaded dependencies are stored in it .
Whenever you download a dependency ,pnpm First, check whether the dependency exists in this store .
Hard links are just exact copies of the original file , It also points to the hard drive ( Of the original document ) Same position .
If a dependency already exists in this store , be pnpm Retrieve the same content by creating hard links .
Conclusion
By explaining pnpm And npm The difference between , And the use of pnpm Instead of npm The benefits that can be obtained , We are right. pnpm With a simple understanding . You've tried before pnpm Do you ? What do you think of it ? Do you have any idea ?
边栏推荐
- What is deadlock
- Rust中的过程宏
- 我在腾讯做测试的这几年...
- China imported wine circulation and investment market survey and Future Development Trend Outlook report 2022-2027
- [004] [stm32] MDK project configuration and commissioning
- web入门之 Promise API
- Distribution operation of D
- [golang] time related
- MYSQL(三)
- How to open an account in flush? Is it safe to open an account online?
猜你喜欢

Decision tree learning notes

我在腾讯做测试的这几年...

Solution of garbled code in sparkshell deletion key of SecureCRT

遇到女司机业余开滴滴,日入500!

营销技巧:相比较讲产品的优点,更有效的是要向客户展示使用效果

Procedure macros in rust
![[004] [stm32] MDK project configuration and commissioning](/img/a8/9817cdbbce557a92739de494490706.jpg)
[004] [stm32] MDK project configuration and commissioning

数据湖架构之Hudi编译篇

二叉树中和为某一值的路径(一)(二)(三)(剑指offer)

报错问题Parameter index out of range(0 < 1) (1 > number of parameters,which is 0
随机推荐
Marketing skills: compared with the advantages of the product, it is more effective to show the use effect to customers
Simple use of enum type in TS
Past events of Xinhua III
Kotlin Compose 状态恢复 rememberSaveable 与 remember
Go learning notes 1.3- data types of variables
NumPy学习挑战第一关-NumPy的下载与安装
How to set MySQL triggers is a simple tutorial for novices
[image fusion] MRI-CT image fusion based on gradient energy, local energy and PCA fusion rules with matlab code
[digital signal processing] basic sequence (basic sequence lists | unit pulse sequence | unit pulse function | discrete unit pulse function | difference between unit pulse function and discrete unit p
报错问题Parameter index out of range(0 < 1) (1 > number of parameters,which is 0
What is deadlock
Solve the problem of cross domain invalidation of cookies in the new version of Google Chrome browser
[micro service series] protocol buffer dynamic analysis
My SQL (II)
SQL基础
Simple use of typescript's class interface
【图像检测】基于Itti模型实现图像显著性检测附matlab代码
Bugku练习题---MISC---富强民主
MySQL基础用法01
Format one insert per line using mysqldump- Using mysqldump to format one insert per line?