Skip to content
Start free

Run a command before each deploy

A pre-deploy command runs in each new version of your app before it goes live. Use it for jobs that must happen before new code serves visitors, such as database migrations.

It runs inside the new version, with your site’s environment variables, before your server starts. If the command fails, the new version doesn’t go live and your current version keeps running, so a failed migration never takes your site down.

  1. Open your site in Sites & Apps and click Settings.

  2. In Pre-deploy command, type your command, for example:

    • npx prisma migrate deploy
    • npx drizzle-kit migrate
    • npm run migrate
  3. Click Save.

  4. Deploy a new version. The command runs from that deploy on.

To stop using it, clear the box and click Save. Your next deploy starts without it.

  • A Node.js app. Static sites have no server, so there’s nothing to run before them.
  • A start script in package.json, such as "start": "next start" or "start": "node server.js". The command runs first, then your start script.
  • A command that finishes. It should do its job and stop. A command that keeps running stops your app from starting.

The command can use the environment variables on your site’s Environment variables tab, such as DATABASE_URL.

  • Every new version: uploads, Git pushes, your AI tool’s deploys and versions promoted from staging.
  • Every time that version starts: the command is part of how the version starts, so it also runs when your app restarts, for example after a plan change. Make sure it’s safe to run more than once. Migration tools are: they skip migrations that have already run.
  • Restores: an earlier version starts as it was built. If it was built with a pre-deploy command, that command runs again; if it was built before you added one, it doesn’t.

If a deploy didn’t go live because of the command, its error lines are on the deploy’s page, and Fix a failed deploy explains what to look for.