Introduction to Next.js & Setup
Next.js is a flexible React framework built by Vercel. It extends React's capabilities by providing out-of-the-box support for Server-Side Rendering (SSR), Static Site Generation (SSG), dynamic image loading, routing, and backend API routes.
Standard React apps run client-side (Single Page Applications). This means the browser receives an empty HTML shell and uses JavaScript to build the view, which presents challenges for SEO crawlers and initial load performance.
Next.js solves these issues by rendering pages on the server first, delivering fully populated HTML pages to users instantly:
- Server-Side Rendering (SSR): Renders pages dynamically on each request.
- Static Site Generation (SSG): Pre-renders pages at build time for fast, CDN-ready loading.
- App Router: A modern file-system router with support for React Server Components.
Use the official Next.js CLI to initialize projects programmatically:
# 1. Initialize project scaffold
npx create-next-app@latest my-next-app
# 2. Select setup preferences:
# - TypeScript: Yes
# - ESLint: Yes
# - Tailwind CSS: Yes/No
# - Src Directory: Yes
# - App Router: Yes (Recommended)
# - Import Alias: @/*
# 3. Navigate into folder
cd my-next-app
# 4. Start local development server
npm run dev
The compiler runs the application locally on http://localhost:3000, watching files for updates.
pages/ routing model and the modern app/ router directory layout.