docs/src/content/en/guides/deployment/netlify.mdx
import Steps from "@site/src/components/Steps"; import StepItem from "@site/src/components/StepItem";
Use @mastra/deployer-netlify to deploy your Mastra server as serverless functions on Netlify. The deployer bundles your code and generates a .netlify directory conforming to Netlify's frameworks API, ready to deploy.
:::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. :::
You'll need a Mastra application and a Netlify account.
:::warning Netlify Functions use 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. :::
Add the @mastra/deployer-netlify package to your project:
npm install @mastra/deployer-netlify@latest
Import NetlifyDeployer and set it as the deployer in your Mastra configuration:
import { Mastra } from '@mastra/core'
// highlight-next-line
import { NetlifyDeployer } from '@mastra/deployer-netlify'
export const mastra = new Mastra({
// highlight-next-line
deployer: new NetlifyDeployer(),
})
Create a netlify.toml file with the following contents in your project root:
[build]
command = "mastra build"
After setting up your project, push it to your remote Git provider of choice (e.g. GitHub).
<Steps> <StepItem> Connect your repository to Netlify. During the setup process, Netlify will detect your `netlify.toml` file and set the build command to `mastra build`.:::note
Remember to set your environment variables needed to run your application (e.g. your [model provider](/models/providers) API key).
:::
Since the [Mastra server](/docs/server/mastra-server) prefixes every API endpoint with `/api`, you have to add it to your URLs when making requests.
:::info
Netlify functions are typically deployed at `https://<random-slug>.netlify.app/.netlify/functions/api`. The `NetlifyDeployer` redirects any request from `/*` to `/.netlify/functions/api/:splat`, so you don't need to include the `.netlify/functions` prefix in your URLs.
:::
:::warning
Set up [authentication](/docs/server/auth) before exposing your endpoints publicly.
:::