PresentationInteractive, narrated presentation of the section content.
ContentDetailed description of the section content.
Next.js Foundations π
In this module of our Full-Stack Development Course, we dive into Next.js, a powerful React framework that makes building fast, scalable, and SEO-friendly web applications easier than ever. Next.js goes beyond traditional React by offering server-side rendering (SSR), static site generation (SSG), and API routes, making it perfect for modern full-stack applications. Throughout this course, weβll progressively build a feature-rich blogging and content management system (CMS), learning how to fetch and mutate data, optimize performance, and secure our app with authentication. By the end, youβll have the essential skills to develop and deploy production-ready full-stack applications with Next.js! π
While we will use a project with some boilerplate, let's first take a look at how can you quickly start a new project with Next.js!
π¬ Starting from Scratch
If you want to create a clean new Next.js project, you can use the the following command, which will take you through series of questions to set up your project:
pnpx create-next-app@latestThis is what you can observe in the console:

Let's break it down!
1. What is your project named?
Example: my-test-project
This defines the name of your project folder. Whatever you enter here will be used as the directory name where your Next.js project is initialized.
π Effect: Creates a folder with this name and sets up a Next.js project inside it.
2. Would you like to use TypeScript? (No / Yes)
TypeScript is a superset of JavaScript that adds static typing, which helps catch errors at compile time rather than runtime.
β’ Yes β The project will be set up with TypeScript, and .ts/.tsx files will be used instead of .js/.jsx.
β’ No β The project will use plain JavaScript.
π Effect: If enabled, Next.js generates a tsconfig.json file and ensures TypeScript is properly configured.
3. Would you like to use ESLint? (No / Yes)
ESLint is a tool that helps enforce consistent coding style and catch common errors in JavaScript/TypeScript.
β’ Yes β A .eslintrc.json file is created with Next.js-specific linting rules.
β’ No β No linting setup is included.
π Effect: Helps maintain clean, readable, and bug-free code.
4. Would you like to use Tailwind CSS? (No / Yes)
Tailwind CSS is a utility-first CSS framework that allows for rapid UI styling using predefined classes.
β’ Yes β Tailwind CSS is installed and configured in tailwind.config.js.
β’ No β No CSS framework is included (you can add your own later). The initial project will use CSS modules
π Effect: If enabled, Next.js will automatically configure Tailwind CSS and PostCSS for styling.
5. Would you like your code inside a src/ directory? (No / Yes)
By default, Next.js places its files (pages/, components/, etc.) in the root directory. Enabling this option moves everything inside a src/ folder, making the root cleaner.
β’ Yes β The project structure will look like:
/my-test-project
βββ /src
β βββ /app (or /pages if using Pages Router)
β βββ /components
β βββ /stylesβ’ No β All project files remain at the root level.
π Effect: Organizes the code into a src/ folder for better project structure.
6. Would you like to use App Router? (recommended) (No / Yes)
Next.js has two routing strategies:
β’ Pages Router (Legacy) β Uses pages/ directory and file-based routing (e.g., pages/index.js).
β’ App Router (Recommended) β Uses app/ directory and introduces React Server Components for improved performance.
β’ Yes β The project is set up with App Router (app/ directory), supporting modern features like Server Actions and Streaming.
β’ No β Uses the older Pages Router (pages/ directory).
π Effect: Choosing App Router enables the latest Next.js features and optimizations.
7. Would you like to use Turbopack for next dev? (No / Yes)
Turbopack is Next.jsβ new Rust-based bundler that replaces Webpack for local development.
β’ Yes β Uses Turbopack, which provides faster startup and hot reloading times.
β’ No β Uses Webpack instead, which is more stable but slower.
π Effect: Choosing Turbopack makes development faster but is still in progress for some features.
8. Would you like to customize the import alias (@/* by default)? (No / Yes)
Next.js allows you to use import aliases to make importing files easier. By default, it uses:
import Button from '@/components/Button';Instead of:
import Button from '../../components/Button';β’ Yes β You can define a custom alias (e.g., ~/ instead of @/).
β’ No β Uses the default alias @/.
π Effect: Helps with cleaner imports, especially in large projects.
9. What import alias would you like configured? (Default: @/*)
If you chose βYesβ in the previous question, you can customize the alias.
β’ Example: Entering ~/ would let you do:
import Button from '~/components/Button';π Effect: Creates a tsconfig.json or jsconfig.json file with a custom alias setting.
Final Thoughts
These options let you tailor your Next.js project based on your preferences and needs. If youβre new to Next.js, using the recommended defaults (TypeScript, ESLint, Tailwind, App Router) is a great way to get started with modern best practices. π
Folder Structure
Next.js follows a convention-based folder structure that helps organize your project efficiently. Depending on whether you use the App Router (app/ directory) or Pages Router (pages/ directory), the structure will differ slightly. We will focus on app router only
Introduced in Next.js 13, the App Router uses React Server Components by default and enables powerful features like layouts, streaming, and server actions.
/my-next-app
βββ /app
β βββ /layout.tsx
β βββ /page.tsx
β βββ /dashboard
β β βββ /page.tsx
β β βββ /settings
β β β βββ /page.tsx
β βββ /api
β β βββ /route.ts
βββ /components
βββ /lib
βββ /public
βββ /styles
βββ /utils
βββ /node_modules
βββ .gitignore
βββ next.config.js
βββ package.json
βββ tsconfig.jsonKey Folders & Files in app/ Directory
β’ app/ β The main folder where pages, layouts, and API routes live.
β’ app/layout.tsx β Defines the root layout for the application (persists across all pages).
β’ app/page.tsx β The default home page (/).
β’ app/dashboard/page.tsx β A route for /dashboard.
β’ app/dashboard/settings/page.tsx β A nested route for /dashboard/settings.
β’ app/api/route.ts β Defines API endpoints (e.g., /api).
π App Router Benefits:
β
Uses React Server Components for better performance.
β
Supports nested layouts and loading states.
β
Enables streaming and server-side rendering (SSR) by default.
Running The Project
To run the Next.js project, please run the following command in the web project directory
pnpm runThis starts the development server at http://localhost:3000. If you are running multiple applications, the port may change and you may see the following message:
$ pnpm dev
> my-test-project@0.1.0 dev /Users/30031005/Github/WSU/FSD/my-test-project
> next dev --turbopack
β Port 3000 is in use, trying 3001 instead.
β² Next.js 15.1.7 (Turbopack)
- Local: http://localhost:3001
- Network: http://192.168.1.184:3001In this case I would open the project at the following URL: http://localhost:3001. When you open the browser at that URL, you should see the following:

Our (Monorepo) Project
In this chapter we will be working in the same code base from your second assignment. To learn how to set it up, please follow instructions here:.
We recommend you to create a new βLectureβ branch to play with exercises in the lecture.
No hints available.