Deploying
Deploy a Next.js app to production
Deploy a Next.js app on DployHub: automatic build with next build, start with next start, correct port handling, environment variables and staging.
Updated 3 min read
Next.js apps deploy on DployHub with no configuration in most cases. When next is in your dependencies we treat the project as a Node.js server, run your build script and start the app with next start, so server components, API routes and server-side rendering all work as they do locally.
What gets detected
- Package manager from your lockfile: pnpm, yarn or npm.
- Build command: your
buildscript, normallynext build. - Start command: your
startscript if you have one, otherwisenpx next start. - Port: taken from the start script if it sets one (for example
next start -p 4000), otherwise 3000. - Base image
node:20-alpinewithNODE_ENV=production.
A standard Next.js package.json needs nothing extra:
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "14.2.5",
"react": "18.3.1",
"react-dom": "18.3.1"
}
}Deploy steps
- 1
Create the app
Go to New app, choose GitHub or a Public Git URL and select your repository and branch.
- 2
Keep auto-detection
Leave "Figure it out for me" selected. For a monorepo, set Folder with your app, for example
apps/web. - 3
Add environment variables
Add any API keys or database URLs your app needs. You can do this after creating the app in the Environment variables tab, then redeploy.
- 4
Pick resources and create
Next.js builds can be memory-hungry; 1 GB of memory is a comfortable starting point for most apps.
Environment variables and builds
Environment variables are set separately for staging and live, are encrypted at rest and are shown masked until you click Reveal. Changes apply on the next deploy or restart, so redeploy or restart after saving. Use Copy from staging to bring a tested set of variables across to live. Keep secrets such as database URLs and API keys here rather than in .env files committed to the repository.
Static export
If you use output: 'export' and have no server, you can serve the generated out folder as a static site by choosing Static website or providing a small Dockerfile. Most Next.js apps should simply run as a server with next start.
Troubleshooting
- Build killed or exit code 137: raise memory in Settings, Resources. See App crashed: out of memory.
- App didn't answer on the port: check that the port in Settings matches what
next startuses. See Port and health checks. - Health check returns 5xx: point the health check path at a page that renders without external services.
The short version of this guide is at /deploy/nextjs. If something still fails, raise a ticket with the deployment attached.
Frequently asked questions
Do Next.js API routes and server rendering work?
Yes. Next.js runs as a Node.js server with next start, so API routes, server components and SSR work normally.
How much memory does a Next.js app need?
It depends on the app, but 1 GB is a comfortable starting point. You can change resources later in Settings.
Why does my app not see a variable I just added?
Environment variable changes apply on the next deploy or restart. Redeploy or restart the environment after saving.
Related articles
- Deploy a Node.js app (Express, Fastify, NestJS)How DployHub detects and deploys Node.js apps: package manager, build and start commands, port detection and the settings you can override.
- Set environment variables for staging and liveAdd API keys, database URLs and other settings as environment variables on DployHub, separately for staging and live, and apply them with a redeploy.
- Choose vCPU, memory and storage for your appPick vCPU, memory and storage for your live environment, see the monthly price before you commit, and change resources later with a quick restart.
- Staging and live environments: test, then go liveEvery DployHub app has a free staging environment and a live one. Learn how deploys flow through staging and how Go live promotes the same image.