Spirit 369
, first of all, is new JavaScript runtime and, per its creator saying, “is designed as a drop-in replacement for your current JavaScript & TypeScript apps or scripts ...”
Generally saying, Bun.js is something like the “Swiss knife” of the JS world since you have a bundler, transpiler, and package manager as a single tool.
Sounds promising, isn’t it?!
Bun.js functionsAs a swiss knife of the JS world, Bun.js has different functions so let’s talk about each of them.
Using bun as a bundler/transpilerModern days Node.js is known as a backend tool. I think we sometimes forget that in the beginning, Node.js was mostly used to improve the quality of life for front-end engineers, different tools like gulp/grunt/webpack emerged just for this purpose.
Bun.js supports JSX, Typescript, and TSX out of the box. Want to try it out? Just run bun create react ./app , and then do bun dev to start the dev server. Moreover, you can configure your typescript with a regular tsconfig.json file.
Want to bundle your code for production use? Just run bun bun , and it will create a binary file with an extension .bun with insane speed, then you can publish this file onto a static webserver to serve the content.
For comparison, to bundle a basic Create React App template for production, you need around 6 seconds with Node.js. While Bun.js makes the bundle for 8ms. It is a significant improvement, though we need to remember the fact that Bun.js does not support tree-shaking yet, and I wasn’t able to find a way to chunk the bundle.
Using bun as a backendBun.js has ambitious goals to replace Node.js one day, and a big part of modern Node.js is backend development.
Fortunately, you can install express with Bun, and it will just work. Bun is 2 times faster than Node.js when using Express
Using bun as a package managerBun.js is 4x-80x faster than NPM. You can open your existing application and run bun install to see how fast it will download all the dependencies for your application.
You can use bun add and bun remove to add/remove packages from your application.
Other HighlightsNo DebuggerIt actually does not have a debugger yet.
Bundling and TranspilingThe JS world is changing rapidly. Today we are using JSX because of React, but we also have Angular/Svelte/Vue and they have different file formats, and you cannot just use it with Bun.js at the moment.
TypeScriptBun.js provides TS support out of the box, and they are making the same mistake Deno developers did (even at a bigger scale due to Bundling/Traspiling), someone will have to support the core Bun.js to keep up with changes of the TypeScript. Now to get the latest features of TS you will need to wait for Bun.js to add support for it as well, that may be okay for someone.
Bun.js !== Node.jsBun.js is not 100% backward compatible with Node.js at the moment, though it strives to be as backward compatible as possible. This is a completely separate runtime. Not all Node.js core modules are implemented in Bun.js, like cluster or dns and child_processes, at the moment.
DocumentationAs it is still early beta Bun.js doesn’t have a lot of documentation about it and its internals.
Fast start timeBun has a better start time than Node.js, which can be a great benefit in a Serverless environment, or PC applications built with something like Electron.
Why Bun.js is so fast?First of all, Bun.js is using a different JS engine. Instead of it uses . Apart from that, it is written in the programming language.
My vision of Bun.js’ futureBun tries to be an all-in-one tool that brings a lot of burden to its contributors. In my opinion, Bun should think about how to go UNIX-way. By UNIX-way, I mean having small independent tools that do one thing well and still can play together. Bun.js right now is like a poke bowl, and I would split it into separate ingredients.
The bowl could be a bun-core, a runtime + package manager that would provide the core functionality that would power our application with insane performance and minimal overhead.
Then the bun-core could provide API to extend it with the modules (our ingredients), and a separate module could be installed via a built-in package manager to provide things like bundling or transpiling, support for other frameworks, and so on.
Node.js killer?It is commendable that Bun.js has big ambitions for the future. Its goal is to replace Node.js, though it is still too early to make such statements. The performance of Bun.js is definitely insane, but It tries to replace many tools at once, which places a big burden on the contributors of Bun.js. Moreover, it is written in which is not a very popular programming language, which makes searching for a contributor a tough task, IMHO.
SummaryBun.js is still a too young and immature tool and it will take years to develop it to the extent that we could use it in our production applications. Though it has great potential.
I believe that now Node.js/Deno now will have more “motivation” to improve their performance as much as possible since they have a potentially strong competitor in the market.
Man who knows everything but knows nothing