# Migrate Next.js from Heroku to Reverhost

Move your Next.js app in four steps, and keep Heroku running until the new deployment works.

## Export your variables

```
heroku config -s > .env
```

Then import them into Reverhost.

```
npx ezhst env import .env
```

## Change the Next.js setup

No adapter is needed. Remove `output: "export"` if you want server features, and treat incremental static regeneration as a single-container cache.

`Procfile` is not read by Reverhost, so its build and routing rules need moving into your app or into your Dockerfile.

Start from the Node.js template and replace its last line with the Next.js start command. For a smaller image, set `output: "standalone"` and run `node .next/standalone/server.js` from a multi-stage build.

```Dockerfile
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN --mount=type=secret,id=appenv,target=/run/secrets/appenv sh -c 'set -a; . /run/secrets/appenv; set +a; npm run build'
ENV NODE_ENV=production PORT=3000
EXPOSE 3000
CMD ["sh", "-c", "exec npx next start -H 0.0.0.0 -p $PORT"]
```

## Deploy and test

```
npx ezhst projects create my-project --link
npx ezhst apps create my-app
npx ezhst link --project <project-slug> --app <app-slug>
npx ezhst build dockerfile set -f Dockerfile
npx ezhst env import .env
npx ezhst deploy
```

Test your `easyhost.fun` URL before changing DNS. Heroku runs your app on dynos, so check anything that depends on it, such as platform functions or cron configuration. Reverhost does not run scheduled jobs.

## Switch your domain

```
npx ezhst domains add www.example.com
npx ezhst domains list
npx ezhst domains verify www.example.com
```

Follow the [custom domain guides](/guides) for your DNS provider. Keep Heroku running until traffic has moved. Also read [why Next.js may be unreachable](/errors/nextjs-app-unreachable) and the [Heroku overview](/migrate/heroku).
