Prerequisites
Install a recent stable Bun release. Check the runtime before starting:
bash
bun --versionCreate a project
bash
mkdir my-volt-api
cd my-volt-api
bun init -y
bun add volttsCreate index.ts
Copy the entire file below. The globalThis._importMeta_.main guard starts the server only when this file is run directly, so you can import the app in tests.
index.ts
import { Volt } from 'voltts';
const app = new Volt({ port: 3000 });
app.get('/hello', () => ({ message: 'Hello Volt' }));
if (globalThis._importMeta_.main) app.listen(3000);
export default app;Run and verify
bash
bun run index.ts
# In another terminal:
curl -i http://localhost:3000/helloExpect HTTP 200 and {"message":"Hello Volt"}. For automatic reload while editing, run bun --watch index.ts.
Continue learning
Follow Build a Tasks API. If startup fails, see Troubleshooting.