Comparison between npm deps and pnpm deps
Tags: webdev, beginners, npm, pnpm
Published: 2022-06-12 12:08:08


![bench mark](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jikd42jev73iupm4vheh.png)
[pnpm.io/benchmarks](https://pnpm.io/benchmarks)

> `pnpm` is a fast, disk space-efficient package manager. 

---

`npm` was my package. Although I saw a lot of posts that `yarn` is faster and useful than `npm`, I just wanted to use a default manager. And recently, I've heard of a new package manager from a colleague. "`pnpm` is faster than even `yarn` and has an interesting structure for it" he said. I thought that it might've been time to move on to another package manager.

`pnpm` takes advantage of **symbolic links** for saving storage, connecting packages without installing, and preventing accessing arbitrary packages, etc.

I don't have enough knowledge to explain well about `pnpm`. There are good explanations in [pnpm.io](https://pnpm.io/motivation).

After reading the document, I just wanted to check my own how `npm` and `pnpm` are different when installing other versions of dependencies that are already installed.

I'm going to show you the test that I've done with a package `express`.

---

## npm

```properties
npm install express
```

![express](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wu0wncdm47pz3e5vkxh.png)

There are many dependencies that related to `express` in *node_modules*.

One of the dependencies is `debug`, and many packages has `debug` as a dependency.

```json
...
 "body-parser": {
      "version": "1.20.0",
      "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.0.tgz",
      "integrity": "sha512-DfJ+q6EPcGKZD1QWUjSpqp+Q7bDQTsQIF4zfUAtZ6qk+H/3/QRhg9CEp39ss+/T2vw0+HaidC0ecJj/DRLIaKg==",
      "requires": {
...
        "debug": "2.6.9",
...
      }
    },
...
 "express": {
      "version": "4.18.1",
      "resolved": "https://registry.npmjs.org/express/-/express-4.18.1.tgz",
      "integrity": "sha512-zZBcOX9TfehHQhtupq57OF8lFZ3UZi08Y97dwFCkD8p9d/d2Y3M+ykKcwaMDEL+4qyUolgBDX6AblpR3fL212Q==",
      "requires": {
...
        "debug": "2.6.9",
...
    "finalhandler": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
      "integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==",
      "requires": {
        "debug": "2.6.9",
...
      }
    },
...
      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
    },
    "send": {
      "version": "0.18.0",
      "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz",
      "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==",
      "requires": {
        "debug": "2.6.9",
...
      },
...
```

![no debug](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdnbz4wyt2958ce7qj3m.png)

As you can see, they don't have `debug`.

![debug in node_modules](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xasvh1zsxmf69zita2ce.png)

`debug` is in *node_modules*. They have the same version of `debug`, it makes sense.

in this case, what will it be going on if I install another version of `debug` in my project?

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ud313088n18pw3d6zq15.png)

I installed `debug@2.6.8`, and the version of `debug` in *node_modules* has changed `2.6.8` from `2.6.9`, because my project needs `2.6.8`.

So, where is `debug@2.6.9`? 

![several debug packages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lrxjg4amhp8s907ry7se.png)

Each packages have `debug@2.6.9`. 

---

## pnpm

Let's do the same process with `pnpm`!

```properties
pnpm add express
```

![pnpm and express](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tioguylcio3ub0cpcjzs.png)
 
I have **.pnpm** and `express` in *node_modules*, it looks clean. 

![packages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2voaxrv7mb7522yq2jk.png)

in **.pnpm**, there are actual versions of packages.

![link view](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvqu3yjd6j5hmfkh8qex.png)

Actually, `express` in *node_modules* is a link. look up the below image.

![document image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q818j1yvr7xlo8prby9q.png)

[https://pnpm.io/motivation](https://pnpm.io/motivation)

And, the packages that have `debug` as a dependency already have `debug` in their *node_modules* as a link file.

![links](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1nd3em2zo0s16hqrqalg.png)
 
If I install `debug@2.6.8`.

![debug link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bcn4pg65sdhoeuu4685.png)

![two debug packages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/39kr92a8tzcfch3wp2qf.png)

`debug@2.6.8` has been installed in **.pnpm**, and a link file has been added in *node_modules*, and it doesn't make any changes in packages like `body-parser`, `send`.

---

## Conclusion

I haven't used `pnpm` in my projects yet though, I can't wait to use this package manager, it looks nice and interesting, and actually, `pnpm` has more powerful features. You will find them in their docs. 

I hope it will be helpful for someone.

Happy Coding!