- Native Bun HTTP server using
Bun.serve(). - No build step required - TypeScript runs directly.
- Built-in TypeScript support - No transpilation needed.
- Fast startup - Instant server boot.
- Minimal dependencies - Only
@types/bunfor development. - Health check endpoint included.
Configuration
With Bun, no build step is required. Bun runs TypeScript directly, so you don’t need a separate build command. Sevalla will automatically:- Run
bun installto install dependencies. - Execute
bun run startto start your server.
package.json file for deploying Bun on Sevalla:
Containerization
Dockerfile
The build for Dockerfiles is fully customizable. The Dockerfile below follows best practices for building and running a Bun application in Sevalla. It:- Uses official
oven/bunimage for optimal performance. - Installs dependencies with
--frozen-lockfilefor deterministic builds. - Exposes port 3000 by default.
- Runs the application using
bun run start. - Excludes unnecessary files via
.dockerignore(node_modules, .git, .env, etc.).
Nixpacks
Nixpacks detects Bun projects automatically by locating apackage.json and bun.lock file in your application. It then installs the Bun runtime, runs bun install to fetch dependencies, and uses the start script from your package.json file to configure how your application is launched.
When using Nixpacks in Sevalla for your Bun application:
- Ensure your
package.jsonhas a validstartscript. - Nixpacks respects your
bun.lockfile for deterministic builds. - All standard Sevalla features (CDN, scaling, processes) work with Nixpacks.
- Nixpacks uses Node 18 by default, but Bun requires Node 22. To ensure compatibility, set the
NIXPACKS_NODE_VERSIONenvironment variable to22.
CDN
Sevalla provides a premium, Cloudflare-powered CDN for Application Hosting at no additional cost. To get the most out of Sevalla’s CDN when deploying your Bun application, we recommend the following best practices:- Enable the CDN for all production applications to ensure global, low-latency delivery.
- Set appropriate
Cache-Controlheaders on API routes to ensure proper caching behavior. - Purge CDN cache after critical deployments to ensure users receive updated content.
- Use versioned URLs for static assets (e.g.,
/static/app.v123.js).
Optimizing Bun server for CDN
Static files with cache headers
Edge caching
Edge caching stores your Sevalla site cache on Cloudflare’s 260+ global data centers, delivering responses from the location nearest to each visitor for faster performance. To maximize the benefits of Sevalla’s Edge Caching for your Bun application, we recommend the following best practices:- Set appropriate
Cache-Controlheaders in loaders to control caching behavior. - Combine edge caching with the CDN for a complete caching strategy.
Optimizing Bun for edge caching
Cache-Control
With Sevalla’s Cloudflare integration, Cache-Control headers are respected at the edge, giving you precise control over how content is cached and served globally. The following are some common directives you can use in your Bun application:
public, s-maxage=3600- Caches the response on the CDN for 1 hour, improving performance for frequently accessed content.public, max-age=31536000, immutable- Ideal for versioned static assets, allowing them to be cached for up to 1 year with no revalidation.private- Prevents CDN caching and ensures the response is only cached by the end user’s browser, for personalized or sensitive data.
Sevalla does not yet support the
stale-while-revalidate Cache-Control directive. To prevent unexpected caching behavior, we recommend not using this directive in your API or asset caching settings.Health checks
Ensure your application remains available during deployments by implementing health checks:- Always implement health checks for production applications.
- Keep checks lightweight; responses should complete in under 1 second.
- Verify critical dependencies (e.g., databases, Redis) as part of the checks.
- Return 200 for degraded states to allow deployments to continue smoothly.
- Return 503 only for critical failures that require pod restarts.
Basic healthcheck
Graceful shutdown
Bun supports graceful shutdown by default. For custom cleanup logic, useSIGTERM and SIGINT , for example:
S3
Bun includes a built-in s3 package that integrates seamlessly with Sevalla’s object storage. You can also integrate your Bun application with AWS S3 for object storage, file uploads, and static assets.Set up AWS S3
- Install AWS SDK dependency:
- Set S3 environment variables:
AWS S3 Usage
The S3 client is initialized insrc/s3.ts: