Directus

Self-host Directus with Postgres and S3 storage

Run Directus from its npm package on a managed Node.js container, with Postgres for collections and users, files in an S3 bucket and Redis when you scale out. This guide goes from an empty folder to a production Directus on Modelence.

Last updated /Tested with Directus 12.7.0 on Node.js 26.13

To self-host Directus, install the directus package from npm, run directus bootstrap against a SQL database so it creates its tables and the first admin, and then directus start, with SECRET fixed and files pointed at an S3 bucket. On Modelence the project is a package.json and a modelence.config.json, and npx modelence@latest deploy installs Directus on the official Node.js 26 image and runs it as a managed container on AWS, in your choice of 17 regions, next to managed MongoDB, Postgres and Redis.

Directus also ships as a Docker image, and most guides start from that. The npm package runs the same server with no Dockerfile, and it makes the Directus version a line in package.json that npm ci installs exactly. We ran every command below with Directus 12.7.0 on Node.js 26, using SQLite for the local run. Your collections live in Postgres, so the project folder itself stays small: the package, its lockfile, the extensions you add and, once you want it, a schema snapshot.

Directus on Modelence at a glance

How it runs
npm start runs directus bootstrap, which installs or migrates the database, then directus start on the PORT Modelence sets
Node.js
Directus 12 needs Node.js 26 or newer, so the service uses the node-26-slim image
Database
Managed Postgres through the DB_ variables, with the first admin created from ADMIN_EMAIL and ADMIN_PASSWORD
Files
STORAGE_LOCATIONS=s3 sends uploads to S3, Cloudflare R2 or another S3-compatible bucket
Health check
GET /server/ping answers pong without a login, while /server/health needs an admin token
Scaling
Managed Redis holds the cache and rate limiter so several Directus containers share them
Regions
17 AWS regions, with Directus and its database in the same one

Before you start

  • Node.js 26 or newer and npm on your machine, for the local run
  • An S3 bucket and an access key that can read and write it, or a bucket on an S3-compatible service such as Cloudflare R2
  • The email address you want for the first Directus administrator
  • A Modelence account, which you can create for free. Managed Postgres needs a paid plan, from $20 a month with that amount included as usage
  • Optionally, Claude Code, Cursor or Codex, if you'd rather have your coding agent write the files and run the deploy

Create the project with the directus package

A Directus project needs no generator. Make a folder, install the package with an exact version, and create an extensions folder, which Directus scans at startup and complains about when it's missing:

mkdir my-directus && cd my-directus
npm init -y
npm install [email protected] --save-exact
mkdir extensions && touch extensions/.gitkeep

Then set package.json to the following. The start script is the whole server: directus bootstrap installs the schema on an empty database or runs pending migrations on an existing one, and exec hands the process over to directus start, so the stop signal on a deploy reaches Directus itself and it closes its database connections cleanly. In our test, without exec, stopping npm left Directus running on its own.

During the install, npm 11 lists packages such as argon2, sharp and sqlite3 whose install scripts it didn't run. They ship prebuilt binaries for Linux, so Directus loads them anyway, and nothing needs approving.

package.json
{
  "name": "my-directus",
  "private": true,
  "scripts": {
    "start": "directus bootstrap && exec directus start"
  },
  "dependencies": {
    "directus": "12.7.0"
  },
  "engines": {
    "node": ">=26"
  }
}

Run Directus locally

Put local settings in a .env file, which Directus reads from the project folder, and add .env and data/ to .gitignore. SQLite needs no server, so it's the quickest database for trying things locally:

bash
cat > .env <<'EOF'
DB_CLIENT=sqlite3
DB_FILENAME=./data/data.db
SECRET=local-only-secret-replace-me-with-32-chars
[email protected]
ADMIN_PASSWORD=change-me-locally
PORT=8055
EOF
mkdir -p data extensions
npm start

Model your data

Open http://localhost:8055/admin and log in with the admin address and password from .env. Collections and fields you create in the Data Model settings become real tables and columns, and Directus stores its own settings, roles, permissions and Flows in tables that start with directus_, all in the same database. That's why the project folder holds no schema files by default.

To move a data model from one Directus to another, take a schema snapshot. It writes every collection, field and relation to a YAML file you can commit, and schema apply brings another database in line with it:

npx directus schema snapshot ./snapshot.yaml

A snapshot covers the data model, not content, roles or Flows. Those stay in each environment's database, and production readiness shows how to apply a snapshot on deploy.

Add a database

  • MongoDBMONGODB_URI
  • PostgresDATABASE_URL
  • RedisREDIS_URL

Directus works with PostgreSQL, MySQL, MariaDB, MS SQL, OracleDB, CockroachDB and SQLite, and Postgres is a common choice in production. The config below creates a managed Postgres called directus-db in the same region as Directus. Leave it empty: on the first start, directus bootstrap creates the system tables, the Administrator role and a user with ADMIN_EMAIL and ADMIN_PASSWORD, and on every later start it finds an installed database and only runs migrations.

Directus takes the connection as separate DB_* variables, so each one is tied to an output of directus-db. Variables with a double underscore become nested options, which is how DB_SSL__REJECT_UNAUTHORIZED=false turns on TLS for the connection without checking the server certificate against a CA, as sslmode=require does.

Managed Redis isn't required for one container. It becomes useful when you run several, and the checklist covers adding it.

modelence.config.json
{
  "resources": {
    // "directus": the service from the deploy step
    "directus-db": { "type": "postgres", "plan": "postgres-1gb" }
  },
  "env": {
    "DB_CLIENT": { "value": "pg" },
    "DB_HOST": { "type": "resource", "resource": "directus-db", "output": "host" },
    "DB_PORT": { "type": "resource", "resource": "directus-db", "output": "port" },
    "DB_DATABASE": { "type": "resource", "resource": "directus-db", "output": "database" },
    "DB_USER": { "type": "resource", "resource": "directus-db", "output": "user" },
    "DB_PASSWORD": { "type": "resource", "resource": "directus-db", "output": "password" },
    "DB_SSL__REJECT_UNAUTHORIZED": { "value": "false" }
  }
}

Describe Directus in modelence.config.json

Add modelence.config.json next to package.json. It installs the package on the official Node.js 26 image, runs npm start, creates the database and lists every variable Directus needs, so the sandbox and production environments come from the same file:

modelence.config.json
{
  "$schema": "https://cloud.modelence.com/schema/modelence.config.json?version=1",
  "resources": {
    "directus": {
      "type": "service",
      "image": "node-26-slim",
      "build": { "commands": ["npm ci"] },
      "start": { "commands": ["npm start"] },
      "healthCheck": { "type": "http", "path": "/server/ping", "gracePeriod": 120 }
    },
    "directus-db": { "type": "postgres", "plan": "postgres-1gb" }
  },
  "env": {
    "DB_CLIENT": { "value": "pg" },
    "DB_HOST": { "type": "resource", "resource": "directus-db", "output": "host" },
    "DB_PORT": { "type": "resource", "resource": "directus-db", "output": "port" },
    "DB_DATABASE": { "type": "resource", "resource": "directus-db", "output": "database" },
    "DB_USER": { "type": "resource", "resource": "directus-db", "output": "user" },
    "DB_PASSWORD": { "type": "resource", "resource": "directus-db", "output": "password" },
    "DB_SSL__REJECT_UNAUTHORIZED": { "value": "false" },
    "SECRET": { "type": "secret" },
    "ADMIN_EMAIL": {},
    "ADMIN_PASSWORD": { "type": "secret" },
    "PUBLIC_URL": {},
    "IP_TRUST_PROXY": { "value": "true" },
    "STORAGE_LOCATIONS": { "value": "s3" },
    "STORAGE_S3_DRIVER": { "value": "s3" },
    "STORAGE_S3_BUCKET": {},
    "STORAGE_S3_REGION": {},
    "STORAGE_S3_KEY": { "type": "secret" },
    "STORAGE_S3_SECRET": { "type": "secret" }
  }
}

Understand the settings

  • The build is only npm ci, which installs the exact versions from package-lock.json. Directus ships its admin app prebuilt inside the package, so there's no build step.
  • Directus listens on PORT, which defaults to 8055 and which Modelence sets to 3000 for a Node.js service, and it binds to 0.0.0.0 by default, so no port setting is needed.
  • SECRET signs login tokens. Without it, Directus picks a random value on each start and warns that tokens won't persist between restarts, which logs everyone out on every deploy. Generate one with openssl rand -hex 32. Directus 12 doesn't use the older KEY variable.
  • ADMIN_EMAIL and ADMIN_PASSWORD are only read when bootstrap installs a new database. After that, change the password in the admin app.
  • PUBLIC_URL is the address Directus puts in password reset emails, file links and OAuth callbacks: https://<app>-<environment>.cloud.modelence.app or your own domain.
  • IP_TRUST_PROXY=true makes Directus read the client's address from the forwarded headers set by Modelence's load balancer, which activity logs and the rate limiter use.
  • The health check calls /server/ping, which answers pong once the server is up. Directus 12 answers /server/health with 403 unless the request carries an admin token, so a load balancer can't use it.

Store files in S3

By default Directus writes uploads to ./uploads on the container, which starts empty on every deploy. The four STORAGE_* lines with values send them to a bucket instead, and Directus keeps each file's metadata in its directus_files table in Postgres:

  • STORAGE_LOCATIONS=s3 names one storage location, s3, and STORAGE_S3_DRIVER=s3 makes it use the S3 driver. Every other setting of that location starts with STORAGE_S3_.
  • STORAGE_S3_BUCKET, STORAGE_S3_REGION, STORAGE_S3_KEY and STORAGE_S3_SECRET come from your bucket and access key. The bucket can stay private, since Directus streams files through /assets/<id> and applies its own permissions to them.
  • For Cloudflare R2, add STORAGE_S3_ENDPOINT with your account's endpoint, such as https://<account id>.r2.cloudflarestorage.com, and set the region to auto.

Image transformations, such as /assets/<id>?width=400, are generated by Directus from the original in the bucket and cached as new files there.

Deploy

In the project folder, run:

npx modelence@latest deploy

The browser opens so you can sign in and choose the organization, app and environment. The CLI then asks for everything the environment doesn't have yet: SECRET, ADMIN_EMAIL, ADMIN_PASSWORD, PUBLIC_URL and the bucket settings. A new environment also asks which of the 17 AWS regions to use, and creates the container and database there. The CLI uploads the project, runs npm ci and follows the rollout. On this first start, bootstrap installs Directus into the empty Postgres, which is why gracePeriod allows 120 seconds before the health check counts.

When the deploy finishes, open /admin on the environment's URL and log in with ADMIN_EMAIL and ADMIN_PASSWORD. Your own domain goes under Domains in the dashboard, and PUBLIC_URL changes with it. You can view or change any of these values later under Environment variables, where every view of a secret is logged.

Let your coding agent do it

Paste Deploy using https://modelence.com/skill.md into Claude Code, Cursor or Codex in the project. The agent reads the Modelence docs, writes the config, runs the deploy and asks you for the secret, the admin account and the bucket details when it needs them.

Production readiness

Add Redis before running more than one container

Directus keeps its cache, rate limiter counters and internal messages in memory unless Redis is configured, and with several containers each one would have its own copy, so a schema change in one wouldn't reach the others. Add a managed Redis, pass its url output as REDIS, and turn on the cache and the rate limiter with Redis as their store. Directus then uses that Redis for messages between containers too. We didn't run this part locally, so check the logs after the first deploy with it:

{
  "resources": {
    "directus-cache": { "type": "redis" }
  },
  "env": {
    "REDIS": { "type": "resource", "resource": "directus-cache", "output": "url" },
    "CACHE_ENABLED": { "value": "true" },
    "CACHE_STORE": { "value": "redis" },
    "CACHE_AUTO_PURGE": { "value": "true" },
    "RATE_LIMITER_ENABLED": { "value": "true" },
    "RATE_LIMITER_STORE": { "value": "redis" }
  }
}

Merge these entries into your existing resources and env, deploy, and then raise the container count under Configure.

Apply the data model on deploy

Once you commit snapshot.yaml, you can have each environment apply it when it starts by putting schema apply between bootstrap and start in package.json. Make data model changes in one place, such as your local Directus, take a new snapshot, deploy to the sandbox first, then to production:

"start": "directus bootstrap && directus schema apply --yes ./snapshot.yaml && exec directus start"

Apply makes the target match the file, so a collection you deleted locally is deleted in production too, along with its data. Check npx directus schema apply --dry-run ./snapshot.yaml against a copy first if you're unsure.

Upgrade by changing one version

Upgrading means changing the directus version in package.json, running npm install, and deploying. Bootstrap runs the new version's migrations before the server starts. During the rollout the old container keeps serving while the new one migrates, so deploy upgrades to the sandbox first, read the release notes for breaking changes, and make sure a recent production backup exists. Major versions can also raise the Node.js requirement, which you change with the image line.

Keep backups, the bucket and SECRET together

Production Postgres on Modelence is backed up at least every six hours and kept for up to 12 months, with restores through [email protected]. That covers collections, users, permissions, Flows and file metadata. The files themselves are in the bucket, so turn on bucket versioning to recover deleted ones. Keep SECRET with your recovery notes. A new value logs everyone out, while static tokens you gave integrations keep working, since Directus stores those in the database.

Put extensions in the repository

Custom interfaces, endpoints, hooks and operations you build with the Directus extensions SDK go in ./extensions, and Directus loads them on start. Committing them means every environment runs the same set and a redeploy can't lose one.

If your team installs extensions from the Marketplace in the admin app instead, set EXTENSIONS_LOCATION=s3. Directus then keeps every extension in the bucket and syncs them to each container when it starts, in place of the local ./extensions folder.

Watch logs and memory

Directus's log lines, including each migration bootstrap runs and every failed request, show on the environment's Logs page with no setup. The dashboard shows memory and CPU per container. In our test an idle Directus used about 320 MB of memory, so Small, with 0.5 vCPU and 1 GB at about $22 a month, is a reasonable first size, and image transformations on large files are what push it up. Directus also sends anonymous usage data to its makers by default, and TELEMETRY=false turns that off.

Modelence vs Directus Cloud, Railway and Render for Directus

The usual alternatives for hosting Directus are Directus Cloud, a Railway template, Render's Directus article and a VPS. Details below come from each provider's own pages, checked on November 29, 2026.

OptionHow Directus runsData and filesPrice
ModelenceThe npm package on the official Node.js image, on AWS Fargate in 17 regionsManaged Postgres backed up at least every six hours; files in your S3 or R2 bucketFree plan; paid plans from $20 a month including $20 of usage, and managed databases need a paid plan
Directus CloudHosted by Directus, as an add-on to a Directus planManaged by DirectusPer plan, on Directus's pricing page
RailwayA community template with the Docker image, PostGIS and RedisFiles on a volume, at $0.15 per GB a monthHobby $5 and Pro $20 a month including that much usage, then CPU and memory by use
RenderThe Docker image as a web service, from Render's Directus articlePostgres plus a disk for uploads, at $0.25 per GB a monthHobby $0 or Pro $25 a month per workspace, plus instances from $7 a month
VPSDocker Compose on a server you manage, such as Hetzner CloudThe server's disk, with backups, TLS and updates handled by youHetzner servers from €5.49 a month before VAT

Directus Cloud fits teams that would rather buy Directus as a service and not run it. A VPS costs the least for a single instance if you're comfortable maintaining the server and its backups. Railway and Render start Directus from a template or article quickly, with uploads on a volume or disk, and Render's docs note that a service with a disk can't run more than one instance or deploy without downtime. Modelence fits when Directus should run on AWS with managed MongoDB, Postgres and Redis next to it, files in a bucket you own and every setting in the repository. Railway alternatives and Railway vs Render go deeper on those platforms, and Migrate from Railway covers moving an app off Railway.

Next steps

Frequently asked questions

How do I deploy Directus?

Install the directus package in a project, set the start script to directus bootstrap followed by directus start, and give it a Postgres database through the DB_ variables, a fixed SECRET, the first admin's email and password, and an S3 bucket for files. On Modelence that's a modelence.config.json that creates the database and declares those variables, and npx modelence@latest deploy runs it.

Can I run Directus without Docker?

Yes. Directus publishes the same server as the directus npm package, and the Directus docs describe installing it from npm with Node.js 26 or newer. Run npx directus bootstrap once against your database and npx directus start to serve it. This guide deploys it that way on the node-26-slim image, so the project has no Dockerfile at all.

Why does /server/health return 403 in Directus?

Directus 12 only returns the detailed health report, which checks the database, cache and storage, to a request with an admin token. Anonymous requests get 403, so a load balancer health check fails against it. Use /server/ping instead, which answers pong without a login, and call /server/health with a token from your own monitoring if you want the details.

Why does everyone get logged out of Directus after a deploy?

Because SECRET isn't set, so Directus generates a random one on every start and the tokens signed with the previous value stop working. Directus logs a warning about this at startup. Set SECRET to a long random value, such as the output of openssl rand -hex 32, and keep it the same in that environment.

Is Directus free to self-host?

Directus 12 is source-available under the Monospace Sustainable Core License, not an open-source license, and its pricing page says self-hosting is available on every tier. Smaller organizations can use it free under Directus's grant, and larger ones need a paid license, with the current thresholds and tiers on directus.com/pricing. Hosting costs are separate from the license.

Does Directus still need the KEY variable?

Not in Directus 12. KEY was a project identifier in older versions, and the current server doesn't read it. SECRET is the variable that matters, since it signs access and refresh tokens. If you upgrade an older project, you can leave KEY set or remove it.

Do ADMIN_EMAIL and ADMIN_PASSWORD change the admin login later?

No. Directus bootstrap only uses them when it installs into an empty database, to create the first administrator. After that it skips installation, so changing the variables does nothing. Change the password in the admin app under your user, or create other administrators there.

Where does Directus store uploaded files?

In whatever storage location STORAGE_LOCATIONS names, which is local by default and writes to ./uploads. In production, set it to s3 with the S3 driver, bucket, region and keys so files survive a redeploy, and the bucket can stay private because Directus serves files through its /assets endpoint with its own permissions. File metadata always stays in the database.

How much does it cost to host Directus on Modelence?

Modelence has a free plan, and Directus with managed Postgres needs a paid plan, from $20 a month with $20 of usage included. Usage covers the container, billed by the hour by size, and the database, plus Redis if you add it. Idle Directus used about 320 MB in our test, so Small, with 0.5 vCPU and 1 GB at about $22 a month, is a good start, and your storage provider bills the bucket.

Deploy other stacks

Deploy your Directus app

Start on the free plan and move up when your app needs more.

Or paste this into your coding agent