Deploy Mastra to Digital Ocean
This guide covers Digital Ocean's App Platform and Droplets. Each of these offerings has its own set of strengths and is suited for different types of projects and developer expertise. Read Digital Ocean's comparison to understand the differences and choose the best option for your project.
This guide covers deploying the Mastra server. If you're using a server adapter or web framework, deploy the way you normally would for that framework.
Before you beginDirect link to Before you begin
You'll need a Mastra application and a Digital Ocean account.
The App Platform uses an ephemeral filesystem, so any storage you configure (including observability storage) must be hosted externally. If you're using LibSQLStore with a file URL, switch to a remotely hosted database.
App PlatformDirect link to App Platform
After setting up your project, push it to your remote Git provider of choice (e.g. GitHub).
Follow the official App Platform quickstart. It'll guide you through connecting your repository, selecting the branch to deploy from, and configuring the source directory if necessary.
Make sure that a "Node.js" build is detected. You'll need to configure a build command. Set it based on your package manager:
- npm
- pnpm
- Yarn
- Bun
npm run buildpnpm run buildyarn buildbun run buildAdd any required environment variables for your Mastra application. This includes API keys, database URLs, and other configuration values.
Your app will be built and deployed automatically. Digital Ocean will provide you with a URL to access your deployed application.
You can now call your Mastra endpoints over HTTP.
warningSet up authentication before exposing your endpoints publicly.
DropletsDirect link to Droplets
PrerequisitesDirect link to Prerequisites
- A Droplet running Ubuntu 24.04 LTS or later
- A domain name with an A record pointing to your droplet
- A reverse proxy configured (e.g., using nginx)
- SSL certificate configured (e.g., using Let's Encrypt)
- Node.js 22.13.0 or later installed on your droplet
DeployDirect link to Deploy
After setting up your project, push it to your remote Git provider of choice (e.g. GitHub). Connect to your Droplet and make sure git is installed.
Clone your repository:
- Public Repository
- Private Repository
git clone https://github.com/<your-username>/<your-repository>.gitgit clone https://<your-username>:<your-personal-access-token>@github.com/<your-username>/<your-repository>.gitNavigate to the repository directory:
cd "<your-repository>"Install the project dependencies:
- npm
- pnpm
- Yarn
- Bun
npm installpnpm installyarn installbun installSet the required environment variables for your Mastra application. Create a
.envfile in the root of your project:touch .envEdit the
.envfile and add your environment variables:.envOPENAI_API_KEY=your-api-keyBuild the project:
- npm
- pnpm
- Yarn
- Bun
npm run buildpnpm run buildyarn buildbun run buildThis will create a production build of Mastra's server in the
.mastra/outputdirectory.You can run the Mastra Server by running the
mastra startcommand:mastra startinfoYour Mastra application will run on port 4111 by default. Ensure your reverse proxy is configured to forward requests to this port.
You can now call your Mastra endpoints over HTTP.
warningSet up authentication before exposing your endpoints publicly.