DEV Community

Cover image for I Built a Server Library for Bun (and got carried away)
Wess Cope
Wess Cope

Posted on

I Built a Server Library for Bun (and got carried away)

I wanted a server library built for Bun, not ported from Node.js. Couldn't find one. So I built it.

What is Verb?

Express-style API, zero dependencies:

import { createServer } from "verb"

const app = createServer()

app.get("/", (req, res) => {
  res.json({ message: "Hello from Verb!" })
})

app.listen(3000)
Enter fullscreen mode Exit fullscreen mode

One API, Many Protocols

HTTP, WebSocket, gRPC, TCP, UDP - same API:

import { server } from "verb"

const http = server.http()
http.get("/api/users", getUsers)

const ws = server.websocket()
ws.on("connection", handleConnection)

const grpc = server.grpc()
grpc.addService(userService, userHandlers)
Enter fullscreen mode Exit fullscreen mode

Zero Dependencies

Verb uses only Bun's built-in APIs. No external packages. Clean node_modules, simple supply chain.

The Ecosystem

Then I needed more stuff. So I built that too:

Hull - Ecto-inspired database toolkit:

const User = schema("users")
  .uuid("id", { primaryKey: true })
  .string("email", 255)
  .timestamps()

const users = await all(repo, whereEq(from(User), "active", true))
Enter fullscreen mode Exit fullscreen mode

Allow - Authentication (JWT, OAuth, local):

const allow = createAllow({
  secret: process.env.JWT_SECRET,
  strategies: [{ name: "local", type: "local", config: {} }]
})

app.get("/dashboard", requireAuth, dashboardHandler)
Enter fullscreen mode Exit fullscreen mode

Hoist - Self-hosted deployment:

hoist deploy
Enter fullscreen mode Exit fullscreen mode

Shelves - S3-compatible object storage you can self-host.

Getting Started

bunx @verb-js/create-verb my-app
cd my-app
bun run dev
Enter fullscreen mode Exit fullscreen mode

Performance

~93k req/sec, ~0.5ms latency. Hybrid router with O(1) static lookups.

Links

MIT licensed. Questions? Drop them in the comments.

Top comments (2)

Collapse
 
toddpress profile image
Todd Pressley

Neat work… imma hit up your GitHub to look into shelves a bit more

Collapse
 
wess profile image
Wess Cope

Awesome, looking forward to feedback