DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Bun, the new Javascript runtime competing with Deno and Node
Saji Wang for Codesphere Inc.

Posted on

Bun, the new Javascript runtime competing with Deno and Node

Incredible amounts of discussion have taken place over the past couple years over Deno, Ryan Dahl’s successor to the NodeJS runtime meant to solve all the problems of his original creation.

In reality, despite Deno being largely stable and solving a lot of the issues with Node, it hasn’t received significant adoption because it isn’t compatible with existing node modules.

The development world was caught by surprise when Bun, a new Javascript runtime, launched its public beta about a week ago.

Bun’s pitch is that it is solving the problems that Deno does and is compatible with the existing Node ecospace, all while being significantly faster than both Deno and Node.

Let’s dive in


The Issues with Node

Despite its widespread usage for the past decade, NodeJS has its fair share of problems.

The most egregious issue with Node is the incredibly convoluted nature of NPM and the entire module system. Not only can it be incredibly slow and unsecure, but the design of the system is drastically different from what is typical of web technologies.

Additionally, Node has near complete access to the system, which is a major security flaw.

On top of all that, some of the standard capabilities that a developer is going to need, like environment variables, https, or Typescript, aren’t included in Node out of the box.

Most of these issues seem to be solved with Deno, but at the expense of the entirety of the Node ecosystem. For the vast majority of developers, solving these issues simply isn’t worth jumping into a completely new ecosystem, and thus we haven’t seen adoption of Deno.


How Bun solves them

Now while Bun is very much in its infancy, it seems to largely be solving the lack of built-in support and the unfortunate speed issues of Node.

Bun claims to be more than twice efficient on many key tasks than both Node and Deno

Image description

Image description

Image description

Bun achieves this by not running on the V8 engine that Deno and Node use, and instead opting for the incredibly low level language Zig.

Additionally, Bun is a drop-in solution for Node, so it is already compatible with the entirety of the Node ecosystem that’s out there.


Trying out Bun

You can install Bun on Mac and Linux with:
curl https://bun.sh/install | bash

And then you can run a js file with:
bun run index.js

And you can install your NPM packages with:
bun install package-name

As you can see, the CLI is effectively identical to Node’s, which means there’s no learning curve.


What to Keep in Mind

Keep in mind that Bun was launched barely over a week ago. It is still very-much full of bugs. You are likely to run into some issues if you are trying to play around with it.

Additionally, this means we are yet to see what comes of this project. Will it really solve all the issues of Node and finally dethrone it? Maybe. But it might also be the case that Bun simply can never achieve the stability of Node.

We will likely find out the fate of BunJS over the next year…


At Codesphere, we’re also in the business of making web development faster, smoother, and less stressful. We’re building an all-in-one web IDE, DevOps tool, and cloud provider.

Happy Coding!

Top comments (8)

Collapse
ecyrbe profile image
ecyrbe

I don't see how Bun will solves security and packaging issues of node.

It's marketed as a compatible runtime with node package and runtime model.

It's from what i see only tackling performance side of things.

Even then, i doubt performances will keep it's promise once it becomes featurefull.

Collapse
sewangco profile image
Saji Wang Author • Edited on

I think you're right, but also keep in mind Bun is in its infancy. Hopefully they take some inspiration from Deno and try to solve those security and packaging issues.

Collapse
xhyrom profile image
Hyro
Collapse
ecyrbe profile image
ecyrbe • Edited on

In fact no, the answer is pretty symptomatic of someone who don't care about security. It's almost a joke to read such an answer.

Thread Thread
kevlened profile image
Len Boyette

That’s an odd take. In deno, there could be a bug in the runtime detection. The linked suggestion is to avoid runtime bugs by removing features a user doesn’t want (like networking) from the bun binary entirely.

Collapse
pengeszikra profile image
Peter Vivo • Edited on

Bun writed in ZIG, if benchmark is right, that also prof the speed of ZIG.

I like the Zen for ZIG developers ( found end of ZIG documentation )

Zen

  • Communicate intent precisely.
  • Edge cases matter.
  • Favor reading code over writing code.
  • Only one obvious way to do things.
  • Runtime crashes are better than bugs.
  • Compile errors are better than runtime crashes.
  • Incremental improvements.
  • Avoid local maximums.
  • Reduce the amount one must remember.
  • Focus on code rather than style.
  • Resource allocation may fail; resource deallocation must succeed.
  • Memory is a resource.
  • Together we serve the users.
Collapse
jwp profile image
John Peters • Edited on

That's sweet. Maybe they can rename it to honeybun.

Collapse
alexmario74 profile image
Mario Santini

Thanks to introduce Bun, I didn't know about it and it is an interesting project to keep an eye on.

Anyway, I noticed there are some wrong assertion in your post:

"...like environment variables, https, or Typescript, aren’t included in Node"

Actually, environment variables and https are included in Node.

I have a look to the Bun docs and what it offers more than Node is a built in dotenv, fetch, and WebSocket packages.

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.