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
| Idea | Meaning |
|---|---|
| App Router | File-based routing under app/ (default in new apps) |
| Pages Router | Legacy file-based routing under pages/ |
| RSC | React Server Components — default in App Router |
| SSR / SSG | Server-render on request vs pre-render at build |
| Turbopack | Fast bundler used by next dev (newer versions) |
Create a project:
npx create-next-app@latest my-app
cd my-app
npm run dev| Script | Purpose |
|---|---|
next dev | Local development server |
next build | Production build |
next start | Serve production build |
next lint | Run 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 buildbeforenext startserves a stale or missing build.