new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Bun · all subjects

http & websocket apis

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Bun.serve() development mode features

When development is set to true in Bun.serve(), Bun includes the SourceMap header in the response so devtools can show original source code, disables minification, re-bundles assets on each request to a .html file, and enables hot module reloading unless hmr is set to false.

Bun.serve() advanced development configuration

The development option in Bun.serve() can be an object with the following properties: hmr (boolean) to enable or disable Hot Module Reloading, and console (boolean) to echo console logs from the browser to the terminal. Bun sends browser logs over the existing HMR WebSocket connection.

Development vs Production mode comparison in Bun.serve()

Source maps are enabled in development and disabled in production. Minification is disabled in development and enabled in production. Hot reloading is enabled in development and disabled in production. Asset bundling happens on each request in development and is cached in production. Console logging from browser to terminal is enabled in development and disabled in production. Error details are detailed in development and minimal in production.

Runtime bundling in production with development: false

Setting development: false in Bun.serve() enables in-memory caching of bundled assets. Bun bundles assets lazily on the first request to an .html file and caches the result in memory until the server restarts. This also enables Cache-Control and ETag headers and minifies JavaScript/TypeScript/TSX/JSX files.

API endpoint definition with HTTP method handlers

In Bun.serve() routes, define API endpoints as objects with HTTP method handlers (GET, POST, PUT, DELETE). Each method handler is an async function that receives the request object and returns a Response. Example: "/api/users": { async GET(req) { return Response.json(users); }, async POST(req) { const userData = await req.json(); return Response.json(user, { status: 201 }); } }

Dynamic routes with URL parameters in Bun.serve()

Use URL parameters in routes by including colons followed by parameter names, such as /api/users/:id or /api/users/:userId/posts/:postId. Wildcard routes are supported with /api/files/*. Access parameters via req.params, which is an object containing the parameter names and their values.

Request handling in Bun.serve() routes

Within route handlers, parse JSON body with await req.json(), access headers with req.headers.get("header-name"), access URL parameters with req.params, and access query parameters by creating new URL(req.url) and using url.searchParams.get("param-name").

Hot reloading requires Bun v1.2.3+

Hot reloading in Bun.serve() requires Bun version 1.2.3 or later.

Limitations of Bun fullstack dev server

Auto-discovery of API routes is not implemented. Server-side rendering (SSR) is not built-in. Planned features include file-based routing for API endpoints and built-in SSR support.

Give your agent this brain