Bun Learning Resources
This chapter summarizes various resources for learning Bun, including official documentation, community resources, open source projects, and advanced learning materials.
Official Resources
Official Website
- Bun Website: https://bun.sh
- Latest version download
- Official documentation
- API reference
Official Documentation
- Getting Started Guide: https://bun.sh/docs
- API Reference: https://bun.sh/docs/api
- CLI Commands: https://bun.sh/docs/cli
GitHub Repository
- Bun Source Code: https://github.com/oven-sh/bun
- Source code
- Issue tracking
- Release notes
- Contribution guidelines
Community Resources
Official Community
- Discord: https://bun.sh/discord
- Real-time discussions
- Problem solving
- Feature suggestions
Social Media
- Twitter/X: @bunikidevs
- Reddit: r/bunjs
Tutorials and Articles
Getting Started Tutorials
Bun Official Tutorial
- Quick start
- Basic concepts
- Common use cases
Video Tutorials
- Search "Bun.js tutorial" on YouTube
- Search "Bun 教程" on Bilibili (Chinese platform)
Advanced Articles
Performance Optimization
- Bun performance benchmarks
- Production best practices
Framework Integration
- Bun + React
- Bun + Vue
- Bun + Next.js
Frameworks and Libraries
Bun-specific Frameworks
| Framework | Description | Link |
|---|---|---|
| Elysia | High-performance Web Framework | elysiajs.com |
| Hono | Lightweight Web Framework | hono.dev |
Elysia Example
import { Elysia } from "elysia";
const app = new Elysia()
.get("/", () => "Hello Elysia!")
.get("/user/:id", ({ params }) => `User ${params.id}`)
.post("/login", ({ body }) => body)
.listen(3000);
console.log(`🦊 Elysia running at ${app.server?.hostname}:${app.server?.port}`);Compatible Frameworks
These frameworks can be used in Bun:
- Express - Traditional Node.js framework
- Fastify - High-performance framework
- Koa - Middleware framework
- NestJS - Enterprise-level framework
Tools and Plugins
Development Tools
| Tool | Purpose |
|---|---|
| VS Code Extension | Bun syntax support and debugging |
| Bun Type Definitions | @types/bun |
VS Code Configuration
// .vscode/settings.json
{
"typescript.tsdk": "node_modules/typescript/lib",
"editor.formatOnSave": true
}
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "bun",
"request": "launch",
"name": "Debug Bun",
"program": "${workspaceFolder}/src/index.ts"
}
]
}Open Source Projects
Learning Examples
Bun Examples
- Official example repository
- Various usage scenarios
Awesome Bun
- Community-curated resource list
- GitHub search "awesome-bun"
Practical Projects
Open source projects for learning and reference:
# Clone example projects
git clone https://github.com/oven-sh/bun-examples
cd bun-examples
# Run examples
bun run example-nameCommon Commands Quick Reference
Project Management
# Initialize project
bun init
# Install dependencies
bun install
# Add dependencies
bun add package-name
bun add -d package-name # Dev dependency
# Remove dependencies
bun remove package-name
# Update dependencies
bun updateRunning Scripts
# Run files
bun run file.ts
bun file.ts
# Watch mode
bun --watch file.ts
# Hot reload
bun --hot server.ts
# Run package.json scripts
bun run script-nameBuilding and Bundling
# Bundle
bun build ./src/index.ts --outdir ./dist
# Minify
bun build ./src/index.ts --outdir ./dist --minify
# Generate sourcemap
bun build ./src/index.ts --outdir ./dist --sourcemapTesting
# Run tests
bun test
# Watch mode
bun test --watch
# Coverage
bun test --coverageAPI Quick Reference
Bun Global Object
// Version information
Bun.version // "1.x.x"
Bun.revision // git commit
// Environment variables
Bun.env.NODE_ENV
// File operations
Bun.file(path)
Bun.write(path, data)
// Server
Bun.serve({ port, fetch })
// Shell
import { $ } from "bun";
await $`command`;
// Sleep
await Bun.sleep(1000);
// Password hashing
await Bun.password.hash("password");
await Bun.password.verify("password", hash);Common Imports
// Testing
import { test, expect, describe } from "bun:test";
// SQLite
import { Database } from "bun:sqlite";
// FFI
import { dlopen, FFIType } from "bun:ffi";
// Shell
import { $ } from "bun";Learning Path Suggestions
Beginners (1-2 weeks)
- Read official getting started documentation
- Install and create your first project
- Learn basic commands (run, install, add)
- Try creating a simple HTTP server
- Understand differences from Node.js
Intermediate Developers (2-4 weeks)
- Deep dive into Bun API
- Master bundling and testing features
- Learn Elysia or other frameworks
- Understand performance optimization tips
- Practice with a complete project
Advanced Developers (ongoing)
- Study Bun source code
- Contribute to community
- Develop Bun plugins
- Explore FFI and advanced features
- Share experiences and tutorials
Frequently Asked Questions
Q: Is Bun stable?
A: Bun 1.0 has been officially released and is suitable for production use. However, it is recommended to perform sufficient testing for critical business operations.
Q: How to report bugs?
A: Submit through GitHub Issues: https://github.com/oven-sh/bun/issues
Q: How to contribute?
A: Read the contribution guide: https://github.com/oven-sh/bun/blob/main/CONTRIBUTING.md
Q: Will Bun replace Node.js?
A: Bun is an alternative to Node.js, not a replacement. Both have their advantages, choose based on project requirements.
Continuous Learning
Stay Updated
- Subscribe to Bun blog
- Follow Twitter account
- Join Discord community
Practice Projects
- Migrate existing Node.js projects to Bun
- Build new projects with Bun
- Contribute to open source projects
Share Experience
- Write blog articles
- Record video tutorials
- Answer community questions
Summary
Bun is a powerful tool for modern JavaScript development. Through this tutorial, you have learned:
- ✅ Bun installation and basic usage
- ✅ Package management and module system
- ✅ HTTP server and WebSocket
- ✅ File operations and database
- ✅ Bundling and testing
- ✅ Advanced features and performance optimization
- ✅ Node.js compatibility and migration
Continue exploring Bun and enjoy faster, simpler JavaScript development!
Thanks for reading this tutorial! Feel free to provide feedback if you have any questions or suggestions.