Basic setup (Node, VS Code, project create)
-
Next.js app structure समझना
-
Pages, routing, components, CSS, assets
-
Running, building, deploying basics
Main example: simple blog-style app / demo site.
I’ll use create-next-app (App Router, TypeScript off for now to keep it simple).
Commands मान रहा हूँ कि तू Windows + Node.js + npm use कर रहा है.
1️⃣ Prerequisite setup
1. Install Node.js
-
Go to Node.js वेबसाइट (LTS version install करना बेहतर है).
-
Install and verify:
अगर दोनों version दिखा रहे हैं तो setup ready ✅
2. Create workspace folder
मान लो तू D:\Projects\nextjs-basics use कर रहा है:
2️⃣ New Next.js app बनाना (from scratch)
Next.js team officially create-next-app recommend करती है.
1. Run the generator
ये command पूछेगा (approx — options थोड़े बदल सकते हैं time के साथ):
-
What is your project named? →
my-first-next-app -
TypeScript? →
No(for now) -
ESLint? →
Yes -
Tailwind CSS? → अभी
No(पहले core समझते हैं) -
src/ directory? →
No(simple रखना) -
App Router (recommended)? →
Yes -
import alias? → default रहने दे (
@/*)
Create होने के बाद:
2. Important npm commands (core commands)
Inside project folder:
-
Dev server चलाने के लिए:
Default: http://localhost:3000
-
Production build बनाने के लिए:
-
Production server run (build के बाद):
-
Lint check (ESLint):
ये चार commands तू बार-बार use करेगा.
3️⃣ Project structure समझना
my-first-next-app folder में कुछ main चीज़ें दिखेंगी:
App Router basics
-
app/page.js→ route/ -
app/about/page.js→ route/about -
app/blog/page.js→ route/blog -
app/blog/[slug]/page.js→ dynamic route/blog/anything
4️⃣ First run – check default page
Run:
Browser में खोल:
http://localhost:3000
तुझे Next.js का default welcome page दिखेगा.
अब इसे धीरे-धीरे अपने हिसाब से तोड़ते हैं.
5️⃣ layout.js & page.js – skeleton समझ
app/layout.js (root layout)
यहाँ basically HTML का outer shell होता है:
जो भी page होगा (app folder के अंदर), वो children के रूप में यहाँ render होगा.
मतलब ये एक बार define, हर जगह common layout मिल गया.
app/page.js (home page)
Default वाला हटाकर simple अपना बना:
Save करो → browser auto reload → नया page दिखेगा ✅
6️⃣ Pages & Routing – basic to intermediate
1. New static page बनाना (/about)
New folder + page:
अब http://localhost:3000/about खुल जाएगा.
2. Linking between pages
Next.js client navigation के लिए <Link> component देता है (no full reload).
Concept:
Normal
<a href>→ browser reload, full round-trip
<Link href>→ SPA-style, fast navigation (Next.js handles internally)
3. Blog listing page
(चाहो तो यहाँ भी Link use कर सकते हो, अभी basic दिखा रहा हूँ.)
4. Dynamic routes (/blog/[slug])
Concepts:
-
paramsprop App Router में आता है{ slug } -
[slug]→ dynamic URL segment -
posts[params.slug]→ URL के हिसाब से डेटा fetch
7️⃣ Styling – CSS basics in Next.js
1. Global CSS (app/globals.css)
globals.css में कुछ basic styling डाल:
ये सब pages पर लागू होगा automatically क्योंकि layout.js में import './globals.css' already रहता है (check कर लेना).
2. Component-level UI (simple Nav component)
app/components/Nav.js create:
अब इसे layout में use कर:
Concept:
Reusable React components + file-based routing = Next.js की ताकत
8️⃣ Static data vs async data fetch (Server Components)
By default App Router pages Server Components होते हैं.
तू async function directly use कर सकता है.
Example: Blog list को async बना देते हैं (मान लो future में API से आएगा):
Concepts:
Server Components → run on server, can use async/await easily, no client JS overhead.
Data fetching यहाँ ही कर सकता है (later Directus / DB / API से).
9️⃣ Public assets (images, favicon, etc.)
public/ folder = directly accessible at root.
Example:
-
Put
logo.pnginpublic/ -
Use in any page:
next/image:
Automatic optimization
Lazy loading
Responsive behaviour
🔟 Basic “Dev → Build → Prod” cycle
1. Development
-
Hot reload
-
Error overlays
-
Console logs etc.
2. Production build
ये करेगा:
-
Code optimization
-
Static optimization
-
Server & client bundles separation
-
Warnings अगर कुछ गलत या heavy है
3. Run production server
अब ये optimized mode में चलेगा. Real world जैसा behaviour.
1️⃣1️⃣ Some important Next.js concepts covered so far
-
App Router (
app/directory) -
File-based routing (
page.js,[slug]/page.js) -
Layouts (
layout.js, shared across pages) -
Linking (
next/link) -
Global CSS (
globals.css) -
Components (Nav, etc.)
-
Server Components + async data
-
Static files (
public/+next/image) -
npm scripts (
dev,build,start,lint)
1️⃣2️⃣ Next level ideas (jab तू comfortable हो जाए)
Once basics pakka:
-
Add Tailwind CSS (re-run project with Tailwind yes, या manually add)
-
Add API routes using
app/api/... -
Connect to a CMS (Directus 😉)
-
Add dynamic metadata, SEO optimizations
-
Try deployment (Vercel is the default easy way)
Comments
Post a Comment