Bun Quick Start
This chapter will guide you through creating your first Bun project and understanding the basic structure and workflow of Bun projects.
Creating a New Project
Using bun init
The fastest way to create a new project:
Interactive prompts will ask:
Generated File Structure
Viewing package.json
Your First Program
Hello World
Edit index.ts:
Run the program:
Output:
Using JavaScript
Bun also supports pure JavaScript:
Installing Dependencies
Adding Packages
Using Dependencies
Run:
Project Scripts
Configuring Scripts
Add scripts in package.json:
Running Scripts
Creating an HTTP Server
Bun has a built-in high-performance HTTP server:
Run the server:
Visit http://localhost:3000 to see the result.
Creating CLI Tools
Simple CLI
Run:
Interactive CLI
Using Environment Variables
Creating .env File
Reading Environment Variables
Project Templates
React Project
Next.js Project
Elysia Project (Bun-specific Framework)
Creating from Template
Complete Project Example
Create a simple todo API:
Test the API:
Summary
This chapter introduced:
- ✅ Using
bun initto create projects - ✅ Running TypeScript/JavaScript files
- ✅ Installing and using dependencies
- ✅ Configuring and running project scripts
- ✅ Creating HTTP servers
- ✅ Using environment variables
- ✅ Using project templates
Next Steps
Continue reading Running Scripts to learn more about Bun's script execution mechanism.