Bun is an all-in-one toolkit for JavaScript and TypeScript apps. It ships as a single executable called bun.
src: https://bun.sh/docs
So, basically, it's a JS runtime, but at the same time, it can bundle files, install packages, run tests.
People currently focus a lot on the "fast" aspect of Bun, but i just want to take a look on it's features and the experiences of setting up as well as using it for the first time.
There are a lot going on with Bun but i find below features draw my attention the most. They're all built-in instead of having to install like on Nodejs.
Regarding typescript, there's actually nothing we have to do, after the setup, bun-types was installed and you can start using typescripts as normal.
We no longer need to install dotenv or dotevn-expand, you can just call process.env.API_TOKEN
or Bun.env.API_TOKEN
, for example.
import { hello } from "./hello"
is ok to use with Bun.
CommonJS modules (require()/module.exports) is acceptable, but it's not recommended in order to keep the consistency if you start a new project.
Forget nodemon, with Bun, you just need to add script to watch the changes like below
Now everytime you make chages, your app restart. You can also watch the test, so that tests will run when you make changes on test case.
Beside --watch
, you can also use --hot
, which does not hard-restart the entire process. Instead, it detects code changes and updates its internal module cache with the new code.
Yes, Bun support Websocket by default. Below is a basic websocket server in Bun.
Beside sending message, you can also:
Bun natively implements a high-performance SQLite3 driver with below supported features:
Bun ships with a fast, built-in, Jest-compatible test runner with below supported features:
--watch
--preload
Please be noted that mock() function is not implemented yet, but you can use alternative way to achieve the same thing.
Above are just those that draw my most attention but there are more and you can check out the details on official website. There are also guides in case you want to try Bun with frameworks or the things you care about.
Bun is still young and they still have plans for it, but the fact that it removes lots of installations everytime I start a be project in javascript, is nice.