Review, Practice & Interview Prep
Review, Practice & Interview Prep
Section titled “Review, Practice & Interview Prep”Phase Summary
Section titled “Phase Summary”Phase 7 covered production-deploying and maintaining Next.js applications:
Deployment: Vercel (automatic, preview deployments), self-hosting (Docker, Nginx), environment variables, and a deployment checklist.
Production Build: Build process, bundle analysis with @next/bundle-analyzer, static assets, and production best practices.
Monitoring: Logging with structured logs, error monitoring with Sentry, analytics with Google Analytics, and performance monitoring (Core Web Vitals).
Testing: Unit tests (Vitest, Testing Library), integration tests for API routes and Server Actions, E2E tests with Playwright, and testing best practices.
Maintenance: Updating dependencies safely, upgrading Next.js, applying security updates, and a maintenance checklist.
Practice Tasks
Section titled “Practice Tasks”Deployment
Section titled “Deployment”- Deploy a Next.js app to Vercel from a GitHub repository
- Set up a custom domain with automatic SSL
- Create a
vercel.jsonwith custom region settings - Configure environment variables for development, preview, and production
Production Build
Section titled “Production Build”- Run
ANALYZE=true npm run buildand identify the largest dependencies - Replace a large library (e.g., Moment.js) with a tree-shakeable alternative
- Enable
output: 'standalone'and compare the output size
Monitoring
Section titled “Monitoring”- Set up Sentry error monitoring on both client and server
- Configure structured logging in a Server Action
- Track a custom event (button click, form submission) with analytics
Testing
Section titled “Testing”- Write a unit test for a utility function
- Write an integration test for an API route
- Write an E2E test for the login flow with Playwright
Maintenance
Section titled “Maintenance”- Run
npm auditand fix vulnerabilities - Check for outdated dependencies with
npm outdated - Set up Dependabot for automated security updates
Common Interview Questions
Section titled “Common Interview Questions”Q: How do you deploy a Next.js app to production?
A: The recommended way is Vercel — connect your Git repository, and deployment is automatic. For self-hosting, use output: 'standalone' and run next start behind a reverse proxy like Nginx.
Q: What’s the difference between static and dynamic rendering? A: Static rendering generates HTML at build time (faster, cached). Dynamic rendering generates HTML on each request (slower but always fresh). Next.js automatically chooses based on the features used in each page.
Q: How do you monitor errors in a Next.js production app?
A: Use Sentry (@sentry/nextjs) for both client and server error monitoring. Configure API route logging with structured logs. Use Vercel Analytics or Google Analytics for performance monitoring.
Q: How do you write tests for Next.js? A: Use Vitest with Testing Library for unit and integration tests. Use Playwright for E2E tests. Test API routes, Server Actions, and components. Run tests in CI on every commit.
Q: How do you handle environment variables in production?
A: Set them in your deployment platform’s dashboard (Vercel, Docker). Use .env.local for local development (not committed). Never commit secrets to version control. Use NEXT_PUBLIC_ prefix for client-accessible variables.
Q: What is the deployment checklist before going live? A: Verify the build succeeds, all environment variables are set, security headers are configured, error monitoring is active, SSL is enabled, and there’s a rollback plan.