Fast, disk space efficient npm installs
node_modulesfolder are organized always the same way, the way they are described in
pnpm uses hard links and symlinks to save one version of a module only ever once on a disk.
When using npm or yarn for example, if you have 100 packages using lodash, you will have
100 copies of lodash on disk. With pnpm, lodash will be saved in a single place on the disk
and a hard link will put it into the
node_modules where it should be installed.
As a result, you save gigabytes of space on your disk and you have a lot faster installations!
If you'd like more details about the unique
node_modules structure that pnpm creates and
why it works fine with the Node.js ecosystem, read this small article: Why should we use pnpm?
Install it via npm.
npm install -g pnpm
Do you wanna use pnpm on CI servers? See: Continuous Integration.
pnpm in place of
npm. It overrides
pnpm install and some other command, the rest will pass through to
pnpm install lodash
For using the programmatic API, see: API.
pnpm uses npm's programmatic API to read configs. Hence, you should set configs for pnpm the same way you would for npm.
Furthermore, pnpm uses the same configs that npm uses for doing installations. If you have a private registry and npm is configured to work with it, pnpm should be able to authorize requests as well, with no additional configuration.
However, pnpm has some unique configs as well:
The location where all the packages are saved on the disk.
If true, pnpm will use only the local registry mirror to get packages. If a package won't be found locally, the installation will fail.
Controls the maximum number of HTTP requests that can be done simultaneously.
Controls the number of child processes run parallelly to build node modules.
Dangerous! If false, the store is not locked. It means that several installations using the same store can run simultaneously.
Can be passed in via a CLI option.
--no-lock to set it to false. E.g.:
pnpm install --no-lock.
If you experience issues similar to the ones described in #594, use this option to disable locking. In the meanwhile, we'll try to find a solution that will make locking work for everyone.
If true, symlinks leaf dependencies directly from the global store. Leaf dependencies are
packages that have no dependencies of their own. Setting this config to
true might break some packages
that rely on location but gives an average of 8% installation speed improvement.
pnpm is faster than npm and yarn. See this benchmark which compares the three package managers on different types of applications.
time npm i babel-preset-es2015 browserify chalk debug minimist mkdirp 66.15 real 15.60 user 3.54 sys
time pnpm i babel-preset-es2015 browserify chalk debug minimist mkdirp 11.04 real 6.85 user 2.85 sys
name@versionmultiple times and with different sets of dependencies. npm's shrinkwrap file is designed to reflect the
node_moduleslayout created by npm. pnpm cannot create a similar layout, so it cannot respect
bundleDependenciesmanaged by pnpm.
node_modules/.bin) are always shell files not symlinks to JS files. The shell files are created to help pluggable CLI apps in finding their plugins in the unusual
node_modulesstructure. This is very rarely an issue and if you expect the file to be a js file, just reference the original file instead, as described in #736.
Got an idea for workarounds for these issues? Share them.
node_modulesfolder use disk space if packages are stored in a global store?
pnpm creates hard links from the global store to project's
Hard links point to the same place on the disk where the original files are.
So, for example, if you have
foo in your project as a dependency and it occupies 1MB of space,
then it will look like it occupies 1MB of space in the project's
node_modules folder and
the same amount of space in the global store. However, that 1MB is the same space on the disk
addressed from two different locations. So in total
foo occupies 1MB,
For more on this subject: