199 Next.js interview questions and answers

Next.js interview questions on the App Router, Server Components, Server Actions, caching and revalidation, routing, rendering strategies, middleware and performance.

Easy70 easy Next.js questions

  1. 1What is Next.js and how does it differ from React?
  2. 2What are the main features of Next.js?
  3. 4What is the Pages Router in Next.js?
  4. 6How does file-based routing work in Next.js?
  5. 7What is the _app.js file and what is it used for?
  6. 9What is the public folder in Next.js used for?
  7. 10How do you create a 404 page in Next.js?
  8. 11What is the next.config.js file?
  9. 12How do you set environment variables in Next.js?
  10. 13What is the NEXT_PUBLIC prefix used for in environment variables?
  11. 14How does Next.js handle CSS imports?
  12. 15What are CSS Modules in Next.js?
  13. 16How do you create dynamic routes in Next.js?
  14. 18What is the difference between [slug] and [...slug]?
  15. 20How do you use the useRouter hook?
  16. 21What is the difference between router.push and router.replace?
  17. 22How do you programmatically navigate in Next.js?
  18. 25What is the Link component and how does it work?
  19. 27What are route groups in the App Router?
  20. 31What is the layout.js file in the App Router?
  21. 32What is the page.js file in the App Router?
  22. 34What is the loading.js file used for?
  23. 36What is getStaticProps and when do you use it?
  24. 37What is getServerSideProps and when do you use it?
  25. 43How do you fetch data in Server Components (App Router)?
  26. 52How do you pass data from Server Components to Client Components?
  27. 56How do you handle loading states during data fetching?
  28. 62What is the difference between Server and Client Components?
  29. 63When should you use the 'use client' directive?
  30. 64Can Server Components use hooks?
  31. 70Can you import a Client Component inside a Server Component?
  32. 81How do you create an API route in Next.js (Pages Router)?
  33. 82What HTTP methods are supported in API routes?
  34. 83How do you handle different HTTP methods in a single API route?
  35. 84How do you create API routes in the App Router (Route Handlers)?
  36. 85What is the route.js file in the App Router?
  37. 86How do you read request body in Route Handlers?
  38. 87How do you return JSON from a Route Handler?
  39. 91How do you create dynamic API routes?
  40. 101What is middleware in Next.js?
  41. 102Where do you define middleware in Next.js?
  42. 104How do you redirect users in middleware?
  43. 106How do you access cookies in middleware?
  44. 114How do you protect pages using getServerSideProps?
  45. 118What is the useSession hook in NextAuth?
  46. 121What is the Next.js Image component?
  47. 122What are the benefits of using next/image?
  48. 123What is lazy loading and how does Next.js handle it?
  49. 124What is the priority prop in next/image?
  50. 125How do you configure remote image domains in Next.js?
  51. 126What is next/font and how does it optimize fonts?
  52. 129What is code splitting in Next.js?
  53. 130How does Next.js handle dynamic imports?
  54. 132What is the purpose of the next/dynamic function?
  55. 146How do you use Tailwind CSS in Next.js?
  56. 149How do you use Sass in Next.js?
  57. 150What is the globals.css file?
  58. 151How do you use CSS variables in Next.js?
  59. 164How does Next.js handle redirects in next.config.js?
  60. 165How does Next.js handle rewrites?
  61. 166What are headers in next.config.js?
  62. 168What is the next/headers module?
  63. 169How do you read cookies on the server in the App Router?
  64. 173How do you configure path aliases in Next.js?
  65. 176What is the difference between next build and next dev?
  66. 187What is the Next.js error overlay?
  67. 188How do you use React DevTools with Next.js?
  68. 191What is the Metadata API in the App Router?
  69. 194How do you implement a sitemap in Next.js?
  70. 195How do you implement a robots.txt in Next.js?

Medium106 medium Next.js questions

  1. 3What is the difference between CSR, SSR, SSG, and ISR?
  2. 5What is the App Router introduced in Next.js 13?
  3. 8What is the _document.js file and when should you use it?
  4. 17What are catch-all routes and how do you define them?
  5. 19What is an optional catch-all route [[...slug]]?
  6. 23What is shallow routing?
  7. 24How do you handle query parameters in Next.js?
  8. 26How does prefetching work with the Link component?
  9. 30How do you create nested layouts in the App Router?
  10. 33What is the template.js file and how does it differ from layout.js?
  11. 35What is the error.js file used for?
  12. 38What is getStaticPaths and when is it required?
  13. 40What is Incremental Static Regeneration (ISR)?
  14. 41How do you set a revalidation time in ISR?
  15. 42What is on-demand revalidation?
  16. 44What is the fetch API extension in Next.js?
  17. 45How do you cache fetch requests in Next.js?
  18. 46What is cache: 'no-store' used for in fetch?
  19. 47What is next: { revalidate } in the fetch options?
  20. 48How do you use React.cache in Next.js?
  21. 49What is the difference between static and dynamic rendering in the App Router?
  22. 50What makes a route dynamic in the App Router?
  23. 51What is the unstable_noStore function?
  24. 53Can Client Components fetch data directly?
  25. 54What is SWR and how is it used with Next.js?
  26. 55What is React Query and how does it integrate with Next.js?
  27. 57What is Suspense and how does it work in Next.js?
  28. 59What are Server Actions in Next.js?
  29. 60How do you use use server directive?
  30. 61What are React Server Components (RSC)?
  31. 65Can Client Components be async?
  32. 66How do you use context in the App Router?
  33. 68How do you pass server data as props to Client Components?
  34. 69What are the limitations of Server Components?
  35. 71Can you import a Server Component inside a Client Component?
  36. 73What are third-party libraries' compatibility issues with RSC?
  37. 74How do you handle browser-only APIs in Server Components?
  38. 75What is the difference between use server and use client?
  39. 76How do you share state between Server and Client Components?
  40. 77What is serialization and why does it matter when passing props?
  41. 78What is a Shared Component?
  42. 79How does React handle hydration in Next.js?
  43. 80What are hydration errors and how do you fix them?
  44. 88How do you handle cookies in Route Handlers?
  45. 89How do you handle headers in Route Handlers?
  46. 90What is the NextRequest and NextResponse API?
  47. 92How do you protect API routes with authentication?
  48. 93What is CORS and how do you configure it in Next.js?
  49. 94How do you handle file uploads in Next.js?
  50. 96What are Edge API Routes?
  51. 97What is the difference between Node.js and Edge runtime?
  52. 98How do you add middleware to API routes?
  53. 100How do you handle errors in API routes?
  54. 103What is the matcher config in middleware?
  55. 105How do you rewrite URLs in middleware?
  56. 107How do you protect routes using middleware?
  57. 108What is the execution order of middleware?
  58. 109What runtime does middleware run on?
  59. 110What are the limitations of Next.js middleware?
  60. 111How do you implement authentication in Next.js?
  61. 112What is NextAuth.js (Auth.js)?
  62. 113How do you set up session management in Next.js?
  63. 115How do you protect routes using middleware?
  64. 117How do you handle OAuth providers with NextAuth?
  65. 119How do you access the session in Server Components?
  66. 127What is automatic font optimization in Next.js?
  67. 128What is next/script and what are its loading strategies?
  68. 131What is React.lazy and how does it work with Next.js?
  69. 133How do you disable SSR for a component using next/dynamic?
  70. 134What is tree shaking and does Next.js support it?
  71. 135What is bundle analysis in Next.js and how do you do it?
  72. 136How does Next.js optimize third-party scripts?
  73. 137What is the Turbopack bundler in Next.js?
  74. 138What are the performance metrics Next.js focuses on (Core Web Vitals)?
  75. 143How do you opt out of caching in the App Router?
  76. 144What is revalidatePath and revalidateTag?
  77. 145How do you use cache tags in Next.js?
  78. 147How do you use styled-components in Next.js?
  79. 152What is the recommended styling approach for Server Components?
  80. 153How do you handle dark mode in Next.js?
  81. 154How do you use PostCSS in Next.js?
  82. 158What are Server Actions and how do they differ from API routes?
  83. 159How do you handle form submissions with Server Actions?
  84. 160What is useFormState and useFormStatus?
  85. 162What is the after function in Next.js?
  86. 163What is the forbidden and unauthorized function in Next.js 15?
  87. 167How do you configure internationalization (i18n) in Next.js?
  88. 170What is the draftMode API in Next.js?
  89. 171What is Preview Mode in the Pages Router?
  90. 174What is the output option in next.config.js (standalone, export)?
  91. 175How does next export work and what are its limitations?
  92. 177How do you deploy Next.js on Vercel vs self-hosted?
  93. 178How do you configure custom server in Next.js?
  94. 179What is edge rendering and when should you use it?
  95. 180How do you test Next.js applications?
  96. 181What is the recommended testing setup for Next.js (Jest + Testing Library)?
  97. 182How do you mock useRouter in tests?
  98. 183How do you write end-to-end tests with Playwright or Cypress for Next.js?
  99. 185How do you test API routes in Next.js?
  100. 186How do you debug a Next.js application?
  101. 190How do you implement SEO in Next.js?
  102. 192How do you generate dynamic metadata (Open Graph, Twitter cards)?
  103. 193What is generateStaticParams and how does it replace getStaticPaths?
  104. 196What are the key differences between Next.js 13, 14, and 15?
  105. 198What are common pitfalls when using the App Router?
  106. 199How does Next.js compare to Remix, Nuxt, or Astro?

Hard23 hard Next.js questions

  1. 28What are parallel routes in Next.js?
  2. 29What are intercepting routes?
  3. 39What is the difference between fallback: false, true, and blocking in getStaticPaths?
  4. 58How do you stream data with Suspense boundaries?
  5. 67What is the component tree boundary between server and client?
  6. 72What is the "children pattern" for mixing server and client components?
  7. 95How do you stream responses from API routes?
  8. 99How do you rate-limit API routes in Next.js?
  9. 116How do you implement JWT-based auth in Next.js?
  10. 120How do you implement role-based access control (RBAC) in Next.js?
  11. 139How do you implement caching strategies in Next.js?
  12. 140What is the full route cache in the App Router?
  13. 141What is the router cache in the App Router?
  14. 142What is the data cache in the App Router?
  15. 148What are the challenges of CSS-in-JS in the App Router?
  16. 155What is the order of CSS precedence in Next.js?
  17. 156What is the React Server Component payload (RSC payload)?
  18. 157How does Next.js handle partial prerendering (PPR)?
  19. 161How do you handle optimistic updates with Server Actions?
  20. 172How do you implement a monorepo with Next.js?
  21. 184How do you test Server Components?
  22. 189How do you analyze and fix slow build times in Next.js?
  23. 197How do you migrate from the Pages Router to the App Router?