Bun Runtime
Host Bun apps on Witchly.host — the fast all-in-one JavaScript runtime, bundler, and package manager. TypeScript and JSX out of the box.
languages (12 articles)
On This Page
Bun Runtime
Bun is a fast JavaScript runtime, package manager, transpiler, and bundler — all in one binary. It runs TypeScript and JSX without a build step, ships with built-in testing and HTTP servers, and is 2–4× faster than Node.js for most workloads. Witchly runs the latest Bun release.
Why Bun vs Node.js?
- Faster startup — cold start in ~10ms.
- TypeScript native — no
tscstep, just run.tsfiles directly. - Built-in APIs —
Bun.file(),Bun.serve(),Bun.spawn()— no need forfs,http, or child process modules. - Drop-in Node.js compat — most npm packages work unchanged.
Quick deploy
- dash.witchly.host → Deploy → Languages → Bun.
- On the Startup tab:
Git Repository Address— your repo URLMain file— entrypoint (defaultindex.js, but tryindex.ts!)
- Start.
Startup flow
if [[ -d .git ]] && [[ {{AUTO_UPDATE}} == "1" ]]; then git pull; fi
if [[ ! -z ${BUN_PACKAGES} ]]; then bun install ${BUN_PACKAGES}; fi
if [[ ! -z ${RMBUN_PACKAGES} ]]; then bun remove ${RMBUN_PACKAGES}; fi
bun run ${MAIN_FILE}
Variables reference
| Variable | Purpose |
|---|---|
GIT_ADDRESS | Git repo URL |
BRANCH | Git branch |
USER_UPLOAD | 1 to skip clone |
AUTO_UPDATE | 1 to git pull on start |
MAIN_FILE | Entrypoint (supports .js, .ts, .tsx) |
BUN_PACKAGES | Extra packages installed via bun install |
RMBUN_PACKAGES | Packages to remove via bun remove |
USERNAME, ACCESS_TOKEN | Private repo credentials |
TypeScript, zero config
Just commit a .ts file and set MAIN_FILE = index.ts:
// index.ts
const server = Bun.serve({
port: Number(process.env.SERVER_PORT),
fetch(req) {
const url = new URL(req.url)
if (url.pathname === "/") return new Response("Hello from Bun!")
return new Response("Not found", { status: 404 })
},
})
console.log(`Listening on :${server.port}`)
Package management
bun install is 20–30× faster than npm install. Ship a bun.lockb (binary) in your repo and the egg’s bun install step will resolve deps instantly.
For ad-hoc additions on a running server, use the Console:
bun add zod
Or set BUN_PACKAGES = zod on the Startup tab to install on each boot.
Frameworks
Bun works with:
- Hono — ultralight HTTP framework designed for Bun
- Elysia — Bun-native framework with end-to-end types
- Express / Fastify — via Node.js compatibility
- Discord.js, discord-api-types — Discord bots run great on Bun
Discord.js bot example
// index.ts
import { Client, GatewayIntentBits } from "discord.js"
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
})
client.on("ready", () => console.log(`Logged in as ${client.user?.tag}`))
client.on("messageCreate", (msg) => {
if (msg.content === "!ping") msg.reply("pong")
})
client.login(process.env.DISCORD_TOKEN)
Troubleshooting
- Package won’t install — some Node.js packages with native C addons need rebuilding; try
bun install --force. - “Cannot find module” — commit your
bun.lockbalong withpackage.json. - Crashes on start — check you’re using
Number(process.env.SERVER_PORT)— Bun is strict about types.
Next steps
- Node.js runtime for comparison
- Redis as a lightning-fast cache