Skip to main content
Mastra 1.0 is available 🎉 Read announcement

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.

info

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 begin
Direct 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 Platform
Direct link to App Platform

After setting up your project, push it to your remote Git provider of choice (e.g. GitHub).

  1. 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.

  2. 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 run build
  3. Add any required environment variables for your Mastra application. This includes API keys, database URLs, and other configuration values.

  4. Your app will be built and deployed automatically. Digital Ocean will provide you with a URL to access your deployed application.

  5. You can now call your Mastra endpoints over HTTP.

    warning

    Set up authentication before exposing your endpoints publicly.

Droplets
Direct link to Droplets

Prerequisites
Direct 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

Deploy
Direct 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.

  1. Clone your repository:

    git clone https://github.com/<your-username>/<your-repository>.git

    Navigate to the repository directory:

    cd "<your-repository>"
  2. Install the project dependencies:

    npm install
  3. Set the required environment variables for your Mastra application. Create a .env file in the root of your project:

    touch .env

    Edit the .env file and add your environment variables:

    .env
    OPENAI_API_KEY=your-api-key
  4. Build the project:

    npm run build

    This will create a production build of Mastra's server in the .mastra/output directory.

  5. You can run the Mastra Server by running the mastra start command:

    mastra start
    info

    Your Mastra application will run on port 4111 by default. Ensure your reverse proxy is configured to forward requests to this port.

  6. You can now call your Mastra endpoints over HTTP.

    warning

    Set up authentication before exposing your endpoints publicly.

On this page