> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shardcloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Migrate from Vercel to Shard Cloud

> Move a Vercel project (Next.js or static site, environment variables, Postgres, KV, Blob and cron jobs) to Shard Cloud, step by step.

## Introduction

This guide moves a Vercel project to Shard Cloud. On Shard Cloud your app runs as a regular, always-on server instead of serverless functions, so there are no cold starts and no function time limits.

| On Vercel | On Shard Cloud |
| - | - |
| Next.js project | An [application](https://docs.shardcloud.app/apps.md) running `next start` |
| Static site (Vite, React, Astro...) | An application serving the built files |
| Serverless functions in `/api` (non-Next.js projects) | Routes of a Node.js API application |
| Environment variables | Environment variables (import a `.env` file) |
| Vercel Postgres / Neon | A PostgreSQL [database](https://docs.shardcloud.app/databases.md) |
| Vercel KV / Upstash Redis | A Redis database |
| Vercel Blob | The [Shard Cloud CDN](https://docs.shardcloud.app/cdn/introduction.md) API |
| Cron jobs (`vercel.json`) | A small application that calls your routes on a timer |
| Git deployments | [Git integration](https://docs.shardcloud.app/tutorials/platform/git-integration.md): deploy on every push |
| Domains | [Custom domain](https://docs.shardcloud.app/tutorials/platform/custom-domain.md), with HTTPS included |

## Before You Start

### What you need

* The [Vercel CLI](https://vercel.com/docs/cli) (`npm i -g vercel`), logged in, and the project linked (`vercel link` in the code folder)
* The project's code
* A Shard Cloud account with room for the app (a Next.js app needs about 1024 MB to build), plus any databases
* To copy a Postgres database: [Docker](https://www.docker.com/), or `pg_dump` and `pg_restore` installed locally

### What doesn't move

* **Preview deployments per pull request.** You can keep a staging app instead: a second application deployed from another branch (step 7).
* **Vercel Analytics, Speed Insights and Edge Config.** They only work on Vercel. Shard Cloud web apps have their own [HTTP analytics](https://docs.shardcloud.app/apps.md#http-metrics) (Core plan and above). Remove `@vercel/analytics` and `@vercel/speed-insights` from your code, and move Edge Config values to environment variables or your database.

## Step 1: Export the Environment Variables

```bash theme={null}
vercel env pull .env.production --environment=production
```

`.env.production` now holds the production variables. Open it and:

* **Delete the ones Vercel adds itself**: `VERCEL`, `VERCEL_ENV`, `VERCEL_URL`, `VERCEL_OIDC_TOKEN` and any other `VERCEL_*`. If your code uses `VERCEL_URL` to build links, set your own variable with the Shard Cloud address instead.
* **Fill in the sensitive ones.** Variables marked *Sensitive* on Vercel come back empty: copy their values from where they came from.
* Leave the database variables for now: you'll replace them in step 3.

> [!WARNING]
>
> This file contains your secrets. Don't commit it, and delete it when you're done.

## Step 2: Prepare the App

> [tab] Next.js
>
> Shard Cloud runs Next.js with `next start`, which supports everything a Node.js server does: server rendering, API routes and route handlers, server actions, middleware, ISR and image optimization. Check that `package.json` has the usual scripts:
>
> ```json package.json theme={null}
> {
>   "scripts": {
>     "build": "next build",
>     "start": "next start"
>   }
> }
> ```
>
> `next start` listens on the `PORT` variable, which Shard Cloud sets to 80, so no `-p` flag is needed. Create a `.shardcloud` file at the root:
>
> ```systemd .shardcloud theme={null}
> DISPLAY_NAME=My Next.js App
> LANGUAGE=node
> MEMORY=1024
> VERSION=recommended
> SUBDOMAIN=myapp
> CUSTOM_COMMAND=npm run build && npm start
> ```
>
> The build runs each time the app starts, with the app's environment variables, so `NEXT_PUBLIC_*` values are picked up. After changing a variable, restart the app so it builds again.
>
> If you used `rewrites`, `redirects` or `headers` in `vercel.json`, move them to `next.config.js` (same names, see the [Next.js docs](https://nextjs.org/docs/app/api-reference/config/next-config-js/rewrites)).

> [tab] Static site (Vite, React, Astro...)
>
> The site is built to static files and served by a small server that sends every unknown route to `index.html` (so client-side routing works):
>
> ```systemd .shardcloud theme={null}
> DISPLAY_NAME=My Site
> LANGUAGE=node
> MEMORY=512
> VERSION=recommended
> SUBDOMAIN=mysite
> CUSTOM_COMMAND=npm run build && npx serve -s dist -l 80
> ```
>
> Replace `dist` with your framework's output folder (`build` for Create React App, `out` for a Next.js static export). See the [Vite tutorial](https://docs.shardcloud.app/tutorials/website/vite.md) for other options.

> [tab] Serverless functions (/api)
>
> Outside Next.js, Vercel runs each file in `/api` as a function. On Shard Cloud, serve them from one Express app. A Vercel function such as:
>
> ```javascript api/hello.js theme={null}
> export default function handler(req, res) {
>   res.status(200).json({ message: `Hello ${req.query.name}` });
> }
> ```
>
> keeps its code and is mounted as a route:
>
> ```javascript server.js theme={null}
> import express from 'express';
> import hello from './api/hello.js';
>
> const app = express();
> app.use(express.json());
>
> app.all('/api/hello', hello);
> // one line per file in /api
>
> // Serve the built frontend too, if the project has one
> app.use(express.static('dist'));
> app.get('*', (req, res) => res.sendFile('index.html', { root: 'dist' }));
>
> app.listen(process.env.PORT || 80, '0.0.0.0');
> ```
>
> Express's `req` and `res` have the same `req.query`, `req.body`, `res.status()` and `res.json()` that Vercel's helpers provide. Then run it with `CUSTOM_COMMAND=npm run build && node server.js` (drop `npm run build` if there's no frontend).

Set `VERSION` to your Vercel project's Node.js version (in **Settings → Build and Deployment**) if it isn't the recommended one. Dependencies are installed with npm, yarn, pnpm or bun, following your lockfile.

## Step 3: Move the Data

### Postgres (Vercel Postgres or Neon)

**1. Create the database**

In the [Dashboard](https://shardcloud.app/dash), create a **PostgreSQL** database with the same major version as the old one or a newer one (the version can't change later).

**2. Dump the old database**

Use the **direct (unpooled)** connection URL: `POSTGRES_URL_NON_POOLING` or `DATABASE_URL_UNPOOLED` in your environment variables. The pooled URL can break `pg_dump`.

```bash theme={null}
docker run --rm -v "$PWD:/backup" postgres:17 \
  pg_dump -Fc --no-owner --no-acl -f /backup/vercel.dump "YOUR_UNPOOLED_URL"
```

**3. Restore it into Shard Cloud**

```bash theme={null}
docker run --rm -v "$PWD:/backup" postgres:17 \
  pg_restore --verbose --no-owner --no-acl \
  --dbname "YOUR_SHARD_CLOUD_DATABASE_URL" /backup/vercel.dump
```

Use the Docker image of your Shard Cloud database's major version (`postgres:17`, `postgres:18`).

**4. Point the app at it**

In `.env.production`, set every Postgres variable your code reads (`DATABASE_URL`, `POSTGRES_URL`, `POSTGRES_PRISMA_URL`...) to the Shard Cloud connection URL, and delete the `PG*` and unpooled ones your code doesn't use.

> [!NOTE]
>
> `@vercel/postgres` and `@neondatabase/serverless` talk to Neon over HTTP and WebSockets, which a regular PostgreSQL server doesn't speak. If your code imports them, switch to [`pg`](https://www.npmjs.com/package/pg) (or `postgres`). Prisma, Drizzle with `node-postgres` and other regular drivers work as they are.

### KV (Vercel KV or Upstash Redis)

Create a **Redis** database. KV data is usually a cache, so it starts empty.

`@vercel/kv` and `@upstash/redis` use Upstash's HTTP API, so they can't talk to a regular Redis server. Switch to a Redis client such as [`redis`](https://www.npmjs.com/package/redis) or [`ioredis`](https://www.npmjs.com/package/ioredis), with the connection URL from the database page:

```javascript theme={null}
// Before
import { kv } from '@vercel/kv';
await kv.set('key', 'value', { ex: 60 });

// After
import Redis from 'ioredis';
const redis = new Redis(process.env.REDIS_URL);
await redis.set('key', 'value', 'EX', 60);
```

Then set `REDIS_URL` in `.env.production` and delete the `KV_*` variables.

### Blob (Vercel Blob)

Files move to the [Shard Cloud CDN](https://docs.shardcloud.app/cdn/introduction.md):

1. Replace `put()` from `@vercel/blob` with an upload to the CDN API. The upload has to happen on the server (a route handler or API route), since it uses your CDN token.
2. Copy the existing files: list them with `list()` from `@vercel/blob`, download each one, and upload it to the CDN.
3. If your database stores Blob URLs (`https://...public.blob.vercel-storage.com/...`), replace them with the new CDN URLs.

The [Lovable migration guide](https://docs.shardcloud.app/tutorials/migration/lovable.md#step-6-move-storage-to-the-cdn) walks through the same steps for another storage service, with a script you can adapt.

## Step 4: Replace Cron Jobs

Vercel calls the paths in `vercel.json`'s `crons` on a schedule, with `Authorization: Bearer $CRON_SECRET`:

```json vercel.json theme={null}
{
  "crons": [{ "path": "/api/cron/cleanup", "schedule": "0 3 * * *" }]
}
```

Keep your cron routes as they are, and call them from a small scheduler application:

```javascript scheduler.js theme={null}
const cron = require('node-cron');

const jobs = [
  { path: '/api/cron/cleanup', schedule: '0 3 * * *' },
  // one entry per item of "crons"
];

for (const job of jobs) {
  cron.schedule(job.schedule, async () => {
    const res = await fetch(process.env.APP_URL + job.path, {
      headers: { Authorization: `Bearer ${process.env.CRON_SECRET}` },
    });
    console.log(job.path, res.status);
  }, { timezone: 'UTC' });
}
```

```json package.json theme={null}
{ "dependencies": { "node-cron": "^3.0.3" } }
```

```systemd .shardcloud theme={null}
DISPLAY_NAME=My App Scheduler
MAIN=scheduler.js
MEMORY=256
VERSION=recommended
```

Set its `APP_URL` (`https://myapp.shardweb.app`, or your domain) and the same `CRON_SECRET` as the app. It has no `SUBDOMAIN`, so 256 MB is enough, and it restarts automatically if it crashes. Vercel cron schedules are in UTC, as above.

## Step 5: Deploy

**1. Upload the app**

Zip the project **without** `node_modules/`, `.next/`, `.vercel/` and build output (100 MB at most), and upload it in the [Dashboard](https://shardcloud.app/dash/applications).

**2. Import the environment variables**

On the application's page, open **Environment Variables**, choose **Import .env** and pick `.env.production`. Check the values, then restart the application so it builds with them.

**3. Follow the first start**

Watch the logs on the application's page: dependencies install, the build runs, then the server starts.

**4. Connect GitHub**

To deploy on every push like on Vercel, connect the application to your repository on its **Deploy** page, choosing the production branch. See [Git integration](https://docs.shardcloud.app/tutorials/platform/git-integration.md). Turn on **Auto-Restart on Deploy** so each push builds and serves the new code.

## Step 6: Test, Then Switch the Domain

**1. Test on the free subdomain**

Open `https://myapp.shardweb.app` and check pages, logins, forms, uploads and anything that reads or writes data.

**2. Add your domain**

Add your domain to the application and update its DNS to point at Shard Cloud instead of Vercel. If the domain uses Vercel's nameservers, change the records in Vercel's DNS settings, or move the domain's DNS elsewhere first. See [Custom Domain](https://docs.shardcloud.app/tutorials/platform/custom-domain.md). HTTPS is set up for you.

**3. Clean up Vercel**

Once traffic is on Shard Cloud and you've checked the data, remove the domain from the Vercel project and delete the project and its stores to stop any charges.

## Step 7 (Optional): A Staging App

To replace preview deployments, create a second application from the same code with its own `SUBDOMAIN` (for example `myapp-staging`), its own environment variables, and its **Deploy** page connected to your development branch.

> [!WARNING]
>
> A `.shardcloud` file in your repository is applied to **every** application deployed from it, so two apps would fight over the same `SUBDOMAIN`. With more than one application on the same repository, keep `.shardcloud` out of the repository (add it to `.gitignore`) and let each application keep the one it was uploaded with.

## Troubleshooting

> [accordion] Out of memory during the build
>
> `next build` runs inside the app's RAM. Raise `MEMORY` to 1024 MB or more.

> [accordion] The site doesn't load, but the logs show the server started
>
> The server must listen on port 80 (the `PORT` variable) and on `0.0.0.0`. `next start` and `serve -l 80` already do; check custom servers.

> [accordion] A NEXT\_PUBLIC\_ variable is empty in the browser
>
> `NEXT_PUBLIC_*` values are baked in at build time. Check that the variable is set on the application, then restart it so the build runs again.

> [accordion] Error connecting to the database after switching
>
> Check that every database variable your code reads points to the Shard Cloud URL, and that the code doesn't use `@vercel/postgres`, `@neondatabase/serverless`, `@vercel/kv` or `@upstash/redis`, which only speak HTTP (see step 3).

> [accordion] Changed an environment variable and nothing happened
>
> Environment variables are read when the app starts: restart the application after changing them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.