Web BuildingIntermediate

Next.js Full-Stack Development

Build production-ready full-stack web apps with Next.js - SSR, SSG, API routes, and deployment.

7 hours
10 key concepts
3 in-depth sections
Official Docs

0 of 10 concepts completed (0%)

What You'll Learn

1.App Router File Structure

app/
  layout.tsx          → Root layout (HTML shell, applies to all routes)
  page.tsx            → Route: /
  loading.tsx         → Suspense loading state
  error.tsx           → Error boundary
  not-found.tsx       → 404 page
  about/page.tsx      → Route: /about
  blog/
    page.tsx          → Route: /blog
    [slug]/page.tsx   → Route: /blog/:slug (dynamic)
  api/
    users/route.ts    → API: GET /api/users, POST /api/users
    users/[id]/route.ts → API: GET/PATCH/DELETE /api/users/:id
tsx
// app/layout.tsx
export const metadata = {
  title: { default: "My App", template: "%s | My App" },
  description: "App description",

export default function RootLayout({ children }: { children: React.ReactNode }) { return (

{children}
); } ```

2.Server Components & Data Fetching

tsx
// Server Component runs on server, direct DB access, no useEffect

export async function generateStaticParams() { const posts = await db.post.findMany({ select: { slug: true } }); return posts.map(post => ({ slug: post.slug })); }

export async function generateMetadata({ params }) { const post = await db.post.findUnique({ where: { slug: params.slug } }); if (!post) return { title: "Not Found" }; return { title: post.title, description: post.excerpt, openGraph: { title: post.title, images: [post.coverImage] } }; }

export default async function BlogPost({ params }) { const post = await db.post.findUnique({ where: { slug: params.slug } }); if (!post) notFound(); return (

{post.title}

{post.content}

); }

// Client Component only when browser APIs or interactivity needed "use client"; import { useState } from "react";

export default function LikeButton({ postId, initialLikes }) { const [likes, setLikes] = useState(initialLikes); return ( ); } ```

3.API Routes & Server Actions

typescript
// app/api/users/route.ts

export async function GET(request: NextRequest) { const { searchParams } = new URL(request.url); const page = parseInt(searchParams.get("page") ?? "1"); const users = await db.user.findMany({ skip: (page - 1) * 20, take: 20 }); return NextResponse.json({ users }); }

export async function POST(request: NextRequest) { const body = await request.json(); const user = await db.user.create({ data: body }); return NextResponse.json(user, { status: 201 }); }

// Server Action (replaces API routes for mutations) "use server"; import { revalidatePath } from "next/cache";

export async function createPost(formData: FormData) { const title = formData.get("title") as string; await db.post.create({ data: { title } }); revalidatePath("/blog"); // invalidate the blog page cache }

// Use in a form function PostForm() { return (

); } ```

Code Example

// pages/index.js - SSG
export async function getStaticProps() {
  const res = await fetch("https://api.example.com/posts");
  const posts = await res.json();
  return { props: { posts }, revalidate: 60 };
}

export default function Home({ posts }) {
  return (
    <ul>
      {posts.map(post => (
        <li key={post.id}>{post.title}</li>
      ))}
    </ul>
  );
}

// pages/api/hello.js - API Route
export default function handler(req, res) {
  if (req.method === "POST") {
    res.status(201).json({ message: "Created" });
  } else {
    res.status(200).json({ name: "World" });
  }
}

Pro Tips

  • 1Start with Server Components (the default in App Router). Move to 'use client' only when you need browser APIs, event handlers, or useState/useEffect.
  • 2Image optimization with next/image is automatic it generates multiple sizes, converts to WebP, and lazy loads by default.
  • 3Use environment variables with NEXT_PUBLIC_ prefix for client-side values. Without the prefix, variables are server-only and won't be in browser bundles.
  • 4Server Actions replace API routes for form submissions they run on the server, support file uploads, and automatically invalidate caches.

Topics Covered

Next.jsSSRSSGFull-Stack

Continue Learning

Explore the official documentation and deepen your knowledge with real-world practice.

Explore the Full Portfolio

This is the complete portfolio of Sufi Khan Sulaiman, a technology leader specialising in B2B commerce and digital automation. Start from the Home page for the overview, then move through two decades of career experience across FLIR Systems, Lorex Technology, and 1c Platform, and the full catalogue of project case studies spanning headless commerce migrations, AI recommendation engines, and multi-channel fulfilment systems.

The skills and certifications page maps the technical and leadership capabilities behind the work, while the articles and the knowledge base break down the thinking into actionable frameworks. For hands-on learning, the tutorials and applications sections cover practical builds from front-end fundamentals to full-stack web apps.

For consulting engagement, the expertise page outlines service offerings, the ecommerce hub covers platform architecture and automation strategy, and the ecommerce guide (PDF) is a downloadable 55-page field manual. When you are ready to talk, the contact page is the direct line.