How NPM broke my server

Last Updated October 20, 2024

I own a small 1vCPU and 1GB RAM Digital Ocean Droplet. Which costs me aroud 500rs per month.

So, Last week I was trying to build a Documentation website with Docusaurus for a project. I have pushed the project to GitHub and cloned it to my server.

Then I started installing with npm. I ran npm install and it started installing the dependencies. After a few minutes, I got an error saying that the server is out of memory. I was surprised because I have only 1GB of RAM and the server was not doing anything else. And The CPU and Disk usage was very high.

I checked the memory usage with htop. But I couldn’t figure it out because the server was unresponsive. I had to reboot the server to get it back online.

I tried to install the dependencies again, but the same thing happened. I was frustrated and started searching for the issue. I found that npm uses a lot of memory to install the dependencies. I tried to increase the swap memory, but it didn’t help.

Then I was fed up using npm and according to few reddit posts they mentioned that pnpm is a good alternative to npm. So I tried to install pnpm with npm install -g pnpm. It worked and I tried to install the dependencies with pnpm install. It worked like a charm. I was able to install the dependencies without any issues.

Reason behind the issue

Conclusion