Build and deploy

A production build prepares the app to run on your host. Run that build locally first to check the production version, then deploy it using your host's Next.js setup.

Run the commands from the project folder containing package.json, with dependencies installed. Configure any environment variables your integrations need before building; see Environment variables.

Build locally

  1. 1

    Build the app

    npm run build

    This runs next build to create the production version. The build must finish successfully before you can start the production server. If it fails, resolve the error shown in the terminal and build again.

  2. 2

    Run the production server

    Stop the development server if it is using the same port, then run:

    npm run start

    This runs next start to serve the completed build on your computer. Open the URL printed in the terminal.

    After making code changes, build again before restarting the production server so it serves the latest version. See the Next.js CLI reference for command options.

Configure production services

Set your production environment variables in the host's settings before its first build. Local .env.local values are not automatically supplied from your repository. Provide NEXT_PUBLIC_ values before building, since changing them requires a new build.

Deploy to your host

The app uses Next.js server features, so choose hosting that can run a Next.js application. A host that only serves static files is not sufficient for the app as provided.

On a hosting platform with a Next.js integration, connect your application repository, select its Next.js setup and use the folder containing package.json as the project root. Follow that provider's instructions for building and running the app.

On a Node.js server, install the project's dependencies and run the build command above. Keep the production server running with your server's process manager. Use a supported Node.js version consistent with your build environment.

Docker and adapter-based deployments have their own setup. Check support for your Next.js version and follow the relevant Next.js deployment guidance.