DEV Community

Cover image for npm is SLOW! This is better 🍞
Best Codes
Best Codes

Posted on

npm is SLOW! This is better 🍞

Let's face it: we've all waited way too long for npm install to finish. Whether you're racing against a deadline or just impatient (like me), slow install times are quite annoying.
Enter Bun, the super fast alternative to npm that's making quite a stir in the JavaScript world. πŸš€

(If you clicked on this post because of the cover image, now you know β€” it was a reference to Bun).

What is Bun?

Bun isn't just another package manager β€” it's a performance-focused runtime built from the ground up with speed in mind. Instead of relying on Node.js's V8 (which is also used by Chromium), Bun uses JavaScriptCore (from WebKit), giving it an edge in raw performance. This translates to dependency installations that are up to 29x faster than npm, 17x faster than pnpm, and 33x faster than Yarn. Yes, you read that right: 29 times faster. πŸ”₯

Why is Bun so Fast?

  1. Bun's core is written in Zig, a low-level language that ensures efficient memory management.
  2. Bun doesn't need separate tools for bundling, transpiling, or hot reloading, as they're all built-in, reducing overhead.
  3. Unlike npm's package-lock.json, Bun uses bun.lockb, designed for speed and minimal file conflicts.

Key Features of Bun:

  • Blazing-fast Installs: Run bun install and see your dependencies appear almost instantly.
  • Built-in Bundler: No more juggling Webpack or Vite β€” it's all here. Bun builds 188x faster (over one hundred times faster) than rollup with terser and about 2x faster than modern builders like esbuild.
  • Faster CI/CD: Say goodbye to painfully slow dependency setups in your pipelines.
  • Secure: Bun only runs lifecycle scripts for trusted dependencies, unless explicitly approved.

Getting Started with Bun

Switching to Bun is super simple. Support for Windows was recently released (see bun.sh), but here's how to use it on macOS and Linux:
1. Install Bun:

curl -fsSL https://bun.sh/install | bash
Enter fullscreen mode Exit fullscreen mode

2. Remove existing lock files:

rm package-lock.json yarn.lock pnpm-lock.yaml
Enter fullscreen mode Exit fullscreen mode

3. Remove node_modules:

rm -rf node_modules
Enter fullscreen mode Exit fullscreen mode

4. Install dependencies:

bun install
Enter fullscreen mode Exit fullscreen mode

Prepare to be amazed. 🀯

My own experience

I heard a lot about Bun and couldn't resist trying it.

I've already tested pnpm (pretty good!), yarn (alright), etc. before, but Bun had some (extremely!) awesome looking benchmarks!

Well, I opened up a giant top-secret project (I'm posting about that soon! 🀫) with lots of dependencies. First, let's try npm install… Oh, well, it froze. So let's cancel it and try again (npm gets a head-start!):

npm install times

To be fair, 421 dependencies is a lot (now none of you will want to use my app). But let's see how Bun handles this (no head-starts!):

bun install

So npm took 20 seconds. Bun took 0.7 seconds.

WOW! I was impressed. You will be, too.

Final Thoughts

Bun isn't just faster β€” it's a productivity booster. If you're tired of staring at a terminal, waiting for npm to do its thing, give Bun a try. It's simple, secure, and stupidly fast. 🍞

Bun isn't just a package manager!

Bun includes a testing framework that’s several times faster than Vite and Jest, a compiler, executable builder, and more!

Bun reduces dependency size (like pnpm)!

You might have heard good things about pnpm, which uses symlinks to reduce the size of node_modules folders (which are usually gigantic).
Bun optimizes node_modules size too, and it's faster (and easier to type πŸ˜‚).

Bun Social Thumbnail

Check out Bun! πŸš€

Discuss!

This is a #discuss post! I kept it fairly short because I want you to comment and tell me what you think. What package manager do you use? Have you tried Bun? (Do you even use JavaScript)? Let me know in the comments!


Thanks for reading!

Benchmarks taken from Bun's website. See https://bun.sh.
Cover image credit: WikiPedia

Top comments (3)

Collapse
 
alt_exist profile image
Alternate Existance

i dont use npm just plain JS :)

Collapse
 
robbenzo24 profile image
Rob Benzo

i barely even code :P

Collapse
 
best_codes profile image
Best Codes

'Vanilla JS'. I do that every so often…