Digital Ocean
Deploy your Mastra applications to Digital Ocean's App Platform and Droplets.
This guide assumes your Mastra application has been created using the default
npx create-mastra@latest command.
For more information on how to create a new Mastra application,
refer to our getting started guide
- App Platform
- Droplets
App Platform
Prerequisites
- A Git repository containing your Mastra application. This can be a GitHub repository, GitLab repository, or any other compatible source provider.
- A Digital Ocean account
Deployment Steps
Create a new App
- Log in to your Digital Ocean dashboard.
- Navigate to the App Platform service.
- Select your source provider and create a new app.
Configure Deployment Source
- Connect and select your repository. You may also choose a container image or a sample app.
- Select the branch you want to deploy from.
- Configure the source directory if necessary. If your Mastra application uses the default directory structure, no action is required here.
- Head to the next step.
Configure Resource Settings and Environment Variables
- A Node.js build should be detected automatically.
- Configure Build Command: You need to add a custom build command for the app platform to build your Mastra project successfully. Set the build command based on your package manager:
- npm
- pnpm
- yarn
- bun
npm run buildpnpm buildyarn buildbun run build- Add any required environment variables for your Mastra application. This includes API keys, database URLs, and other configuration values.
- You may choose to configure the size of your resource here.
- Other things you may optionally configure include, the region of your resource, the unique app name, and what project the resource belongs to.
- Once you're done, you may create the app after reviewing your configuration and pricing estimates.
Deployment
- Your app will be built and deployed automatically.
- Digital Ocean will provide you with a URL to access your deployed application.
You can now access your deployed application at the URL provided by Digital Ocean.
The Digital Ocean App Platform uses an ephemeral file system,
meaning that any files written to the file system are short-lived and may be lost.
Avoid using a Mastra storage provider that uses the file system,
such as LibSQLStore with a file URL.
Droplets
Deploy your Mastra application to Digital Ocean's Droplets.
Prerequisites
- A Digital Ocean account
- A Droplet running Ubuntu 24+
- 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 18+ installed on your droplet
Deployment Steps
Clone your Mastra application
Connect to your Droplet and 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 dependencies
npm installSet up environment variables
Create a
.envfile and add your environment variables:touch .envEdit the
.envfile and add your environment variables:OPENAI_API_KEY=<your-openai-api-key>
# Add other required environment variablesBuild the application
npm run buildRun the application
node --import=./.mastra/output/instrumentation.mjs --env-file=".env" .mastra/output/index.mjsnoteYour Mastra application will run on port 4111 by default. Ensure your reverse proxy is configured to forward requests to this port.
Connect to your Mastra server
You can now connect to your Mastra server from your client application using a MastraClient from the @mastra/client-js package.
Refer to the MastraClient documentation for more information.
import { MastraClient } from "@mastra/client-js";
const mastraClient = new MastraClient({
baseUrl: "https://<your-domain-name>",
});