Bun — JavaScript just got faster
By Muhammediqbal P— A Technophile .
Bun is built on Zig and has the ability to transpile, set up, and run TypeScript and JavaScript projects. It is a complete utility since it also functions as a package manager. That’s why it’s called all-in-bun ( bundler, transpiler, package manager). This has been made possible via the usage of Zig, a dated programming language that was initially created for video games. It also includes ~90% of Node-API functions (native modules), fs, path, Buffer, and more.
Unlike Deno, Bun is intended to be a drop-in replacement for Node, Webpack, Babel, Yarn, and Post CSS — all in one neat package.
https://gist.github.com/ikku47/4a1e22b8d64bb6ce784005cc92c65d6f#file-deno-node-bun.env
, .toml
, and CSS support (no extra loaders required).Bun uses the JavaScriptCore engine, which tends to start and perform a little faster than more traditional choices like V8 ( Nodejs, Denojs ). The Bun is written in, a low-level programming language with manual memory management.
The Bun is written from scratch including the JSX/TypeScript transpiler, npm client, bundler, SQLite client, HTTP client, WebSocket client, and more.
Supports: macOS x64 & Silicon, Linux x64, Windows Subsystem for Linux (WSL)
curl -fsSL https://bun.sh/install | bash
2. Now it’s Hello World time 😊, Create an http.js file in your project folder:
https://gist.github.com/ikku47/fedfa07d0f4d2cfde16a4133e525c6ac#file-bun-hello-word-js3. Now let’s run it :
bun run http.js
That’s it, you have your first Bun project ready to go.
4. Shall we try a react project now, let’s add react and react-dom to set it up.
bun add react react-dom
https://gist.github.com/ikku47/828e1071d4d53331a2dc60b9cc7a1639#file-bun-react-jsNow you have your react project using Bun.
5. Now let’s try to print the contents of a file
https://gist.github.com/ikku47/409f6a2db25abee6de885e14e09e7d31#file-bun-cat-jsIf you need more examples, have a look at this one.
Is it as fast as it claims to be? Let’s look at some benchmark results.
You can have more bench-marking and detailed reports on this blog by
Jose Granja on this medium article.
Not only is Bun fast, but it is also blazing fast. It feels like you can do anything in under a second. Bun.js focuses on performance, developer experience, and compatibility with the JavaScript ecosystem
Will Bun replace Node Js and Deno Js? It’s too early to say as it is still in beta. Bun JavaScript aims for compatibility, so it has a better chance than Deno. And, as we’ve seen, even at this early beta stage it can be a very efficient and fast tool.
You can follow for more updates on Bun on their Discord channel, and the main developers’ Twitter handle.
Author
Reviewed By
Editor
We at CaratLane are solving some of the most intriguing challenges to make our mark in the relatively uncharted omnichannel jewellery industry. If you are interested in tackling such obstacles, feel free to drop your updated resume/CV to careers@caratlane.com!
Leave a Reply