Skip to main content

Command Palette

Search for a command to run...

Bun: A brand-new, lightning-quick JavaScript runtime

Updated
โ€ข4 min read
Bun: A brand-new, lightning-quick JavaScript runtime
D

๐Ÿ‘จโ€๐Ÿ’ป Creative Software Engineer with 5 years of experience in domains including CI/CD, Networking, Cloud computing, Development, Virtualization, and Linux administration. Passionate about developing forward-thinking solutions to tomorrow's productivity problems. Resourceful and adaptable approach to challenges.

๐Ÿคนโ€โ™€๏ธ Skill stack:

โ€ข Cloud โ˜๏ธ : Azure, GCP โ€ข Databases ๐Ÿ—ƒ๏ธ : MySQL, PostgreSQL, Elasticsearch โ€ข Language ๐Ÿ : Python, JavaScript โ€ข Configuration management, deployment & IaC ๐Ÿ›ก๏ธ : Ansible, Terraform โ€ข Container and orchestration ๐Ÿณ : Docker, Kubernetes โ€ข Version Control ๐Ÿ—‚๏ธ : Git, GitHub โ€ข CI/CD ๐Ÿ”„ : Jenkins, GitHub actions, ArgoCD โ€ข Continuous Monitoring ๐Ÿ“Š : Grafana, ELK, Prometheus

๐Ÿ“š Currently learning: Web development, MLOPS

Bun logo

What is Bun? ๐Ÿค”

Bun is built on Zig and has the ability to transpile, set up, and run TypeScript and JavaScript projects. It is a full utility since it also functions as a package manager. Thatโ€™s why itโ€™s referred to as all-in-bun. This has been made possible via the usage of Zig, a dated programming language that was initially created for video games.

Notably, a bun produces another bun.lockb file, which is not comparable to a standard typical yarn.lock or package-lock.json file. The lock file that goes along with it is produced in binary. Exactly why? due to performance-related factors. This can make it difficult to track changes in common PRs.

Performance ๐Ÿƒโ€โ™‚๏ธ

People now refer to it as blazingly fast instead of just fast.

What could be better than a detailed examination of some of its benchmarks in comparison to NodeJs and Deno:

Comparison of Reactโ€™s server-side rendering :

SSR render comparison

In SSR of React, Bun is unquestionably more than 3 times faster ๐Ÿš€ in handling http requests.

Comparison in terms of Hashing :

Hashing render comparison

Bun has a staggering 6.3 times higher average ๐Ÿ˜ฎ query throughput than deno and nodeJs, respectively.

Support โ›ท๏ธ

Numerous Node.js and Web APIs, such as fs, path, Buffer, and others, are natively supported by Bun. This means that many npm packages already in use will be run by bun.

Bun Node Deno meme

Through improved, more user-friendly tooling, Bun wants to run the majority of JavaScript outside of browsers, increasing infrastructure complexity and speed.

  • TypeScript with JSX? It will work. (even .tsconfig support).

  • Bun loads.env files for you automatically.

  • Node modules? No issue.

  • There are built-in web APIs like fetch and WebSocket

  • Run a test? We possess it. Itโ€™s also quick.

  • Package manager? It soars.

Getting started ๐ŸŽฌ

Run this install script in your terminal to install Bun. From GitHub, Bun is downloaded.

curl https://bun.sh/install | bash

Bun install

Create a react app ๐Ÿ”จ

Run the command below to create a react app right away.

bun create react bun-app

react app bun

It will create a new directory with the name of your app. To start the app run the following command

cd your-app-name  
bun dev

bun dir

bun dev

Build production bundle for react app ๐Ÿ—๏ธ

React-scripts is not included by default with Bun, therefore you must first install it.

bun a react-scripts -d

It is set up in this place as a dev dependency.
Run the subsequent command to create the production bundle after that.

bun react-scripts build

bun react app

The production bundle will be created when you issue the aforementioned command, and it will be saved in the build directory.

Adding scripts to your package.json ๐Ÿ“œ

The scripts listed below can be included in our package.json file.

{  
  "scripts": {  
    "start": "bun dev",  
    "build": "react-scripts build"  
  }  
}

To launch the app, issue the following command.

bun start

And to create the production bundle, we may issue the following command.

bun run build

App โœจ

Bonus ๐Ÿ’ฐ

Bun builds react apps by default with javascript, however typescript can be used by simply changing the file extension from .jsx to .tsx.

Conclusion ๐Ÿ’ญ

Itโ€™s admirable that Bun.js has lofty goals for the future. Although it is currently too early to declare that it will replace Node.js, that is its intended replacement. Although Bun.js performs insanely, it tries to replace a lot of tools at once, which puts a heavy pressure on the Bun.js developers. Additionally, Zig is not a very well-known programming language, making it difficult, in my opinion, to find a contributor.

It will take years for Bun.js to mature and become a technology that we can use in production applications because it is still too new and immature. Even so, it has a lot of potential.

Github URL for the app ๐Ÿ’ป

GitHub - devangtomar/bun-app
*Contribute to devangtomar/bun-app development by creating an account on GitHub.*github.com

Connect with Me on Social Media

๐Ÿฆ Follow me on Twitter: devangtomar7
๐Ÿ”— Connect with me on LinkedIn: devangtomar
๐Ÿ“ท Check out my Instagram: be_ayushmann
โ“‚๏ธ Checkout my blogs on Medium: Devang Tomar
#๏ธโƒฃ Checkout my blogs on Hashnode: devangtomar
๐Ÿง‘โ€๐Ÿ’ป Checkout my blogs on Dev.to: devangtomar

18 views

More from this blog

D

Devang Tomar Senior Software engineer at SAP

57 posts

I write computer code for living ๐Ÿ’๐Ÿปโ€โ™‚๏ธ๐Ÿง‘๐Ÿปโ€๐Ÿ’ป Creative and Passionate Software Engineer โœจ Expertise : Cloud Computing ๐ŸŒฉ๏ธ, Infrastructure Automation ๐Ÿ—๏ธ, Python and shell scripting ๐Ÿ“œ, CI/CD tool โš’