DEV Community

Cover image for How npm Crashed Our VPS (and What Finally Fixed It)
Olushola
Olushola

Posted on • Originally published at codewithgeeky.hashnode.dev

How npm Crashed Our VPS (and What Finally Fixed It)

Our VPS kept crashing every time we ran npm install.

I thought it was Docker bringing down our server. I removed our entire Docker setup and installation, but the issue wasn’t fixed.

After hours of debugging and a few restarts, the fix turned out to be just one line (not quite).


npm Resource Overload

We use a simple bash script for our deployment flow.

#!/bin/bash

set -e

REPO_SSH="git@github.com:user/repo.git"
APP_DIR="/home/xxx/project"
ENV_FILE="/home/xx/.env.prod"

echo "==> Pulling latest code..."

if [ -d "$APP_DIR" ]; then
    cd $APP_DIR
    git pull origin main
else
    git clone $REPO_SSH $APP_DIR
    cd $APP_DIR
fi

echo "==> Copying env..."
sudo cp $ENV_FILE "$APP_DIR/.env"

echo "==> Install dependencies and build output ..."

npm ci && npm run build

echo "==> Deploy via PM2..."

pm2 deploy ecosystem.config.js production

echo "✅ Deployment complete!"

Enter fullscreen mode Exit fullscreen mode

We had a more complex setup using Docker, but it was removed as stated earlier.

We noticed a memory spike during dependency installation. RAM usage was above 80%.

Within minutes, our server was struggling to keep up with the demand.

API calls were unresponsive, and the nginx proxy was no longer responding to client requests.

Our entire VPS came to an instant halt.

npm had consumed nearly 2GB of RAM, and the process was so heavy that it forced us to reboot the machine.

We’re running a small VPS and scaling our resources using pm2 clusters

After trying every common fix, clearing the npm cache, and reinstalling Node.js. Nothing worked.

Each install would spike resource usage and hang until the server ran out of memory. It wasn’t a one-time glitch; it happened consistently.

Increasing memory wasn’t an option because we wanted to keep our server budget very tight. And I also wanted to fix this for Aura (IKYK).

Switching to pnpm

Out of desperation, and because the team had begun to notice the unusual downtime.

We decided to test pnpm, an alternative package manager for Node.js known for its efficient dependency management.

Installation was straightforward:

npm install -g pnpm

Then we replaced our existing install command:

pnpm install

And just like that, everything ran smoothly (Yeah, I wish).

We had to actually fix some dependency mismatches, downgrade some packages because of how pnpm handled symlinks, and also explicitly approve some dependency builds.

After all these, we replaced npm with pnpm in our build script.

Memory usage dropped drastically, the process completed faster, and the system stayed stable throughout.

I wondered why we didn’t use pnpm all this time (sigh).

How pnpm Solved It

The main reason pnpm outperforms npm in scenarios like this is how it manages dependencies.

npm duplicates every package into each project’s node_modules folder.

This leads to massive memory and disk overhead, especially for large projects or shared environments.

pnpm, on the other hand, uses a content-addressable store.

Packages are downloaded once and then symlinked into individual projects.

This dramatically reduces redundant data and improves performance across multiple builds.

In short, pnpm is more memory-efficient, faster, and better suited for large-scale projects or CI pipelines where npm often struggles.

Key Takeaway

We spent hours debugging what turned out to be an npm performance bottleneck. Switching to pnpm solved it instantly.

If your build or deployment process feels heavier than it should be.

Or if your servers keep running out of memory during installs, then it’s worth switching to pnpm.

It’s a drop-in replacement that can save you hours of debugging (and a few reboots).


If you like reading about programming in general or real-world experience in the engineering space, then consider subscribing to this Newsletter.

You can connect with me on X(F.K.A. Twitter).

Like. Comment. Share. Happy debugging.

Top comments (0)