Code Reference

Getting Started with Next.js

Next.js · Reference cheat sheet

Getting Started with Next.js

Next.js · Reference cheat sheet


📋 Overview

Next.js is a React framework for full-stack web apps. It adds routing, rendering modes, image optimization, and deployment conventions on top of React.

🔧 Core concepts

IdeaMeaning
App RouterFile-based routing under app/ (default in new apps)
Pages RouterLegacy file-based routing under pages/
RSCReact Server Components — default in App Router
SSR / SSGServer-render on request vs pre-render at build
TurbopackFast bundler used by next dev (newer versions)

Create a project:

npx create-next-app@latest my-app
cd my-app
npm run dev
ScriptPurpose
next devLocal development server
next buildProduction build
next startServe production build
next lintRun ESLint

💡 Examples

Minimal app/page.tsx:

export default function Home() {
  return <h1>Hello Next.js</h1>;
}

package.json scripts:

{
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  }
}

Check version:

npx next --version

⚠️ Pitfalls

  • Mixing App Router (app/) and Pages Router (pages/) without a clear plan causes confusion.
  • Client hooks (useState, useEffect) need 'use client' in App Router.
  • Forgetting next build before next start serves a stale or missing build.

On this page