Next.js
I. Next.js Fundamentals
1. Introduction to Next.js
2. Next.js vs React
3. Project Setup
4. Folder Structure
5. Pages and Routing
6. Link and Navigation
7. Static Assets
8. CSS and Styling
II. Routing, Data & Rendering
9. Dynamic Routing
10. API Routes
11. Data Fetching Basics
12. getStaticProps
13. getServerSideProps
14. Incremental Static Regeneration
15. Rendering Strategies
16. Image Optimization
III. Advanced Next.js & Performance
17. Middleware
18. Authentication Basics
19. Authorization
20. Environment Variables
21. Performance Optimization
22. SEO with Next.js
23. Internationalization
24. Error Handling
IV. Projects, Deployment & Best Practices
25. Next.js Best Practices
26. Folder and Code Organization
27. Testing Next.js Apps
28. Security in Next.js
29. Next.js Interview Questions
30. Mini Project – Blog
31. Mini Project – Dashboard
32. Mini Project – Ecommerce
33. Mini Project – API Integration
34. Next.js Case Study
35. Real-World Use Cases
36. Project Planning
37. Final Project
38. Deployment with Vercel
39. Course Review
40. Career Roadmap
LESSON 3
Project Setup
Build your first Next.js project from scratch using create-next-app and configure it for NewsWave development.
Setting up a Next.js project feels different from creating a React app. Unlikecreate-react-app, Next.js includes everything you need for production right out of the box.
The official way to start a Next.js project is create-next-app. This CLI tool sets up your project with the latest features, proper TypeScript support, and sensible defaults that teams at companies like Vercel and GitHub use daily.
Creating Your First Next.js Project
Thecreate-next-app command generates a complete project structure. Think of it as scaffolding that gives you pages, routing, and build tools without any configuration.
# Create the NewsWave project
npx create-next-app@latest newswave
# Navigate into the project
cd newswave
# Start the development server
npm run devTerminal
$ npx create-next-app@latest newswave
✔ Would you like to use TypeScript? … No / Yes
✔ Would you like to use ESLint? … No / Yes
✔ Would you like to use Tailwind CSS? … No / Yes
✔ Would you like to use `src/` directory? … No / Yes
✔ Would you like to use App Router? … No / Yes
✔ Would you like to customize the default import alias? … No / Yes
✓ Creating a new Next.js app in /newswave
✓ Installing dependencies...
✓ Project created successfully!
What just happened?
The CLI created a complete Next.js project with routing, development server, and build tools configured. App Router gives you the new file-based routing system. TypeScript adds type safety for catching bugs early. Try this: Open the project in VS Code and explore the generated files.
Understanding the Setup Options
Each option during setup configures your project differently. The choices affect how you write code and deploy to production.TypeScript
Adds type checking to catch errors before they reach users. Recommended for teams and larger projects.
App Router
The new routing system with layouts, loading states, and React Server Components. Choose this for new projects.
Tailwind CSS
Utility-first CSS framework that speeds up styling. Popular at companies like GitHub and Shopify.
src/ Directory
Moves your app code into a src folder, keeping the root clean. Good for larger projects with many config files.
Running Your Development Server
Next.js includes a development server with hot reloading. Unlike plain React, changes appear instantly without losing component state.# Start development server on localhost:3000
npm run dev
# Alternative commands for different package managers
yarn dev
pnpm devlocalhost:3000 — NewsWave
What just happened?
Next.js started a development server with fast refresh enabled. Changes to your code trigger instant updates in the browser. The welcome page shows you're ready to start building. Try this: Edit the page.js file and watch changes appear immediately.
Project Structure Overview
Your new Next.js project contains several important files and folders. Each serves a specific purpose in the development and build process.📁 newswave/
📁 app/
📄 layout.js # Root layout component
📄 page.js # Home page component
📄 globals.css # Global styles
📁 public/
📄 next.svg # Static assets
📄 vercel.svg
📄 package.json # Dependencies and scripts
📄 next.config.js # Next.js configuration
📄 tailwind.config.js # Tailwind CSS config
app folder contains your application code. Unlike React Router, Next.js uses the file system for routing. Every page.js file becomes a route automatically.
Essential NPM Scripts
Next.js projects come with scripts for development, building, and deployment. Understanding these commands helps you work efficiently across different environments.Important Scripts
npm run dev starts development server with hot reloading. npm run build creates production bundle with optimizations. npm run start serves the built application. npm run lint checks code quality with ESLint rules.
{
"scripts": {
"dev": "next dev", // Development server
"build": "next build", // Production build
"start": "next start", // Serve built app
"lint": "next lint" // Code quality check
}
}Environment Setup and Configuration
Next.js works best with Node.js 18 or later. The framework uses modern JavaScript features and optimizations that require a recent Node version.Terminal
$ node --version
v18.17.0
$ npm --version
9.6.7
✓ Environment ready for Next.js development
Customizing Your NewsWave Project
The default Next.js template gives you a starting point. But NewsWave needs custom styling and structure for a news website.// app/page.js - Custom NewsWave homepage
export default function Home() {
return (
<main className="min-h-screen bg-gray-50">
<div className="container mx-auto px-4 py-8">
<h1 className="text-4xl font-bold text-gray-900 mb-8">
Welcome to NewsWave
</h1>
<p className="text-lg text-gray-600 mb-6">
Your source for breaking news and in-depth articles
</p>
<div className="grid md:grid-cols-3 gap-6">
{/* Article cards will go here */}
</div>
</div>
</main>
)
}localhost:3000 — NewsWave
What just happened?
You replaced the default Next.js homepage with a custom NewsWave design. Tailwind classes handle the responsive layout and styling. The component exports as default, making it the page component. Try this: Add more article cards or change the color scheme using different Tailwind classes.
Development Workflow Best Practices
Efficient Next.js development follows patterns that prevent common mistakes. Hot reloading works best when you structure components properly and avoid certain patterns.Hot Reloading Tips
Fast Refresh preserves component state between changes. Export components as default functions for best results. Avoid anonymous functions in exports. Always restart the dev server after changing next.config.js or environment variables.
Quiz
1. The NewsWave team wants to create a new Next.js project. Which command should they use?
2. After creating the NewsWave project, which command starts the development server with hot reloading?
3. What is the main difference between App Router and Pages Router in Next.js?
Up Next: Folder Structure
Explore how Next.js organizes files and folders to create routes, layouts, and components automatically.