Node.js Debugging: Chhote Bugs ko Bade Style se Fix Karein! 😎

Node.js Debugging: Chhote Bugs ko Bade Style se Fix Karein! 😎

πŸ˜„ Agar tum Node.js mein code likhte ho aur kabhi-kabhi “Yaar, yeh toh chal hi nahi raha!” wala feeling aata hai, toh tension nahi! Debugging Node.js ko hum samjhenge, full power! πŸ’»πŸ”

1. console.log(): Sabse Simple Tarika! πŸ—£οΈ

Haan, haan, pata hai sab kehte hain “console.log mat use karo!” par chhota-mota debugging ho toh yeh desi jugaad zabardast kaam karta hai:

const chaiPrice = 20;
console.log("Bhaiya, Chai ka daam:", chaiPrice); // "Bhaiya, Chai ka daam: 20"

Par dhyan rahe:

  • Garbage Logging Mat Karo: Baad mein clean karna padega!
  • console.table(): Array/object ko mast dikhata hai! 😍

2. Node.js Built-In Debugger: Old is Gold! πŸ•΅οΈβ™‚οΈ

Terminal mein yeh magic command chalao:

node inspect server.js

Ab debugger start ho gaya!

  • c β†’ continue
  • n β†’ next line
  • repl β†’ variables check karo
    Thoda purana style hai, par emergency mein kaam aata hai!

3. Chrome DevTools + Node.js: Jodi No. 1! 🌐

Step 1: Apna app isse run karo:

node --inspect server.js

Step 2: Chrome mein jaake chrome://inspect likho.
Step 3: “Remote Target” dikhega – click karo!
Ab breakpoints lagao, variables dekho, call stack check karo… bilkul VIP debugging experience! ✨

4. VS Code Debugger: Asli Developer ka Samaan! 🧰

VS Code toh hum sabka best friend hai na?

  • .vscode/launch.json file mein jaake “Node.js” setup karo.
  • F5 dabao β†’ debugger shuru!
  • Left side mein dikhega: Variables, Watch Expressions, Call Stack!
    Breakpoint lagana? Line ke left mein click karo β†’ laal dot aa jayega! πŸ”΄

Pro Tips: Bach ke Rehna Inse! ⚠️

  • try-catch: Async code mein error catch karo!
  try { 
    await connectDatabase(); 
  } catch (error) {
    console.error("Oho! Database gayi tel lene:", error);
  }
  • Source Maps: TypeScript/Webpack mein zaroor enable karo.
  • Logging Libraries: Winston ya Bunyan use karo – console.log se level up! πŸ“ˆ

Niche Na Jaaye Confidence! πŸ’ͺ

Debugging darrne ki cheez nahi hai! Yaad rakho:

“Har error ek naya lesson hai.
Har bug teri coding ki gehrai badhata hai!”

Agli baar jab server crash kare toh bolein:
“Abey saale, tu galti kaha kar raha hai? Aaja, tujhe debug karta hoon!” 😀


Final Baat: Chahe console.log se kaam chalao ya VS Code ki fancy tools use karo – solutions nikalna hi asli hacking hai! So relax, chai piyo, aur bugs ko debug karo. Happy coding, dost! πŸ™Œ

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *