Elysia on Vercel
Elysia is an ergonomic web framework for building backend servers with Bun. Designed with simplicity and type-safety in mind, Elysia offers a familiar API with extensive support for TypeScript and is optimized for Bun.
You can deploy an Elysia app to Vercel with zero configuration.
Elysia applications on Vercel benefit from:
- Fluid compute: Active CPU billing, automatic cold start prevention, optimized concurrency, background processing, and more
- Preview deployments: Test your changes on a copy of your production infrastructure
- Instant Rollback: Recover from unintended changes or bugs in milliseconds
- Vercel Firewall: Protect your applications from a wide range of threats with a multi-layered security system
- Secure Compute: Create private links between your Vercel-hosted backend and other clouds
Get started by initializing a new Elysia project using Vercel CLI init command:
vc init elysiaThis will clone the Elysia example repository in a directory called elysia.
To deploy, connect your Git repository or use Vercel CLI:
vc deployTo run an Elysia application on Vercel, create a file that imports the elysia package at any one of the following locations:
app.{js,cjs,mjs,ts,cts,mts}index.{js,cjs,mjs,ts,cts,mts}server.{js,cjs,mjs,ts,cts,mts}src/app.{js,cjs,mjs,ts,cts,mts}src/index.{js,cjs,mjs,ts,cts,mts}src/server.{js,mjs,cjs,ts,cts,mts}
The file must also export the application as a default export of the module or use a port listener.
For example, use the following code that exports your Elysia app:
// For Node.js, ensure "type": "module" in package.json
// (Not required for Bun)
import { Elysia } from 'elysia';
const app = new Elysia().get('/', () => ({
message: 'Hello from Elysia on Vercel!',
}));
// Export the Elysia app
export default app;Running your application using app.listen is currently not supported. For now, prefer export default app.
To run your Elysia application locally, you can use Vercel CLI:
vc devEnsure type is set to module in your package.json file:
{
"name": "elysia-app",
"type": "module",
}To use the Bun runtime on Vercel, configure the runtime in vercel.json:
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"bunVersion": "1.x"
}For more information, visit the Bun runtime on Vercel documentation.
In Elysia, you can use plugins and lifecycle hooks to run code before and after request handling. This is commonly used for logging, auth, or request processing:
import { Elysia } from 'elysia';
const app = new Elysia()
.onBeforeHandle(({ request }) => {
// Runs before route handler
console.log('Request:', request.url);
})
.onAfterHandle(({ response }) => {
// Runs after route handler
console.log('Response:', response.status);
})
.get('/', () => 'Hello Elysia!');
export default app;In Vercel, Routing Middleware executes before a request is processed by your application. Use it for rewrites, redirects, headers, or personalization, and combine it with Elysia's own lifecycle hooks as needed.
When you deploy an Elysia app to Vercel, your server endpoints automatically run as Vercel Functions and use Fluid compute by default.
Was this helpful?