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 (18)

Collapse
 
kanonidb profile image
Md. Kanon Biswas

I am use npm. But I do not install npm directly, I am using nvm that handel multiple version of npm. It's so simple to handel multiple project those are build using different version of node without docker container. Now my question is if I have multiple project those are use different version of node then can I handel it with bun?

Collapse
 
best_codes profile image
Best Codes

nvm doesn't make npm any faster (it's just different npm environments) but it is certainly very useful!
When I used npm I used nvm too.
I don't think there is a Bun equivalent (to be clear: nvm is not by npm and does not come with it; it's a third-party thing), though you can globally install bun with npm and use different versions of bun that you have installed in your different npms. (Obviously that's pretty annoying to deal with).

I have seen this, but have not tried it yet:

GitHub logo owenizedd / bum

Bum - Bun Version Manager ⚑

Bum - Bun Version Manager


GitHub CI Status

Introducing Bum, a fast Bun version manager written in Rust from scratch

How to install:

Unix

  1. Open your terminal and execute:
curl -fsSL https://github.com/owenizedd/bum/raw/main/install.sh | bash

This installation will install bun for you and also bum altogether.

Windows

I only own a Mac, so I can't test at all if Windows is working, and I can't write a script to auto-install on Windows as well. So here are a few instructions on how to install Bum for Windows:

  1. Install Bun
  2. Download the last exe in the latest release, and unzip it
  3. Put the exe in your favorite directory, add the path to this directory in your PATH, and that's it!

As Bum is not tested at all on Windows, it may not works. If it's the case please open an issue and I'll be glad to fix it.

How to use:

  • You can just…

Perhaps I'll make my own solution for this.

Collapse
 
arnavk-09 profile image
ArnavK-09

I am πŸ’€

Collapse
 
maxifjaved profile image
Muhammad Asif Javed

my choice is volt.sh

an awesome tool for node management

Collapse
 
best_codes profile image
Best Codes

In my experience, NVM works great. Can volt manage Bun versions?

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…

Collapse
 
bradstondev profile image
Bradston Henry

At my old company, we used to have Front-End meetups and one person broke down the install time differences and I've been convinced since then. But I have yet to try it out. πŸ€¦πŸΏβ€β™‚οΈ I think you have finally pushed me to give it a go. πŸ™ŒπŸΏ

Collapse
 
best_codes profile image
Best Codes

Yay! :D
You'll love it :)

Collapse
 
devmercy profile image
Mercy

Thank you for sharing, I've been there too

Some comments may only be visible to logged-in visitors. Sign in to view all comments.