Bun for Beginners
From empty folder to deployed app
Bun for Beginners
Get the rest of the book.
Part II — eight chapters that turn the routing groundwork from Part I into a real Notes app. Part III ships in a few weeks (production deploy + ops).
·Forms, validation, and application state
·SQLite persistence and user accounts
·Sessions, login, and authorization
·Edit, delete, search, and pagination
Part I — Orientation and First Success
CH 00
Free
Introduction
What this book is, the four pillars of Bun, and how the chapters fit together.
CH 01
Free
Initial Setup
Install Bun on macOS, Linux, or Windows. Get Git working. Confirm everything runs before we write a line of code.
CH 02
Free
Your First Bun Project
Scaffold a project with bun init, write a server with Bun.serve, return HTML, add routes, and run it all in watch mode.
CH 03
Free
Your First Real Bun Script
Build a command-line word counter. Read arguments and files with Bun's built-in APIs. Install your first package with bun add.
CH 04
Free
Test What You Built
Extract countWords into its own file, write tests with bun:test, and use watch mode to get instant feedback as you code.
Part II — Build the Notes App
CH 05
Free
Routes, Layout, and Static Files
Add multiple routes, share a layout across pages, and serve CSS and images from a public folder.
CH 06
Paid
Forms, Notes, and Application State
Accept form submissions, hold notes in memory, and render them back to the page. Lays the groundwork for SQLite in the next chapter.
CH 07
Paid
Persist Notes with SQLite
Replace the in-memory notes array with Bun's built-in SQLite driver. Notes survive restarts, tests get a clean database every run, and we get our first look at the data on disk.
CH 08
Paid
Validate Input and Handle Errors
Reject empty notes, show form errors with the user's input preserved, replace the bare 404 with a styled page, and add a top-level error handler so a broken request never leaks a stack trace.
CH 09
Paid
User Accounts
Add a sign-up form, hash passwords with Bun's built-in argon2id, and store users in the database.
CH 10
Paid
Sessions and Login
Turn a user account into a session — a login form, a sessions table, a cookie that survives a refresh, a logout route, and a currentUser() helper so the rest of the app can ask who is asking.
CH 11
Paid
Authorization and Ownership
Tie every note to a user, gate the routes that create and read them, and let the nav reflect who is logged in — so each account sees only its own notes.
CH 12
Paid
Edit and Delete
Split the test file along module lines, add edit and delete routes parameterized by note ID, gate them with the same auth-and-ownership pattern, and flash a confirmation message on the redirect home.
CH 13
Paid
Search and Pagination
Add a search box that filters notes by title or body, page the list so the home page stays readable past a couple of dozen notes, and keep ownership where the last two chapters left it.
Part III — Ship It
CH 14
Free
Prepare for Production
Move hardcoded values into environment variables, gate the cookie's secure flag on production, tidy the package.json scripts, and see what bun build can do with a single command.
CH 15
Planned
Deploy to Railway
Push to GitHub, deploy to Railway, get a live HTTPS URL.
CH 16
Planned
Persistent Data and Logs
Attach a Railway volume so SQLite survives redeploys; view logs.
CH 17
Planned
Deploy to Fly.io
Same app, different platform — fly launch, volumes, regions.
CH 18
Planned
Next Steps and Production Bun
Where to go from here, and a preview of Book 2.