🚀 Understanding the Node.js Event Loop (libuv) — finally clicked! While learning Node.js internals, I spent time understanding how the libuv event loop actually executes async code — and this diagram made everything crystal clear. 🔁 Key takeaway: There are two priority queues that run before every phase 👇 👉 process.nextTick() 👉 Promise callbacks (microtasks) These always execute first, even between phases. Event Loop flow (simplified): 1️⃣ Microtasks (Highest Priority) process.nextTick() Promise.then / catch / finally 👉 Executed immediately, before moving ahead 2️⃣ Timers Phase setTimeout() setInterval() ➡️ After timers finish → Node again checks microtasks 3️⃣ Poll Phase I/O operations API calls DB queries fs.readFile, network requests 👉 This is where most real backend work happens ➡️ Again → microtasks are checked 4️⃣ Check Phase setImmediate() 5️⃣ Close Phase socket close connection cleanup close callbacks 🧠 Important insight: The inner circle (nextTick + Promises) runs between every phase, which is why misuse of process.nextTick() can starve the event loop. #NodeJS #libuv #EventLoop #JavaScript #BackendEngineering #AsyncProgramming #LearningInPublic
Node.js Event Loop Explained: libuv Diagram
More Relevant Posts
-
⏳ JavaScript is about to fix one of its oldest design flaws: time handling. The Temporal API is getting closer to being enabled by default in Node.js. And this isn’t just a syntax improvement — it’s a structural change in how we model time in backend systems. For years, we’ve relied on Date, which is: 🔁 Mutable 🌍 Implicitly timezone-dependent ⚠️ Easy to misuse 🧩 Hard to reason about in distributed systems In production, that leads to: ⏰ DST-related bugs 💳 Incorrect financial calculations 📜 Log inconsistencies 🗓 Scheduling drift 🌐 Cross-region edge cases Temporal introduces: 🧱 Immutable time objects 🌍 Explicit timezones ➕ First-class date/time arithmetic 🧭 Clear separation between absolute and calendar time For backend engineers, this matters more than most language features. Time bugs are expensive. They’re silent. And they surface when it’s already too late. If Temporal becomes the default in Node.js, it won’t just modernize APIs — it will improve reliability at scale. The real question isn’t whether Temporal is better. It’s whether teams are ready to rethink how they model time. https://lnkd.in/emjWFMh7
To view or add a comment, sign in
-
TypeScript 6.0 beta just dropped. This is the last version written in JavaScript before the Go rewrite in 7.0. Here's what's new: 𝗡𝗲𝘄 𝗧𝗲𝗺𝗽𝗼𝗿𝗮𝗹 𝗔𝗣𝗜 𝘁𝘆𝗽𝗲𝘀 Enable with `--target esnext` or `lib: ["esnext"]` to start using modern date/time handling. 𝗠𝗮𝗽 𝘂𝗽𝘀𝗲𝗿𝘁 𝗺𝗲𝘁𝗵𝗼𝗱𝘀 `getOrInsert` and `getOrInsertComputed` make Map operations cleaner (available in esnext lib). 𝗥𝗲𝗴𝗘𝘅𝗽.𝗲𝘀𝗰𝗮𝗽𝗲 𝗳𝗼𝗿 𝘀𝗮𝗳𝗲𝗿 𝗿𝗲𝗴𝗲𝘅 Automatically escape special characters like *, ?, + (in es2025 lib). `--𝘀𝘁𝗮𝗯𝗹𝗲𝗧𝘆𝗽𝗲𝗢𝗿𝗱𝗲𝗿𝗶𝗻𝗴` 𝗳𝗹𝗮𝗴 Helps compare type outputs between 6.0 and the upcoming 7.0, useful for migration testing (not for everyday use). The catch? That ordering flag can slow type checking by 25% in large codebases. Only use it when you need to diagnose differences. If you're on modern practices (strict mode, ES2020+, ESM), upgrading is smooth. If you're stuck on old bundlers, wait. The real win comes with 7.0. This is just the bridge. Are you upgrading to 6.0 or waiting for the Go rewrite? #TypeScript #WebDevelopment #JavaScript #devlife #DevTools
To view or add a comment, sign in
-
-
Day 93 of #100DaysOfLinkedIn — Providers & Dependency Injection in NestJS Today I learned about Providers and Dependency Injection, which is one of the core concepts of NestJS. Instead of manually creating objects, NestJS automatically manages dependencies, making the code cleaner, testable, and scalable. What I learned today: • What providers and services are • How Dependency Injection works in NestJS • Why services are used for business logic • Service lifecycle and singleton behavior • Injecting services into controllers This concept is what makes NestJS feel enterprise-ready compared to plain Express. #NestJS #NodeJS #TypeScript #BackendDevelopment #DependencyInjection #100DaysOfLinkedIn #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
Day 47 of my #100DaysOfCodeChallenge (Delayed by power outage — but consistency continues.) Today I went deeper into the core architecture of Node.js, and things are starting to connect at a much deeper level. Here’s what I focused on: 🔹 REPL (Read–Eval–Print Loop) Understanding how Node executes JavaScript interactively from the terminal and how execution flows internally. 🔹 Working with Standard Input & Output Using the readline module to capture user input from the terminal. This helped me understand how CLI tools are built and how Node interacts directly with the system environment. 🔹 File System Module (fs) Explored reading and writing files both: Synchronously (blocking) Asynchronously (non-blocking) This was the major learning point. Key Concept Reinforced Today JavaScript is single-threaded Node.js uses a non-blocking, event-driven architecture Synchronous operations block the execution thread Asynchronous operations delegate tasks and continue executing the next line of code Callbacks control execution order in async operations Seeing "Reading File....." log before file data was returned made the event loop behavior much clearer to me. Understanding this execution model makes it obvious why mastering Node fundamentals is critical before going deeper into frameworks like Express. The goal isn’t just to write backend code — It’s to understand how the runtime actually works. On to Day 48. #NodeJS #BackendDevelopment #JavaScript #SoftwareEngineering #BuildInPublic #100DaysOfCode
To view or add a comment, sign in
-
-
😶🌫️The most expensive line of code in a TypeScript project is const data: any = .... Why? Because you’re paying for speed today with a debugging nightmare tomorrow. If you want to keep your codebase clean, think of these three as your Safety Spectrum: ● any is the "I give up" type. 🏳️ It’s a total blackout. It shuts off the compiler and tells TS to go take a coffee break while you ship a potential runtime crash. Use it only when you’re migrating legacy JS and your hair is on fire. ● unknown is the "Prove it" type. 🔍 It’s the safest way to handle uncertainty. It says, "I don't know what this is yet, so I won't let you touch it until you check its ID." It’s any with a conscience. Use it for API responses or dynamic user input. ● never is the "Impossible" type. 🚫 It represents values that should never exist. It’s your best friend for Exhaustive Checking. If your code hits a never block, something has gone fundamentally wrong—and TS will warn you about it before you deploy. 📝 Summary: ▶Don't use any to make errors go away. ▶Do use unknown to force safe checks. ▶Do use never to make sure you’ve handled every possible case. Stop writing "AnyScript." Your future self (and your teammates) will thank you. #TypeScript #WebDev #JavaScript #CleanCode #SoftwareEngineering #DevLife
To view or add a comment, sign in
-
-
Mastering DevTools: The Secret Weapon Every Modern Engineer Should Use Debugging isn’t just a task — it’s a superpower every engineer needs. Whether you're deep in JavaScript, building Angular front‑ends, crafting Node.js services, writing blazing‑fast Go code, or fine‑tuning Postgres queries… one common skill lifts all boats: 👉 Mastering Browser Developer Tools Here are the most underrated yet powerful DevTools features that can instantly level up your debugging game: 🔍 1. Breakpoints (The Precision Debugger) You don’t need to scatter console.log() everywhere. Use conditional breakpoints, XHR breakpoints, DOM breakpoints, and event listener breakpoints to stop execution exactly where the bug hides. 🪜 2. Step In / Step Out / Step Over (Flow Control for Grown‑Ups) Perfect visibility into how your code executes: Step into async calls Step over large logic chunks Step out of noisy functions Great for debugging Angular lifecycle hooks, async Node.js logic, or complex JS closure-based flows. 🧪 3. The Console (Not Just for Logging!) Most devs barely use 20% of its power. Try: $0 to reference the selected DOM node copy() to instantly export data monitorEvents() for debugging complex UI events Live expressions to track values in real time 🧭 4. Network Panel (Your API Lie Detector) Useful for Node.js backend debugging and Postgres query tracing when APIs are slow. Inspect request timing, payloads, caching, and WebSocket frames. 🎨 5. Sources Panel (The Hidden Gem) Use it to: Edit JS/CSS on the fly Map to your local files with Workspaces Replay code execution A must for Angular and heavy front-end apps. ⚡ 6. Performance & Memory Tools (For the Go + JS Crowd) Track memory leaks, GC cycles, and CPU hotspots. Perfect when debugging real-time apps or microservices talking to the front‑end. ✨ Wrapping Up Browser DevTools have grown into one of the most advanced debugging ecosystems available today. Mastering them makes you faster, more accurate, and far more dangerous (in a good way 😉). What’s your favorite DevTools trick that others often overlook? Relevant Hashtags #JavaScript #Angular #NodeJS #Golang #Postgres #WebDevelopment #FrontendEngineering #BackendEngineering #SoftwareEngineering #Debugging #DevTools #ProgrammingTips #Developers
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟭𝟮 𝗼𝗳 𝗠𝘆 𝗧𝘆𝗽𝗲𝗦𝗰𝗿𝗶𝗽𝘁 𝗦𝗽𝗿𝗶𝗻𝘁 — 𝗖𝗟𝗜 𝗡𝗼𝘁𝗲𝘀 𝗔𝗽𝗽 (𝗡𝗼𝗱𝗲.𝗷𝘀 + 𝗧𝗦) I built a CLI Notes App using Node.js + TypeScript, focusing on how types behave in real execution — not just inside tutorials. 𝗖𝗼𝗻𝗰𝗲𝗽𝘁𝘀 𝗔𝗽𝗽𝗹𝗶𝗲𝗱 • fs module for file handling • Async I/O with proper typing • Strongly typed CLI arguments • Module-based architecture • Command handling with the commander 𝗙𝗲𝗮𝘁𝘂𝗿𝗲𝘀 • Add, list, delete, and search notes • JSON-based persistence • Clean, colored CLI output using chalk 𝗪𝗵𝗮𝘁 𝗧𝗵𝗶𝘀 𝗣𝗿𝗼𝗷𝗲𝗰𝘁 𝗥𝗲𝗶𝗻𝗳𝗼𝗿𝗰𝗲𝗱 TypeScript delivers the most value when inputs are unpredictable and side effects exist. Typing CLI arguments, file I/O, and async flows forced me to: • Model data intentionally • Handle edge cases early • Refactor confidently with compiler support #TypeScript #NodeJS #CLI #LearningInPublic #SoftwareEngineering #JavaScript #DeveloperJourney
To view or add a comment, sign in
-
"any" isn't a type. It's you giving up. You write any and TypeScript stops helping you. Completely. It won't catch typos. It won't catch wrong methods. It won't catch anything. You basically paid the TypeScript tax (extra syntax, build step, config files) and got nothing back. With any: call any method, access any property, TypeScript says nothing. Code explodes at runtime. With unknown: TypeScript blocks you until you prove what it is. ts const data = parseJSON(str) // unknown 👏 if (typeof data === 'object' && data && 'name' in data) { console.log(data.name) // now it's safe } "But that's more code" Yes. That's the point. That code is the check you should have written anyway. TypeScript just forced you to not forget it. When to use unknown: → API responses → JSON parsing → User input → Any external data you don't control When to use any: → Never → Ok maybe when migrating JS to TS → But then fix it immediately Every any in your codebase is a bug waiting to happen. You just haven't found it yet. #typescript #javascript #frontend #webdev #programming #webdevelopment #react #cleancode #devtips #softwaredevelopment
To view or add a comment, sign in
-
-
🧠 The bug that cost me 3 hours… and taught me (again) how TypeScript lies to you Today I spent almost 3 hours debugging something that made absolutely no sense. Same DTO. Same ValidationPipe. Same endpoint structure. ✅ Works perfectly in one place. ❌ Completely breaks in another. The logs were weird: DTO looked like a function JSON.stringify() returned undefined ValidationPipe kept throwing BadRequestException request body existed, but DTO fields were undefined Everything looked correct. So naturally: checked pipes checked middleware checked request payload blamed NestJS blamed class-validator questioned life decisions The confusing part? The exact same logic worked elsewhere in the project. After digging through pipes, decorators, and request lifecycle… the problem turned out to be one single word: import type { UpdateUserByAdminDTO } from "../dto/admin-user.dto"; Yep. import type. TypeScript removes type-only imports at runtime. But NestJS needs DTO classes at runtime for validation, transformation, and metadata reflection. So ValidationPipe wasn’t receiving a class — it was receiving… nothing useful. Changing it to: import { UpdateUserByAdminDTO } from "../dto/admin-user.dto"; Fixed everything instantly. Lesson (that I apparently need to relearn every few months): If a class is used by: decorators ValidationPipe Swagger helpers (PartialType, OmitType) class-validator class-transformer 👉 it is NOT a type. It’s runtime code. And import type will silently break it. Sometimes the hardest bugs are not complex ones. They’re the ones where everything looks correct. And the fix is one deleted word. #TypeScript #NestJS #BackendDevelopment #SoftwareEngineering #Debugging #WebDevelopment #ProgrammingLife #Developers #LessonsLearned #Coding
To view or add a comment, sign in
-
-
😄 Async/Await Appreciation Post Looking at old Promise chains in legacy code: .then(() => { .then(() => { .then(() => { 😵💫 Writing the same logic today: const res = await fetch(url); const data = await res.json(); Sometimes developer growth is simply… Writing less code Reading more clarity Debugging less stress ☕⚡ 💡 Biggest realization: Async/Await didn’t change JavaScript… It changed how comfortably we write asynchronous logic. Meanwhile JavaScript: “Don’t worry, I’ll run other tasks while you wait.” 🧠⚡ #JavaScript #AsyncAwait #DevHumor #FrontendDevelopment #LearningInPublic
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Is poll is for async operations?