Next.js › Deployment

How do you build and run a Next.js application in production outside of Vercel, such as on your own server?

Intermediate

Answer

You run the build command to generate an optimized production build, then use the start command to run a Node.js server that serves that build, making sure any required environment variables are set on the server before starting it.
# Build the application
npm run build

# Start the production server
npm run start
Real-world example A company running its own infrastructure builds its Next.js application, copies the build output to their server, and runs the start command behind a process manager to keep the app running reliably.

Common follow-ups: What is the difference between npm run dev and npm run build followed by npm run start?;How do you keep a Next.js server running continuously in production?