A Quick Look at Bun 1.0 – The Node.js Alternative
A wise man once told me, “When you start eating Bun, Node.js will feel bland”.
But how and why is it faster than Node.js? A lot of questions come to mind.
Here are some things we can do with Bun.
Run your Code Faster with Bun
Now, we don’t need tools like
yarn because Bun is 17 times faster. Take a look at the data below:
Bun takes only 0.36 seconds to compile your code, whereas it takes about 6.44 seconds in the case of pnpm, 10.58 seconds with npm, and 12.08 seconds with yarn.
Bun Supports Hot Reloading
You can replace
npm run with
bun run to save over 150ms milliseconds every time you run a command.
Here is the full chart:
From the chart above, using
npm takes about 176ms to run,
yarn takes about 131ms. In the case of
pnpm, it takes 259ms. However, it takes about 7ms in the case of
Bun. That’s fast, isn’t it?
- Parcel, .parcelrc
- Rollup, rollup.config.js
Bun now supports Next.js, Remix, Nuxt, Astro, SvelteKit, Nest, SolidStart, and Vite.
Bun has both ESM and CommonJS Compatibility
Another great feature about Bun is that we can use ES Modules and CommonJs together in the same file, which was not possible in Node.js.
You can use
require() in the same file:
Apart from that, Bun has built-in support for the Web standard APIs that are available in browsers, such as
fetch, along with extra Bun APIs like
Bun.file() to lazy read a file and
Bun.Write() to write a file to the local file system which is a lot simpler than Node.js.
The code above will read the contents of a
package.json file and transfer its content to a new variable called
In the code above,
Bun.write() will write the string
"<html/>", or copy the contents of
home.html file into the
index.html file. If we have to fetch data, it will fetch the results from an external web API and write the contents to a
Why is Bun so fast?
If you want to get things done faster, you should consider replacing Node.js with Bun.
How to Get Started With Bun
You cam install Bun on MacOS and Linux systems using npm:
Now you are all set. To install a npm package, do this:
To start a Next.js app, do this:
All you need to do is replace
This article shows how you can use Bun as a Node.js alternative and speed up your development time.
You can also check out my video on The Node.js killer is here — Bun 1.0 First Look.
Thanks for reading!