Tech TutorBangla Web Documentation
Portfolio
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • Node.js Documentation20টি অধ্যায়
প্রযুক্তি নির্বাচন
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • Introduction
  • Installation
  • Modules
  • NPM
  • File System
  • Events
  • Streams
  • HTTP
  • Async Programming
  • Environment
  • Debugging
  • Express.js
  • API Development
  • Authentication
  • Database
  • Production
  • Advanced Node.js
  • Best Practices
  • Projects
  • Interview
  1. Docs
  2. Node.js
  3. Advanced Node.js
Node.jsAdvanced

Advanced Node.js

Worker Threads, child_process, Buffers, process lifecycle — advanced Node.js concepts বাংলায়।

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

Worker Threads

Worker Threads দিয়ে CPU-intensive কাজ parallel-ভাবে করা যায়। এতে main thread block হয় না।

worker.jsjavascript
javascript
const { Worker, isMainThread, parentPort } = require("node:worker_threads");

if (isMainThread) {
  // Main thread
  const worker = new Worker(__filename);

  worker.on("message", (result) => {
    console.log("Result:", result);
  });

  worker.postMessage(1000000000);
} else {
  // Worker thread
  parentPort.on("message", (n) => {
    let sum = 0;
    for (let i = 0; i < n; i++) sum += i;
    parentPort.postMessage(sum);
  });
}

child_process

const { exec, spawn } = require("node:child_process");

// exec — command run করে
exec("ls -la", (error, stdout, stderr) => {
  console.log("Files:", stdout);
});

// spawn — stream output
const ls = spawn("ls", ["-la"]);
ls.stdout.on("data", (data) => {
  console.log("Output:", data.toString());
});

Buffer

Buffer হলো binary data-কে represent করার উপায়। File I/O, network operations-এ binary data handle করতে Buffer দরকার হয়।

// Buffer create
const buf1 = Buffer.from("Hello");
const buf2 = Buffer.alloc(10); // 10 bytes zero-filled
const buf3 = Buffer.allocUnsafe(10); // uninitialized

// string → buffer → string
const encoded = Buffer.from("বাংলা টেক্সট");
console.log(encoded.toString()); // "বাংলা টেক্সট"
console.log(encoded.toString("base64")); // base64 encoded

// Buffer operations
console.log(buf1.length); // 5
console.log(buf1.toString("utf8")); // "Hello"

Process Lifecycle

// process events
process.on("exit", (code) => {
  console.log("Process exited with code:", code);
});

process.on("unhandledRejection", (reason, promise) => {
  console.error("Unhandled Rejection:", reason);
});

process.on("uncaughtException", (error) => {
  console.error("Uncaught Exception:", error);
  process.exit(1);
});

// graceful shutdown
process.on("SIGTERM", () => {
  console.log("SIGTERM received. Shutting down...");
  server.close(() => {
    db.close();
    process.exit(0);
  });
});
সংক্ষেপ

CPU-heavy কাজে Worker Threads, external command-এ child_process, binary data-তে Buffer — এগুলো advanced Node.js-এর মূল হাতিয়ার।

শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।
আগেরProduction Deployment & OptimizationপরেরNode.js Best Practices
এই পেজে
Tech Tutor

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

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

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

mdanamolhasan1998@gmail.com