Node.jsIntermediate
Node.js Debugging
console methods, Node Inspector, debugger statement — Node.js code debug করার বাংলা গাইড।
10টি অংশবাংলা ভাষায়
Debugging হলো bug খুঁজে বের করা ও fix করা। Node.js-এ অনেক debugging tools আছে।
console Methods
console.log("সাধারণ output");
console.error("Error message");
console.warn("Warning message");
// structured data
console.table([
{ name: "রহিম", age: 25 },
{ name: "করিম", age: 30 },
]);
// time tracking
console.time("loop");
for (let i = 0; i < 1000000; i++) {}
console.timeEnd("loop");
// group output
console.group("User Info");
console.log("Name: রহিম");
console.log("Age: 25");
console.groupEnd();Node Inspector (Debugger)
# --inspect দিয়ে debug mode চালু
node --inspect app.js
# breakpoint-এ থামাবে
node --inspect-brk app.js
# তারপর Chrome-এ chrome://inspect খুলুনdebugger Statement
function calculateTotal(items) {
let total = 0;
for (const item of items) {
debugger; // এখানে থামবে
total += item.price;
}
return total;
}
calculateTotal([{ price: 10 }, { price: 20 }]);util.inspect
const util = require("node:util");
const obj = {
name: "রহিম",
address: {
city: "ঢাকা",
zip: "1205",
},
};
// deep inspection
console.log(util.inspect(obj, {
showHidden: false,
depth: null, // সব depth দেখাবে
colors: true, // colored output
compact: false,
}));VS Code Integration
VS Code-এ launch.json কনফিগার করে direct Node.js debug করা যায়। এতে breakpoint set, variable inspect, call stack check — সব সম্ভব।
শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।