Node.js Tutorial

1. What is Node.js really? (in plain words)

Node.js = JavaScript running outside the browser

  • It lets you use JavaScript to write server-side code
  • It lets you build backend APIs, CLIs, scripts, microservices, real-time apps, etc.
  • Very fast at I/O heavy tasks (files, network, databases, APIs…)

Most popular use case in 2025–2026: Building REST APIs + GraphQL APIs + WebSocket servers

2. Installation (do it properly)

Option A: Recommended (2025–2026 way) → Use nvm (Node Version Manager)

Windows / macOS / Linux:

Bash
Bash

You should see something like:

text

(Or newer — that’s fine)

Option B: Quick install (not recommended long-term)

Just download from https://nodejs.org

Choose LTS version.

3. Hello World – 3 different styles

Style 1: Most basic

Create file hello.js

JavaScript

Run:

Bash

Style 2: Tiny HTTP server (classic Node.js hello world)

server.js

JavaScript
Bash

Open browser → http://localhost:3000

Style 3: Modern ESM style (2025+ best practice)

server.mjs

JavaScript

Run:

Bash

4. Important Project Structure (real-world style)

text

5. package.json – the heart of every Node.js project

Most important fields in 2025–2026:

JSON

6. Modern Express.js API – Full Example (2025–2026 style)

JavaScript

Run it:

Bash

Try:

Bash

7. Most Important Node.js Concepts You Must Understand

Topic Why it matters Quick Tip / Gotcha
Event Loop Heart of Node.js Never block it with heavy computation
require vs import CommonJS vs ESM Use ESM (import) in 2025+
process.env Environment variables Always use dotenv
async/await 90% of real code Handle errors properly!
Streams Files > 100MB, video, logs Use pipeline() from node:stream/promises
Clustering Use all CPU cores cluster module or pm2
Error handling Crashes kill production Use domains + global handler
npm vs pnpm vs bun Package manager speed & disk usage pnpm or bun → much better in 2026

8. Recommended Modern Tech Stack (2026)

Very popular & production-ready combination:

  • Runtime: Node.js 20 LTS or 22
  • Framework: Express (classic) or Fastify (faster) or Hono (very modern & lightweight)
  • Validation: Zod
  • ORM/Database: Prisma + PostgreSQL / Drizzle + PostgreSQL
  • Auth: JWT + cookie-session or ** Lucia** / NextAuth/Auth.js
  • Testing: Jest + Supertest or Vitest
  • Linting/Formatting: ESLint flat config + Prettier
  • Package manager: pnpm or bun
  • Deployment: Docker + Render / Railway / Fly.io / Vercel (for serverless)

Want to go deeper in any of these areas?

  • Async patterns & common mistakes
  • File upload (very common question)
  • Authentication & authorization (JWT vs sessions)
  • WebSockets (real-time chat)
  • How to structure big Node.js projects
  • Performance tips & benchmarking
  • Deploying Node.js properly in 2026

Just tell me which topic you want next — I’ll go as deep as you want! 😄