Bun.js Setup Guide
0 119
Introduction to Bun.js Setup
Setting up Bun.js is incredibly straightforward compared to traditional JavaScript environments. Designed for speed and simplicity, Bun combines a runtime, bundler, package manager, and test runner in one binary. This guide will walk you through installing Bun.js and getting your development environment ready in just a few minutes.
System Requirements
Before installing Bun.js, make sure you have the following:
- Operating System: macOS, Linux, or Windows (WSL2 supported)
- Shell: bash, zsh, or similar terminal environment
- Basic understanding of JavaScript or TypeScript (optional but helpful)
Step 1: Install Bun.js
To install Bun.js, simply open your terminal and run the official install script:
curl -fsSL https://bun.sh/install | bash
This will download and install the Bun binary and update your shell profile (like .bashrc
or .zshrc
) automatically.
Step 2: Verify Installation
After installation, confirm that Bun was installed correctly by running:
bun --version
You should see the current version number of Bun displayed in your terminal.
Step 3: Initialize a New Project
Bun offers a convenient command to set up a new project structure. To create a new project, run:
bun init
You'll be prompted to enter a project name, description, and other basic configurations. Bun will then generate a project folder with a ready-to-use structure, including:
index.ts
– Entry pointbun.lockb
– Lock filepackage.json
– Metadata and dependencies
Step 4: Add Dependencies
Installing packages with Bun is faster than npm or yarn. For example, to add React:
bun add react react-dom
To remove a package:
bun remove package-name
Step 5: Run Your Project
You can run any file directly using the bun
command. For example, if your main file is index.ts
:
bun run index.ts
Bun will automatically handle TypeScript, JSX, and other modern syntax during execution.
Step 6: Using TypeScript with Bun
Bun has built-in TypeScript support, so no extra config is needed to run .ts
files. However, you can still add a tsconfig.json
file if your project requires specific compiler options:
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"strict": true
}
}
Step 7: Create a Basic Server
Here’s how you can set up a minimal HTTP server using Bun:
// index.ts
export default {
port: 3000,
fetch(request: Request): Response {
return new Response("Hello from Bun.js Setup Guide!");
}
};
Now run the server:
bun run index.ts
Visit http://localhost:3000
in your browser to see the response.
Conclusion
Bun.js makes it easy to go from zero to a running app in just a few commands. With its ultra-fast runtime, native TypeScript support, built-in tools, and simplified workflows, Bun saves time and reduces complexity for developers. Whether you're building full-stack apps or lightweight APIs, setting up Bun is a smooth experience worth trying.
Ready to move beyond setup? Check out advanced guides on using Bun with frameworks like React, building REST APIs, or deploying Bun-powered applications.
If you’re passionate about building a successful blogging website, check out this helpful guide at Coding Tag – How to Start a Successful Blog. It offers practical steps and expert tips to kickstart your blogging journey!
For dedicated UPSC exam preparation, we highly recommend visiting www.iasmania.com. It offers well-structured resources, current affairs, and subject-wise notes tailored specifically for aspirants. Start your journey today!

Share:
Comments
Waiting for your comments