---
title: "Deploy a Next.js App"
description: "Deploy a Next.js application to Miget with git push and a public URL."
---
Deploy a Next.js app to Miget in a few minutes. Miget auto-detects Node.js from your `package.json`, installs dependencies, builds, and serves your app on a public URL.
## Prerequisites
Before you start, make sure you have:
- A [Miget account](https://app.miget.com).
- Git installed locally and your app in a Git repository.
- A Next.js app with a `package.json`.
Your `package.json` scripts must include a build and start command so the [buildpack](/overview/buildpacks) can detect and run your app:
```json package.json
{
"scripts": {
"build": "next build",
"start": "next start"
}
}
```
Every app on Miget must listen on `0.0.0.0:5000`. Miget sets an immutable `PORT=5000` environment variable, and public ingress only reaches port `5000`. `next start` respects the `PORT` env var, so it binds to `5000` automatically - you don't need to configure anything. See [Ports](/networking/ports) for details.
## Deploy
Go to [app.miget.com](https://app.miget.com), select **New**, then **Application**. Give your app a name, select the resource it should run in, and select **Next**.
Select **Auto detection (Miget Buildpacks)** as the builder, pick a size, then select **Next**. Miget will detect Node.js from your `package.json`.
Select **git push**, then **Create**. Copy the git token shown - you'll need it to authenticate your push.
Add the Miget remote and push. Replace ``, ``, and `` with your own values:
```bash
git remote add miget https://git..miget.io//
git push miget
```
Miget detects Node from your `package.json`, installs dependencies, runs `next build`, starts your app with `next start`, and deploys it to a public URL.
This guide uses **git push**, but it's one of several ways to deploy. You can also connect a [GitHub repository](/deployments/github-integration) for auto-deploys and pull request previews, deploy from a public Git repository, or push a prebuilt [container image](/deployments/container-registry). See [all deployment methods](/deployments/how-it-works).
## Add a database (optional)
Need persistent storage? Add a PostgreSQL database to your app:
1. Open your app's **Addons** tab.
2. Add a **PostgreSQL** addon.
Miget automatically injects a `DATABASE_URL` environment variable (a `postgres://...` connection string) into your app. Read it in your code:
```js
const connectionString = process.env.DATABASE_URL;
```
See [PostgreSQL](/databases/postgresql) for connection details and [Using secrets](/deployments/using-secrets) for managing your own environment variables.
## Next steps
Learn how the git push deployment flow works end to end.
Connect a repository for auto-deploys and PR previews.
Point your own domain at your Next.js app.
Understand how Miget shares compute across your apps.
How buildpacks detect and build a Next.js app.