Preparing a Next.js App for Production
Desliza para mostrar el menú
Building an app locally is only the first step. Before releasing it, you should make sure the application is ready for a production environment.
In Next.js, production preparation usually means building the app, checking that it runs correctly outside development mode, and making sure the project uses a clean and reliable structure. The standard production workflow is to run next build and then start the app with next start. Next.js supports deployment as a Node.js server, Docker container, or static export, depending on which framework features your app uses.
Building the App
To create a production build, run:
npm run build
This command prepares an optimized version of your application for deployment. In a standard Next.js setup, the production scripts are:
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}
These are the default scripts recommended in the official docs.
Testing the Production Build
After building the app, start it in production mode:
npm run start
This is important because development mode and production mode are not the same. Some behavior, performance, and caching only appear correctly in a real production build, so testing with build and start helps you catch issues before deployment. The official Next.js guidance also recommends using local development for building features and reserving Docker mainly for production deployment or testing production builds.
What to Check Before Deployment
Before deploying, make sure your routes work correctly, metadata is defined for important pages, and your loading and error states behave as expected. You should also confirm that forms and route handlers work properly in production mode, not only during development.
It is also a good idea to keep your project organized and avoid unnecessary complexity. Next.js already provides many production optimizations automatically, so the main goal at this stage is to verify that your app is complete, stable, and ready to run outside your local environment. The official production checklist emphasizes performance, user experience, and security as the main areas to review before release.
Why This Step Matters
Preparing your app for production helps you move from "it works on my machine" to "it works for real users". A production build is optimized, more realistic, and closer to how the app will behave after deployment.
This step is also where you confirm that your application is ready to be hosted on a real platform and used as a complete web app.
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla