Next js

πŸ”° Module 1: Introduction & Setup of Next Js

Mastering Next.js 14+ with TypeScript & src/ Structure

Welcome to the first step of your journey in mastering Next.js 14+ β€” the most advanced and flexible React framework out there. In this module, we’ll cover what makes Next.js 14 so powerful, how it compares to other tools, and how to set up a modern project using TypeScript and the new src/ directory layout.


πŸš€ What is Next.js 14 β€” and Why Should You Care?

Next.js 14 is a React framework built by Vercel that enables you to create full-stack web apps with:

  • Server components and client components
  • Server-side rendering (SSR), static generation (SSG), and incremental rendering (ISR)
  • API routes and server actions
  • File-based routing with App Router
  • Automatic image optimization, metadata handling, and much more

It replaces the traditional β€œfrontend-only” mindset with a full-stack developer experience, without having to leave the React ecosystem.


βš–οΈ Next.js vs CRA vs Gatsby

Here’s how Next.js 14 compares to Create React App (CRA) and Gatsby:

Feature Next.js 14 Create React App (CRA) Gatsby
Server-side rendering βœ… Built-in ❌ Not supported ⚠️ Limited
API routes βœ… Built-in ❌ External only ❌ Needs plugins
File-based routing βœ… With App Router ❌ Manual setup βœ… Pages directory
Performance ⚑ Optimized SSR/SSG 🐒 Basic SPA only ⚑ SSG only
Backend integration βœ… Native (API/DB) ❌ Requires external ⚠️ Plugin-based
Recommended use case Universal web apps Frontend-only apps Static sites, blogs

βœ… Verdict: If you’re serious about building production-ready apps with modern architecture, Next.js 14 is the clear winner.


πŸ› οΈ Installing the Prerequisites

βœ… Install Node.js

Download and install the LTS version from https://nodejs.org. This includes:

  • node: JavaScript runtime
  • npm: Node package manager

To check versions:

node -v
npm -v

βœ… Install VS Code

VS Code is the preferred editor for React and Next.js developers.

Download it from https://code.visualstudio.com and install these extensions:

  • ESLint
  • Prettier
  • Tailwind CSS IntelliSense
  • TypeScript React Support

🧱 Creating Your Next.js 14 Project with TypeScript and src/

Use the official command-line tool to scaffold your app:

npx create-next-app@latest

Answer the prompts as follows:

  • Project Name: next14-ts-app (or any name you like)
  • Use TypeScript? βœ… Yes
  • Use App Router? βœ… Yes
  • Use Tailwind CSS? βœ… Yes
  • Use src/ directory? βœ… Yes
  • Import alias? πŸ‘‰ Yes (@/* is recommended)
  • Use ESLint/Prettier? βœ… Yes (Optional but useful)

Once done:

cd next14-ts-app
npm run dev

Visit http://localhost:3000 and boom β€” your app is live!


πŸ—‚οΈ Project Structure with src/

After choosing the src/ layout, your project structure will look like this:

next14-ts-app/
β”œβ”€β”€ public/                β†’ Static files (images, favicon)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/               β†’ App Router pages, layouts, templates
β”‚   β”‚   └── page.tsx       β†’ Homepage
β”‚   β”œβ”€β”€ components/        β†’ Reusable UI components
β”‚   β”œβ”€β”€ styles/            β†’ Tailwind + global styles
β”‚   β”œβ”€β”€ lib/               β†’ Utility functions or DB logic (optional)
β”‚   β”œβ”€β”€ types/             β†’ TypeScript types (optional)
β”‚   └── app/layout.tsx     β†’ Root layout
β”œβ”€β”€ tailwind.config.ts     β†’ Tailwind setup
β”œβ”€β”€ tsconfig.json          β†’ TypeScript settings
└── next.config.js         β†’ Next.js configuration

πŸŒ€ Setting Up Tailwind CSS (If Skipped)

If you didn’t enable Tailwind CSS during setup, install it manually:

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

Then configure your tailwind.config.ts:

content: [
  "./src/**/*.{js,ts,jsx,tsx}",
]

And include Tailwind in your global stylesheet (src/app/globals.css):

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

Import globals.css in src/app/layout.tsx:

import './globals.css';

πŸ§ͺ TypeScript Is Fully Integrated

By default, your project is now written in TypeScript β€” a must-have for production-level React apps. Benefits include:

  • Static type checking
  • Better autocompletion and tooling
  • Cleaner, safer code

Example component:

type Props = {
  title: string;
}

const Heading = ({ title }: Props) => (
  <h1 className="text-2xl font-bold">{title}</h1>
);

export default Heading;

βœ… Summary: You’re Ready to Build

By the end of Module 1, you have:

  • Understood why Next.js 14 is the future of React
  • Compared it with CRA and Gatsby
  • Installed Node, VS Code, and useful extensions
  • Created a project using TypeScript + App Router + Tailwind
  • Adopted the modern src/ folder structure

πŸŽ‰ You’re now fully set up for modern full-stack web development!


πŸ”œ Up Next:

In Module 2, we’ll explore Routing & Navigation β€” from file-based routes to dynamic segments and shared layouts.

Want the blog version in Markdown or HTML export as well?

Leave a Reply

Your email address will not be published. Required fields are marked *