Deployment
Level: Beginner to Intermediate
- Building for production with npm run build
- Environment variables for production
- Deploying to Vercel (easiest)
- Docker containerization for custom servers
- Static exports vs server rendering choices
- API base URL configuration
- Monitoring and logging in production
- SMS app on production infrastructure
Why This Matters
Deployment is part of building production React applications with Next.js. You will use it when creating student dashboards, SEO-friendly pages, API-connected forms, route handlers, layouts, and deployments for .NET-backed systems.
Before deploying a Next.js app, create a production build.
npm run build
Then run it locally:
npm run start
The Problem
Beginners often treat Next.js like plain React and miss routing, rendering, server/client boundaries, environment variables, and deployment behavior. This lesson shows how Deployment works in a real School Management System frontend that talks to ASP.NET Core APIs.
Environment Variables
Use .env.local for local development:
ASP_NET_API_URL=https://localhost:5001
In production, configure the same variable in your hosting provider.
Build Output
Next.js optimizes:
- JavaScript bundles
- CSS
- route assets
- server-rendered pages
- static pages
- images and fonts
Hosting Options
Common options:
- Vercel
- Azure App Service
- Docker
- VPS with Node.js
- Static export for limited static-only sites
Next.js with ASP.NET Core
You can deploy separately:
next.school.com -> Next.js frontend
api.school.com -> ASP.NET Core Web API
Or behind one reverse proxy:
school.com -> Next.js frontend
school.com/api -> ASP.NET Core Web API
Production Checklist
- Run
npm run build - Configure production API URL
- Configure CORS in ASP.NET Core if browser calls API directly
- Use HTTPS
- Set secure cookie options
- Do not expose secrets with
NEXT_PUBLIC_ - Check pages on mobile
- Test login, logout, refresh, and protected pages
Do not deploy code that still calls localhost. Production users cannot reach your development machine.
After deployment, open the app in a private browser window and test the full login-to-save flow.
Interview Questions
It creates the optimized production build and catches route, rendering, and dependency errors before users see them.
The frontend must use the correct production API URL, and the backend must allow secure authenticated requests from the frontend origin.
Quick Definitions
- Deployment - The main Next.js concept explained in this lesson.
- App Router - The modern Next.js routing system based on the
appfolder. - Server/Client boundary - The decision of whether code runs on the server or in the browser.
- ASP.NET Core integration - Calling or proxying backend APIs from a Next.js frontend.
Common Mistakes
- Treating every component as a Client Component without a reason
- Forgetting environment variables differ between local and production
- Calling ASP.NET Core APIs from the browser without handling CORS
- Putting secrets in
NEXT_PUBLIC_variables - Skipping
npm run buildbefore deployment
Practice Task
Create a small Next.js example using Deployment. Keep it connected to a School Management System scenario.
Suggested practice:
- Create or update a route, layout, form, or data-fetching example.
- Use realistic student, teacher, attendance, or marks data.
- Connect the example to an ASP.NET Core-style API URL or route handler.
- Add one loading, empty, or error state where relevant.
- Explain what runs on the server and what runs in the browser.
Quick Revision
| Question | Answer |
|---|---|
| What is the main idea? | Use Deployment correctly in a Next.js App Router project. |
| Where is it used? | Pages, layouts, route handlers, forms, APIs, authentication, and deployment. |
| What should beginners watch carefully? | Server/client boundaries, environment variables, CORS, and production builds. |
| What is the best debugging habit? | Check terminal build output, browser console, network tab, and server logs. |
Use ChatGPT, Claude, or Copilot to go deeper on Deployment. Try these prompts:
"Explain Deployment with a Next.js and ASP.NET Core example""Give me 5 practice tasks for Deployment in a School Management app""Show common Next.js mistakes in Deployment and how to fix them""Quiz me on Deployment with interview-style questions"
💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.