Tech TutorBangla Web Documentation
Portfolio
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • Express Documentation22টি অধ্যায়
প্রযুক্তি নির্বাচন
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • Introduction
  • Installation
  • Routing
  • Middleware
  • Request & Response
  • Static Files
  • Router
  • Error Handling
  • Template Engines
  • Body Parsing
  • File Upload
  • CORS
  • Database
  • Validation
  • Authentication
  • Security
  • REST API
  • Performance
  • Testing
  • Best Practices
  • Project
  • Interview
  1. Docs
  2. Express
  3. Express Performance Optimization
ExpressAdvanced

Express Performance Optimization

gzip, caching, N+1 query fix, clustering, monitoring — Express-এ performance বাংলায়।

16টি অংশবাংলা ভাষায়

API slow হলে user experience খারাপ হয়। নিচের টেকনিক দিয়ে Express app দ্রুত করা যায়।

1. Compression

npm install compression
const compression = require("compression");
app.use(compression()); // gzip — response size কমানো

2. Response Caching

// static caching headers
app.use(
  express.static("public", {
    maxAge: "1d",
    immutable: true, // content changes না
  })
);

// API caching (private) — client-side redirect
app.get("/api/me", (req, res) => {
  res.set("Cache-Control", "private, max-age=60");
  res.json({ user: req.user });
});

3. N+1 Query Problem

// ❌ N+1 — প্রতিটি post প্রতিটি author query (slow)
const posts = await Post.find();
for (const post of posts) {
  post.author = await User.findById(post.authorId); // N queries
}

// ✅ populate/join — এক query-তেই
const posts = await Post.find().populate("author", "name email");

4. Database Indexing

User Modeljavascript
javascript
const userSchema = new mongoose.Schema({
  email: { type: String, unique: true }, // auto index
  name: String,
  postsCount: { type: Number, default: 0 },
});

// custom index
userSchema.index({ name: "text" });           // text search
userSchema.index({ createdAt: -1 });          // sort dependent

5. Cluster Mode

# PM2 দিয়ে cluster — সব CPU core ব্যবহার
pm2 start index.js -i max
pm2 status

Performance Tests

npm install autocannon
# test 20s, 100 concurrent
npx autocannon -c 100 -d 20 http://localhost:5000/api/users

# Output দেখায়: requests/sec, latency, errors
বড় step-by-step

প্রথমে test করুন (baseline), তারপর optimize (compression → cache → query fix), আবার test — সম্বেখ সেরা ফলাফল দেখুন।

শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।
আগেরRESTful API Design with ExpressপরেরExpress Testing (Jest + Supertest)
এই পেজে
Tech Tutor

বাংলায় ওয়েব ডেভেলপমেন্ট ডকুমেন্টেশন শিখুন — ধাপে ধাপে।

Homeসব ডকুমেন্টেশনQuick Startআমার নোটস

© 2026 Tech Tutor. বাংলায় শিখুন, বাংলায় গড়ুন।

mdanamolhasan1998@gmail.com