Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

NX
Next.js
0/10 completed
Beginner
Why Next.js?Pages, layouts and routingLinks, images and fonts
Intermediate
Server and Client ComponentsFetching data and streamingRoute Handlers (API routes)Forms and Server Actions
Advanced
Caching and revalidationMetadata, SEO, errors and Proxy
Pro
Auth, deployment and production
Tracks / Next.js / Beginner

Why Next.js?

Next.js is a full-stack React framework. React gives you components; Next.js adds everything you need to ship a real product: routing, server rendering, data fetching, caching, API endpoints, image and font optimisation, SEO and deployment. Companies like Netflix, TikTok, Notion, Nike and OpenAI use it.

Prerequisites: the React track (components, props, state, effects). TypeScript helps too; all examples here use it.

This track follows Next.js 16 and the App Router, the modern way to build Next.js apps. Older tutorials that mention pages/, getServerSideProps or middleware.ts describe earlier versions.

What problems does it solve?

A plain React app (for example, built with Vite) is a single-page app (SPA): the browser downloads an empty HTML file plus a big JavaScript bundle, then renders everything on the user's device.

Problem with a plain SPA How Next.js helps
Blank page until the JS loads, which is slow on phones Server rendering: the HTML arrives ready to display
Search engines and link previews see an empty page Full HTML for every URL, plus a Metadata API
You must choose and wire up a router File-system routing: folders become URLs
Data fetching waterfalls from the browser Server Components fetch data on the server, close to the database
You need a separate backend for APIs and form posts Route Handlers and Server Actions live in the same project
Images and fonts slow the page down next/image and next/font optimise them automatically

The big idea: Server and Client Components

In the App Router, components are Server Components by default. They run on the server, can read databases and secrets directly, and send zero JavaScript to the browser. You opt specific interactive pieces into the browser with 'use client'.

tsx
// app/page.tsx — a Server Component (the default)
export default async function Page() {
  const products = await db.product.findMany();       // runs on the server, never in the browser
  return (
    <ul>
      {products.map((p) => <li key={p.id}>{p.name}</li>)}
    </ul>
  );
}

You'll go deep on this in the "Server and Client Components" lesson.

Create a project

You need Node.js 20.9 or newer.

bash
npx create-next-app@latest my-app --yes
cd my-app
npm run dev

Open http://localhost:3000. The --yes defaults give you TypeScript, Tailwind CSS, ESLint, the App Router and Turbopack (the fast default bundler), with the @/* import alias.

Command Does
npm run dev Development server with hot reload
npm run build Production build (type-checks, pre-renders what it can)
npm run start Runs the production build

Project structure

my-app/
├── app/                  ← your routes live here
│   ├── layout.tsx        ← root layout (required: <html> and <body>)
│   ├── page.tsx          ← the home page: /
│   ├── globals.css
│   └── about/
│       └── page.tsx      ← /about
├── public/               ← static files served as-is (/logo.png)
├── next.config.ts        ← framework configuration
├── tsconfig.json
└── package.json

Next.js vs other options

You want… Consider
A fast, SEO-friendly website or full-stack web app Next.js
A pure client-side app (dashboards behind login, internal tools) React + Vite (a simpler setup)
A content-heavy site with little interactivity Astro, or Next.js with static export
Alternatives in the same space Remix / React Router, Nuxt (Vue), SvelteKit

How this track works

Next.js runs on a server, so it can't run inside this page. Lessons show real project code to copy into your own app, and whenever a concept is plain React (such as an interactive Client Component), you'll get a live editor:

React · live preview
Preview

Practice

  1. Create a new app with npx create-next-app@latest my-app --yes.
  2. Edit app/page.tsx to show your name and a short bio. Watch it hot-reload.
  3. Run npm run build and look at the route summary it prints.
✎ Check your understanding

1.In the App Router, what kind of component is app/page.tsx by default?

2.Which folder defines your routes in a modern Next.js app?