Next.js 14 menjadi standar baru untuk aplikasi React yang server‑side rendered, dengan App Router, Server Actions, dan dukungan streaming. Tutorial ini membimbing Anda langkah demi langkah mulai dari instalasi, konfigurasi, contoh kode, hingga best practice untuk produksi.

1. Persiapan Lingkungan

Sebelum memulai, pastikan sistem Anda sudah terpasang:

  • Node.js 20.10+ (LTS) – gunakan nvm untuk mengelola versi.
  • Git terbaru.
  • Editor kode – VS Code dengan ekstensi ESLint, Prettier, dan Tailwind CSS IntelliSense.

Install Node.js:

nvm install 20 && nvm use 20

2. Membuat Proyek Next.js 14 Baru

Gunakan create-next-app dengan flag --app untuk mengaktifkan App Router secara default.

npx create-next-app@latest my-next14-app --typescript --app
cd my-next14-app

Periksa versi:

npm list next

Anda akan melihat next@14.x.x.

3. Struktur Direktori Baru

App Router menggantikan pages dengan app folder. Struktur penting:

  • app/ – layout, route.tsx, dan server actions.
  • components/ – UI reusable.
  • lib/ – helper, API client.
  • styles/ – Tailwind atau CSS modules.

4. Instalasi Dependensi Utama

# UI & styling
npm i tailwindcss@latest postcss@latest autoprefixer@latest
npx tailwindcss init -p

# State management (optional)
npm i zustand

# Validation & schema
npm i zod

# Testing
npm i -D jest @testing-library/react @testing-library/jest-dom

Konfigurasi Tailwind

Edit tailwind.config.js:

module.exports = {
  content: ["./app/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
  theme: { extend: {} },
  plugins: [],
};

Tambahkan direktif ke globals.css:

@tailwind base;
@tailwind components;
@tailwind utilities;

5. Membuat Layout Global dengan Server Component

// app/layout.tsx
import './globals.css';
import type { Metadata } from 'next';

export const metadata: Metadata = {
  title: 'Next.js 14 Demo',
  description: 'Demo App Router & Server Actions',
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    
      
        
🚀 Next.js 14
{children}
© 2026
); }

6. Menambahkan Route dengan Server Actions

Server Actions memungkinkan Anda memanggil fungsi server langsung dari UI tanpa API terpisah.

// app/contact/page.tsx
"use server";
import { z } from 'zod';
import { redirect } from 'next/navigation';

const schema = z.object({
  name: z.string().min(2),
  email: z.string().email(),
  message: z.string().min(10),
});

export async function submitContact(formData: FormData) {
  const result = schema.safeParse(Object.fromEntries(formData));
  if (!result.success) {
    // throw will be caught by the client component
    throw new Error('Validation failed');
  }
  // Simulasi penyimpanan ke DB (replace with Prisma/Firebase)
  console.log('Contact saved', result.data);
  redirect('/thank-you');
}

export default function ContactPage() {
  return (