Skip to content

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

GitHub Repository

Community Resources

Official Community

Social Media

Tutorials and Articles

Getting Started Tutorials

  1. Bun Official Tutorial

    • Quick start
    • Basic concepts
    • Common use cases
  2. Video Tutorials

    • Search "Bun.js tutorial" on YouTube
    • Search "Bun 教程" on Bilibili (Chinese platform)

Advanced Articles

  1. Performance Optimization

    • Bun performance benchmarks
    • Production best practices
  2. Framework Integration

    • Bun + React
    • Bun + Vue
    • Bun + Next.js

Frameworks and Libraries

Bun-specific Frameworks

FrameworkDescriptionLink
ElysiaHigh-performance Web Frameworkelysiajs.com
HonoLightweight Web Frameworkhono.dev

Elysia Example

typescript
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

ToolPurpose
VS Code ExtensionBun syntax support and debugging
Bun Type Definitions@types/bun

VS Code Configuration

json
// .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

  1. Bun Examples

    • Official example repository
    • Various usage scenarios
  2. Awesome Bun

Practical Projects

Open source projects for learning and reference:

bash
# Clone example projects
git clone https://github.com/oven-sh/bun-examples
cd bun-examples

# Run examples
bun run example-name

Common Commands Quick Reference

Project Management

bash
# 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 update

Running Scripts

bash
# 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-name

Building and Bundling

bash
# 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 --sourcemap

Testing

bash
# Run tests
bun test

# Watch mode
bun test --watch

# Coverage
bun test --coverage

API Quick Reference

Bun Global Object

typescript
// 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

typescript
// 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)

  1. Read official getting started documentation
  2. Install and create your first project
  3. Learn basic commands (run, install, add)
  4. Try creating a simple HTTP server
  5. Understand differences from Node.js

Intermediate Developers (2-4 weeks)

  1. Deep dive into Bun API
  2. Master bundling and testing features
  3. Learn Elysia or other frameworks
  4. Understand performance optimization tips
  5. Practice with a complete project

Advanced Developers (ongoing)

  1. Study Bun source code
  2. Contribute to community
  3. Develop Bun plugins
  4. Explore FFI and advanced features
  5. 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.

Content is for learning and research only.