Introduction to Next.js 16 & Project Setup
What Next.js is, why teams choose it over plain React, every rendering strategy explained (CSR, SSR, SSG, ISR, Streaming, PPR), what changed in Next.js 16, and a step-by-step project setup with a full tour of the folder structure.
What is Next.js?
Next.js is a full-stack React framework built by Vercel. React gives you a way to build user interfaces out of components; Next.js gives you everything else a real production application needs around those components.
- Routing โ every folder inside
app/becomes a URL automatically. No router library to configure. - Rendering on the server โ pages can be rendered to HTML on the server, at build time, or streamed in pieces, instead of shipping an empty
<div id="root">to the browser. - Data fetching โ components can be
asyncand read from a database or API directly. - Backend code โ Server Actions and Route Handlers let you write APIs and form handlers in the same project.
- Optimizations โ images, fonts, scripts, code splitting and caching are handled by built-in components and the compiler.
Simple definition: React is the engine; Next.js is the complete car built around it โ routing, rendering, data, backend and performance included.
Why Next.js? Problems It Solves Over Plain React
A plain React app built with Vite is a Single Page Application (SPA). The server sends an almost empty HTML file plus a large JavaScript bundle, and the browser builds the page. That works, but it creates real problems at scale:
- SEO & social previews โ search engines and link-preview bots see an empty page until JavaScript runs. Next.js sends fully rendered HTML.
- Slow first load โ users stare at a blank screen while the bundle downloads and executes. Server rendering shows content immediately.
- Data waterfalls โ component mounts โ
useEffectโ fetch โ render child โ fetch again. Server Components fetch data on the server, close to the database. - Too much JavaScript โ every component ships to the browser. In Next.js, Server Components ship zero client JavaScript.
- Glue code โ routing, code splitting, API servers, image optimization and environment handling all need separate libraries in a SPA. Next.js includes them.
Who uses it: Netflix, TikTok, Twitch, Notion, Hulu, Nike, OpenAI, Anthropic, and this very portfolio โ the notes you are reading are rendered by Next.js.
Rendering Strategies Explained (CSR, SSR, SSG, ISR, Streaming, PPR)
Understanding where and when HTML is produced is the single most important concept in Next.js.
- CSR โ Client-Side Rendering: the browser downloads JavaScript and renders everything. Used for highly interactive widgets inside a page.
- SSR โ Server-Side Rendering: HTML is generated on the server for every request. Always fresh, good for personalized pages (dashboards, carts).
- SSG โ Static Site Generation: HTML is generated once at build time and served from a CDN. Fastest possible, ideal for blogs, docs and marketing pages.
- ISR โ Incremental Static Regeneration: static pages that regenerate in the background after a time interval or on demand. Static speed with fresh-enough data.
- Streaming: the server sends the page in chunks. The shell appears instantly and slow sections stream in later, using React
<Suspense>. - PPR โ Partial Prerendering: one page mixes a static shell (prerendered) with dynamic holes that stream at request time. In Next.js 16 this is the default model when you enable Cache Components (Lecture 7).
Key idea: in Next.js you rarely pick one mode for the whole app. Each route โ and even each component โ gets the strategy it needs.
App Router vs. Pages Router
Next.js has two routers. New projects should use the App Router.
- App Router (
app/directory) โ built on React Server Components. Supports nested layouts, streaming, Server Actions, the new caching model and every Next.js 16 feature. This entire course uses it. - Pages Router (
pages/directory) โ the original router (Next.js 1โ12 era) usinggetServerSidePropsandgetStaticProps. Still supported for existing apps, but it receives no new architecture features.
Both routers can live in one project during a migration, but a route must exist in only one of them.
What's New in Next.js 16
Next.js 16 is a major release. If you learned Next.js from older tutorials, these are the changes you must know:
- Turbopack is the default bundler for both
next devandnext buildโ no more--turbopackflag. Use--webpackto opt out. - Cache Components โ enable
cacheComponents: trueto get the"use cache"directive and Partial Prerendering as the default rendering model. middlewarerenamed toproxyโ the file is nowproxy.jsand the exported function isproxy. It runs on the Node.js runtime.- Async Request APIs only โ
params,searchParams,cookies(),headers()anddraftMode()must be awaited. Synchronous access is removed. - New caching APIs โ
updateTag()(read-your-writes),refresh(), andrevalidateTag(tag, profile)now needs a second argument.cacheLifeandcacheTagare stable. - React 19.2 โ View Transitions,
useEffectEventand<Activity>. - React Compiler support is stable via
reactCompiler: true(opt-in). - Faster navigation โ layouts are deduplicated during prefetching and only missing parts are fetched.
- Removed: AMP, the
next lintcommand (use ESLint directly), andserverRuntimeConfig/publicRuntimeConfig(use environment variables). - Parallel routes now require an explicit
default.jsin every slot.
Prerequisites & System Requirements
Before starting, make sure your machine meets the Next.js 16 minimums:
- Node.js 20.9 or newer (Node 18 is no longer supported). Check with
node -v. - TypeScript 5.1+ if you use TypeScript.
- Browsers: Chrome/Edge/Firefox 111+, Safari 16.4+.
Knowledge you should have: modern JavaScript (arrow functions, destructuring, modules, async/await, promises) and React basics (components, props, state, hooks). If you need a refresher, complete the React track on this site first.
Creating Your First Next.js Project
The official CLI create-next-app scaffolds a project with sensible defaults. Run it with npx so you always get the latest version.
The CLI asks a few questions. Recommended answers for this course:
- TypeScript? Your choice โ examples here use JavaScript so beginners can follow; everything works the same in TypeScript.
- ESLint? Yes.
- Tailwind CSS? Optional (covered in Lecture 10).
src/directory? Optional โ it only movesapp/insidesrc/.- App Router? Yes (required for this course).
- Import alias? Keep the default
@/*, which lets you writeimport Navbar from "@/components/Navbar"instead of long relative paths.
# Create a new project (interactive prompts)
npx create-next-app@latest my-next-app
# Or skip the prompts with the recommended defaults
npx create-next-app@latest my-next-app --yes
# Move into the project and start the dev server
cd my-next-app
npm run dev
# Open http://localhost:3000 in your browserProject Structure Tour
A fresh project looks like this. Knowing what each item does saves hours of confusion later:
app/โ the App Router. Folders become routes; special files (page.js,layout.js, ...) define UI.app/layout.jsโ the root layout, required. It must render<html>and<body>and wraps every page.app/page.jsโ the home page at/.app/globals.cssโ global styles imported once in the root layout.public/โ static files served from the site root:public/logo.pngis available at/logo.png.next.config.js/.mjs/.tsโ framework configuration.package.jsonโ dependencies and thedev,build,startscripts.jsconfig.json/tsconfig.jsonโ editor settings and the@/*path alias..next/โ build output generated by Next.js. Never edit or commit it. In Next.js 16,next devwrites to.next/devso dev and build can run at the same time..env*files โ environment variables (Lecture 12). Keep them out of git.
my-next-app/
โโโ app/
โ โโโ layout.js # Root layout (html + body) โ required
โ โโโ page.js # Home page โ /
โ โโโ globals.css # Global styles
โ โโโ favicon.ico
โโโ public/ # Static assets โ served at /
โ โโโ next.svg
โโโ next.config.mjs # Next.js configuration
โโโ jsconfig.json # "@/*" import alias
โโโ package.json
โโโ .gitignore # Already ignores .next/, node_modules/, .env*Special File Conventions at a Glance
Inside app/, file names have meaning. You will learn each in detail, but here is the map:
page.jsโ the UI for a route; makes the folder publicly accessible.layout.jsโ shared UI that wraps child routes and keeps state between navigations.template.jsโ like a layout, but re-mounts on every navigation.loading.jsโ instant loading UI shown while a route segment loads (Suspense).error.jsโ error boundary for a segment.global-error.jsโ error boundary for the root layout.not-found.jsโ UI fornotFound()and unmatched URLs.route.jsโ an API endpoint (Route Handler) instead of a page.default.jsโ fallback UI for parallel route slots.
Any other file (components, utils, styles) inside app/ is not routable unless it is named page.js or route.js, so you can safely colocate code next to the routes that use it.
Development, Build & Production Scripts
Three scripts cover the whole lifecycle:
npm run devโ starts the development server with Turbopack, Fast Refresh (instant updates on save) and detailed error overlays.npm run buildโ creates an optimized production build: prerenders static routes, bundles and minifies code, and prints a route summary showing which routes are static and which are dynamic.npm run startโ serves the production build. Always test withbuild+startbefore deploying; dev mode is intentionally slower and behaves differently (no prefetching, extra checks).
Note: next build no longer runs the linter in Next.js 16. Run npx eslint . (or your lint script) separately in CI.
// package.json (comments added for explanation โ real JSON cannot contain comments)
{
"scripts": {
"dev": "next dev", // Turbopack by default in Next.js 16
"build": "next build", // Production build (also Turbopack)
"start": "next start", // Serve the production build
"lint": "eslint ." // next lint was removed in v16
}
}
// Need Webpack for a legacy plugin? Opt out per command:
// "build": "next build --webpack"Hands-On: Your First Layout and Pages
Let's replace the starter files with our own. The root layout renders a navigation bar on every page; two pages render inside it through the children prop.
Notice three things:
metadatais a plain exported object โ Next.js turns it into<title>and<meta>tags (Lecture 11).- Pages are Server Components by default, so they can be
asyncand no JavaScript is shipped for them. <Link>fromnext/linkgives instant client-side navigation instead of full page reloads.
// app/layout.js โ Root layout (required)
import Link from "next/link";
import "./globals.css";
export const metadata = {
title: "My Next.js App",
description: "Learning Next.js 16 step by step",
};
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<nav style={{ display: "flex", gap: "1rem", padding: "1rem" }}>
<Link href="/">Home</Link>
<Link href="/about">About</Link>
</nav>
<main style={{ padding: "1rem" }}>{children}</main>
</body>
</html>
);
}
// app/page.js โ Home page โ /
export default function HomePage() {
return <h1>Welcome to Next.js 16 ๐</h1>;
}
// app/about/page.js โ About page โ /about
export default async function AboutPage() {
// Server Components can be async and fetch data directly
const res = await fetch("https://api.github.com/repos/vercel/next.js");
const repo = await res.json();
return (
<section>
<h1>About</h1>
<p>Next.js has {repo.stargazers_count.toLocaleString()} GitHub stars.</p>
</section>
);
}next.config.js Essentials
The config file controls framework behaviour. You will add to it throughout the course; the most common options are:
images.remotePatternsโ allownext/imageto optimize images from external domains (images.domainsis deprecated).redirects()/rewrites()/headers()โ URL rules applied before routing.cacheComponentsโ enables"use cache"and Partial Prerendering.reactCompilerโ automatic memoization with the React Compiler.turbopackโ Turbopack options (top-level in v16, no longer underexperimental).output: "standalone"โ minimal server bundle for Docker deployments (Lecture 13).
// next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
{ protocol: "https", hostname: "images.unsplash.com" },
],
},
async redirects() {
return [
{ source: "/blog/:slug", destination: "/notes/:slug", permanent: true },
];
},
// Opt-in features (covered later in the course)
// cacheComponents: true,
// reactCompiler: true,
};
export default nextConfig;Summary & What's Next
- Next.js is a full-stack React framework: routing, server rendering, data fetching, backend code and optimizations in one tool.
- It solves SPA problems โ SEO, slow first load, data waterfalls and oversized bundles.
- Each route can use the rendering strategy it needs: static, dynamic, ISR, streaming or partial prerendering.
- Always use the App Router for new projects.
- Next.js 16 brings Turbopack by default, Cache Components,
proxyinstead ofmiddleware, and async-only request APIs. create-next-appscaffolds a project;dev,buildandstartcover the lifecycle.
Next lecture: file-system routing in depth โ pages, nested layouts, linking, programmatic navigation, route groups and private folders.