Overriding the default configuration
Configure your Motia application with motia.config.ts - Express customization, Redis, security, file uploads, and more.
The motia.config.ts file is the central configuration for your Motia application. Here you can customize Express, configure Redis, add security middleware, handle file uploads, set up stream authentication, and more.
Quick Start
Create a motia.config.ts file in your project root:
That's it. Motia works out of the box with sensible defaults.
Critical Requirement: ES Modules
Your package.json must have "type": "module"
Motia uses ES modules internally. Without this setting, you'll get import/export errors at runtime.
Configuration Options
| Option | Type | Description |
|---|---|---|
app | (app: Express) => void | Customize the Express instance |
plugins | MotiaPluginBuilder[] | Add Workbench plugins |
adapters | AdapterConfig | Custom adapters for scaling |
streamAuth | StreamAuthConfig | Secure real-time streams |
redis | RedisConfig | Redis connection settings |
Express Customization
Use the app callback to add middleware, routes, or any Express configuration. This runs before Motia's built-in middleware.
Health Check Endpoint
Add a simple health check for load balancers and monitoring:
Security with Helmet
Helmet adds security headers to protect against common vulnerabilities.
Install:
Configure:
For more control:
CORS Configuration
Built-in CORS: Motia automatically adds permissive CORS headers to all responses. You only need custom CORS if you want to restrict origins.
Default Behavior
Motia automatically sets these headers on all responses:
Custom CORS
To restrict origins or customize CORS behavior:
Install:
Configure:
Environment-based origins:
Middleware
Add any Express middleware in the app callback. Middleware runs in the order you define it.
Middleware Order: The app callback runs before Motia's body parsers. If you need to access req.body, your middleware will need to parse it or wait for Motia's parsers.
File Uploads
Limitation: Motia Step handlers receive a simplified ApiRequest object, not the raw Express request. This means traditional Multer middleware cannot pass file data directly to your handlers.
For file uploads, use one of these approaches:
Option 1: Base64 Encoding (Small Files)
For small files (under a few MB), encode as Base64 in the request body:
Option 2: Direct Express Route (Large Files)
For large files, bypass Steps and create a direct Express route in your config:
Direct Express routes don't have access to Motia's emit, state, or streams. If you need these features after upload, emit an event from the Express route to trigger a Step.
Redis Configuration
Motia uses Redis for internal coordination. By default, it includes an embedded in-memory Redis server - no installation required.
Default: In-Memory Redis
External Redis
For production or when you have your own Redis instance:
Skip Embedded Redis
When creating a new project, skip the embedded Redis binary:
This creates a project configured for external Redis from the start.
Redis Options
| Option | Type | Description |
|---|---|---|
useMemoryServer | boolean | Use embedded Redis (default: true) |
host | string | Redis host |
port | number | Redis port |
password | string | Redis password |
username | string | Redis username (Redis 6.0+) |
db | number | Database number (default: 0) |
Stream Authentication
Secure your real-time streams by authenticating WebSocket connections.
Basic Setup
Using Auth in Streams
Once configured, use the auth context in your stream's canAccess callback:
Built-in Features
Motia automatically configures several features you should know about:
Body Parsers
Motia automatically parses JSON, URL-encoded, and text request bodies with a 1GB limit:
Raw Body Access
The raw request body is available as req.rawBody. Useful for webhook signature verification:
Plugins
Add Workbench UI components and custom steps with plugins.
Using Built-in Plugins
Creating Local Plugins
What's Next?
📦 Adapters
Configure distributed adapters for scaling
🔌 Plugins
Extend Motia with custom plugins
📡 Streams
Build real-time features