Deploy A Mastra Server
Mastra builds to a standard Node.js server, so you can deploy it to any platform that supports Node.js applications.
- Cloud VMs (AWS EC2, DigitalOcean Droplets, GCP Compute Engine)
- Container platforms (Docker, Kubernetes)
- Platform as a Service (Heroku, Railway)
- Self-hosted servers
See the Cloud Providers for more information.
Building
Build the application:
# Build from current directory
mastra build
# Or specify a directory
mastra build --dir ./my-project
The build process:
- Locates entry file (
src/mastra/index.ts
orsrc/mastra/index.js
) - Creates
.mastra
output directory - Bundles code using Rollup with tree shaking and source maps
- Generates Hono  HTTP server
See mastra build
for all options.
Running the Server
Start the HTTP server:
node .mastra/output/index.mjs
Enable Telemetry for build output
Load instrumentation for the build output like so:
node --import=./.mastra/output/instrumentation.mjs .mastra/output/index.mjs
Serverless Deployment
Mastra also supports serverless deployment on Cloudflare Workers, Vercel, and Netlify. See Serverless Platforms for more information.