Bun is a Javascript runtime that claims to be 4x faster than NodeJS. Bun is an all-in-one Javascript runtime & toolkit. Bun ships as a single executable that can be installed on your computer. Bun is written in Zig, a low-level general-purpose programming language. Zig is an imperative, general-purpose, statically typed, compiled system programming language. Zig is supposed to be a replacement for C and C++. Zig is designed to be smaller and simpler to program in while also offering modern features, so you'd expect applications built with Zig to be quite fast, a feature that spills into Bun.
Bun also ships as a package manager that can be installed with the npm install bun
command, which Bun also claims will be the last npm command you ever run, I'll keep an eye on this because the bum package manager claims to be 33X faster than npm when installing packages and all existing npm packages can be installed with the bun package manager.
Bun is also a test runner and it is a direct replacement for existing test runners because it claims to be 32X faster than Jest+Babel and 8X than Vitest. These are crazy numbers. A stable 1.0 version of Bun was recently released in September 2023.
Bun is designed with three main goals in mind;
- Speed
- Simplicity
- Providing a full development ecosystem
In today's post, I'm going to go over 6 reasons why I think Bun is the next big thing since Typescript. Here are the main talking points;
- Full compatibility with NodeJS
- Out-of-the-box support for Typescript
- Consistent module imports
- Default Watch Mode
- Bun Internal APIs
- Compact Development Experience
- Why should you care?
Full compatibility with NodeJS
Bun is intended to be a direct replacement for NodeJS, it offers full support for all of the existing NodeJS APIs and you will feel just at home like you're working with NodeJS. This is important because most developers would rather just stick to what works especially if they have to start adapting to using newer APIs. The full compatibility with NodeJS will significantly reduce the learning or adoption curve.
Out-of-the-box support for Typescript
Bun has first-class support for Typescript and it will directly execute your Typescript modules without any further compilation step. This can significantly reduce your overall build step because you are not worried about converting your Typescript to valid Javascript, which has already been taken care of.
Consistent module imports
Bun allows you to do what I call a "consistent module import" This catchy phrase just means that Bun reduces all your worries about moduleResolution
. You can use import {} from 'file'
or require('module')
in any of your modules and you can even mix them in the same file and everything will work just fine, eliminating the need to configure and use a consistent module Resolution throughout your codebase.
Default Watch Mode
Bun has a default watch mode in which you can run your apps. This will allow you to preview live changes in your applications as they happen without having to configure them or install a package for that. This is in stark contrast to NodeJS where you have to install the nodemon
package if you want to develop your application in watch mode. This is another bonus to your overall workflow because you don't need to set up nodemon for any of your future projects on Bun.
Internal APIs
Buns also has its internal APIs that are different from the core NodeJS APIs. Although they offer the same functionalities as the NodeJS API they're more elegant and simpler to use when compared to Nodejs core APIs. There is the Bun.serve({})
which allows you to quickly spin up a server. Compare this to how many lines of code it would take to spin up a server in NodeJS. There are also APIs for reading and writing to files that are more elegant than what we currently have in NodeJS.
Compact Development Experience
The overall goal of Bun is to provide developers with a complete toolbox for developing applications from a single platform. Most of the existing steps in application setup and development are already taken care of by Bun. Allowing you to focus on developing your application as fast as possible as opposed to trying to set up your development environment first. Gone are the days of npm I demon
, gone are also the days of npm i -D @types/package
. This is another reason why Bun is so easy to use.
There are other awesome features of Bun that we had to skip in this post for time's sake nonetheless here is a quick breakdown;
- Bun implements most of the Existing Web APIs directly into the run time, things like fetch, alert, confirm, etc.
- Bun supports
.jsx
and.tsx
files out of the box. - Bun has the fastest package manager with an install speed of less than half a second.
Why should you care?
Does this mean that we should all uninstall our NodeJS and start installing Bun, this is a highly unlikely situation because people adopt things slowly, so it's going to take some time before we see a large-scale adoption of Bun if at all it happens. Besides there are also some drawbacks to getting started with Bun.
- It is only available for installation on Linux and Mac OS, there is no Windows-compatible version of Bun, The only way to get around this is to install the WSL version.
I found this to be very annoying as I am currently using a Windows PC and I don't want to set up WSL on it. But anyway let me know what your thoughts are on Bun, do you think that It will replace NodeJS and npm? How fast do you think that could happen if at all it will happen? What would you like me to write about Next Still on the Bun? I will see you in the next post.
Top comments (29)
I find it very funny that, at v1.0, it does not run on Windows. What is going on in their minds? It's just weird.
I don't care about the OS war, use whatever floats your boat, but you can't ignore that Windows has the largest desktop market share. If you aim at something solid and popular, how can you not support it?
Yeah I hope they make windows a priority.
Yeah I do hope too. You don't only target server OS developer OS is also very important because who will be developing the apps to run on the server?
Exactly. We'll see š
Not to put too fine a point on it, they're hedging their bets.
In 2023, in a survey of over 87,000 developers, Windows use for personal use has fallen to 59.72% (down from 62.33% just last year), and clear down to 46.91% (down from 48.82%) for professional use. The rest being almost unilaterally (99.3%) MacOS and some flavor of Linux. Let that sink in. MORE THAN HALF of the surveyed professional developers are using a non-Windows platform. Go ahead and lump in the 15.68% of the windows developers who DO use WSL and now we're teetering JUST below 66%.
2 out of 3. Developers. Do. Not. Use. Windows. For. Development.
So it's not even that they're "targeting server OS". They're targeting the majority.
I get it. It's clunky and slow. But speaking as a 28-year veteran web software engineer, I have some bad news for you if you choose to stay in this field: you will have to totally re-learn your job every 5 year or so, on average. I've had to six times now. Things are moving too fast to do otherwise.
I understand that too (though I'm typing this on my server dev box... running Ubuntu, sitting next to my company-issued MBP, and over the M2 Pro Mac Mini mounted to the underside of my desk). Indeed: using Linux is not dissimilar to punching yourself in the nuts: it hurts, it take real willpower to keep doing it, and it's typically not necessary for the average guy... but hey: it's free.
That said, allow me to introduce you to a third option: Get. A. Mac.
I can respect the hesitation, though you're only half right about the second point: Good Macs are expensive. But if it's only cost that makes you twitchy about learning a new OS, slightly-older or even a lower-powered contemporary machines are windows-comparable, cost-wise (I paid 600 for my M1 Mini the month they came out). Besides: cost of doing business. If you're working in the field? You can afford it; it's considered "professional development", and you can even write it off. If you're still learning? Well, statistical trends suggest that's the way things are headed, and better to learn now than try to on the job.
And if ALL THAT doesn't clench it for you? If the idea of moving away from what is arguably the worst development environment available on the market today because it's too scary/hard/expensive/time-consuming?
FINE. Windows support is supposed to land on Monday, Nov. 13, 2023. Wimp.
Great thanks for adding the detail! I didn't realize non-Windows had grown that much! I knew it had grown.
The majority of developers use Linux or Docker with a Linux container, why would you need Windows support for those environments? Plus, if you understand how it is doing things under the hood to get the faster performance, you would realize that it is using features from Unix(-like) environments and that is why Windows will take longer to support.
This is the same as Windows and Linux having thousands of games to play and Apple having to wait for them to be ported; not supporting open standards and using proprietary ones are the reason for a platform to be behind.
You aren't going to run the server from your developer machine, you will deploy it.
You can find their open issue ticket here.
github.com/oven-sh/bun/issues/43
They're definitely working hard towards it in making a reality in a not-so-distant future. :)
Yes, that's totally weird, considering that most developers use windows. Let's hope that they make a windows compactible executable soon, rather than later.
If you're disappointed, from my experience, Bun doesn't keep one waiting very long for new features. The first beta release was only last year, and the speed at which Bun has added node features has been astounding. One time I was sad that I couldn't implement a little game server in Bun because it lacked websockets, and a few weeks later it got it. Another time I was sad because I needed web workers, checked again next month, again got it.
That's been my experience trying to replace Node with Bun: I'd be sad that a certain feature was missing, and it would be implemented the next time I checked. Read streams, Svelte support, Vite support, node:tty... and whenever something would get implemented, it would come with tons of other features and optimizations.
Anyway, hang in there! Jarred and the Oven team are extremely capable and dedicated; I'm sure you won't be waiting long :)
Windows should move to Unix but keep the UI the same. These c:, d:, e: and so on have been proven to be a bad design. Nowadays kids donāt even know what HDD or SSD are. They only know cloud stuff like OneDrive or Outlook. Developers shouldnāt use Windows, unless you build windows apps using costly commercial Visual Studio. Itās a shame you still use Window$, you should use Linux and enjoy coding.
Yeah it's quite careless
It would be great if you could cite some references and resources where you claim these numbers come from.
You can definitely check up their home page for reference on the numbers
It is just very, very, very slow on WSL. I don't think it's worthy worrying about Bun just yet since it is really new. But its performance does shine bright, with some sequential requests comparing Node (v20) x Bun (v1.0) on Linux (Ubuntu 22.04) and allocating the JSON in memory (common array), the GC-ed time for Bun is amazing.
The benchmarks for 1000 were in contrast with 2min32s for cold run on Node, 1min18s for the second run on Node.
This is great to know, I'm glad I didn't really bother trying to set it up on WSL. Although I didn't expect it to be slow on WSL, could this be a platform specific problem or it's just your device.
I'd go on so far to say that it's not a device issue, since the WSL environment was a i7 11th gen, 16GB ram, Nvidia integrated GPU and the Ubuntu environment was a random VPS with a somewhat of a average latency. But things are improving quick, hopefully Bun will be ready for Windows platforms without some workarounds like these
Why does it matter if it's not available for Windows?
I suppose we can run it in Docker anyway, right?
There is a Docker image available.
It's mentioned here in the official documentation :
bun.sh/docs/installation
For me, Docker is not an obstacle.
On the contrary, it actually helps to be cross-platform.
This is not necessarily a good or bad argument, it depends on the reality of each developer :)
Why some of my comments are now hidden?
YantraJS is built on .net core and it can run also on mobile devicesā¦
But whoās behind Bun, whatās the motivation for building Bun besides speed? Is there a company behind Bun who fund the project for own interest? And what about Deno, why not cooperate with Deno?
Interesting point, but maybe you could check up the home page to get more information on that
Great article š I think Bun might replace Node.js, but it may take around three - five years
Thanks Vlad, I have the same opinion too... I see a future where Bun becomes the standard but that's going to take some time though.
sounds promising , hope this is not another repeated js framework
This one is really different. Bun has a lot of potential.
Some comments have been hidden by the post's author - find out more