Getting Started With Next.js
By Raju Shrestha • Thu Jan 01 1970

Next.js is a React framework used for building modern full-stack web applications. It provides: Server-side rendering (SSR) Static site generation (SSG) API routes File-based routing SEO optimization and Fast performance.
1. What is Next.js?
Next.js is an open-source, full-stack web development framework built on top of the React JavaScript library. Created and maintained by Vercel, it provides developers with the architecture and tooling needed to build highly optimized, fast, and SEO-friendly web applications without complex manual configuration.
2. Why Use Next.js?
Next.js is used because it makes React applications faster, SEO-friendly, and easier to build and deploy.
Advantages:
- SEO Friendly – Pages are rendered on the server (SSR), making them easily readable by search engines.
- Fast Loading – Supports static generation (SSG) and optimized rendering for better performance.
- Built-in Routing – File-based routing system removes the need for complex routing setup.
- API Handling – You can create backend APIs inside the same project using API routes.
- Image Optimization – Automatically optimizes images for faster loading and better performance.
- Easy Deployment – Easily deploy on platforms like Vercel with minimal configuration.
3. Installation
Create a Next.js app using npm.
4. Project Structure
6. Creating Pages
Pages are created using page.js or page.jsx.
7. Layouts
Layouts are reusable UI wrappers.
8. Components
Reusable UI elements.
9. Client Components vs Server Components
Client Components
- Runs in the browser (client-side)
- Used for interactivity (useState, useEffect, events)
- Can access browser APIs like localStorage, window
- Marked with "use client" at the top
- Slightly heavier because JavaScript is sent to the browser
Server Components
- Runs on the server before sending HTML to the browser
- Used for static content and data fetching
- Better performance and SEO (less JS sent to client)
- Cannot use React hooks like useState or useEffect
- Default in Next.js App Router (no need to declare)
10. use client
Used to enable client-side interactivity.
11. Fetching Data
Fetch API is used in server components.
12. Dynamic Routes
Create dynamic pages using square brackets.
13. API Routes
Build backend APIs inside Next.js.
14. Middleware
Middleware runs before requests complete.
