Start with Bun
Have You Heard About Bun?
You know, the NodeJS framework that claims to be faster—but that’s not its only advantage.
It offers ease of use for unit testing, TypeScript support, and a module management system that simplifies integrations.
Official Bun Website
As you might have guessed, Bun is a development framework designed to “replace” NodeJS.
Installing Bun
To get started, let’s install Bun.
On Linux and macOS, use the following command:
curl -fsSL https://bun.sh/install | bash
Here’s the output of the command:
Added "~/.bun/bin" to $PATH in "~/.zshrc"
To get started, run:
exec /usr/bin/zsh bun --help
Now, let’s run the exec
command and test bun --help
.
Screenshot of bun --help
:
Everything looks good!
Next, I’ll create a new folder named “bun-trd”:
mkdir bun-trd
Then, navigate to the folder:
cd bun-trd
Creating the Project
Now, we’ll create the project using bun init
:
bun init
You can see that Bun has generated a folder with all the necessary files for our project.
(Unlike NodeJS, it doesn’t create an index.js
file by default.)
In the package.json
, I’ll add the scripts
section, which allows us to run the index.ts
file containing a console.log
:
"scripts": { "dev": "bun --hot index.ts" },
What is --hot
? Magic!
It’s an option that enables hot reload. No need to add nodemon
or other tools. :)
Finally, let’s run the project using bun run dev
:
And voilà, our project is running with hot reload, without any additional packages!
In the next part, we’ll see how to create an API with Bun.