🚀 Node.js Interview Question #4: What is a Buffer in Node.js? A Buffer in Node.js is used to handle binary data directly in memory. Since JavaScript traditionally works with strings, Node.js introduced Buffer to process raw binary data such as: • File streams • Network packets • Image/video data 📌 Example const buffer = Buffer.from("Hello"); console.log(buffer); Output will be the binary representation of the string. 💡 Buffers are commonly used in file systems, streams, and networking applications. #NodeJS #BackendDevelopment #JavaScript
Node.js Buffer: Handling Binary Data
More Relevant Posts
-
#day53 Headline: 0ms Runtime | Beats 100% of JavaScript Submissions 🚀 Just cleared the "Single Element in a Sorted Array" challenge on LeetCode with $O(\log n)$ time complexity and $O(1)$ space. While a simple XOR approach works in $O(n)$, the real challenge was implementing a binary search that correctly navigates the even/odd index logic to find that one unique element in logarithmic time. There's a specific kind of satisfaction in seeing that "Beats 100%" metric. It's a reminder that in software engineering, the difference between "it works" and "it's optimal" is where the real fun begins. #LeetCode #JavaScript #DataStructures #Algorithms #CodingLife #Optimization #ProblemSolving
To view or add a comment, sign in
-
-
JavaScript Polyfills (forEach, map, filter, reduce): I explored how commonly used JavaScript array methods work internally by creating my own custom polyfills. ✔ forEach() – Iterates over each element (no return) ✔ map() – Transforms data and returns a new array ✔ filter() – Returns elements that satisfy a condition ✔ reduce() – Accumulates values into a single output Writing these polyfills helped me understand: • Callback function execution • Internal iteration logic • How new arrays are created • How reduce builds value step-by-step • Difference between transformation and filtering This exercise improved my understanding of higher-order functions and core JavaScript fundamentals. Naveen Kumar K G Raghu K #JavaScript #Polyfill #FrontendDevelopment #WebDevelopment #LearnInPublic #MERNStack #CodingJourney #JavaScriptDeveloper #BackendDevelopment #NodeJS #ExpressJS #MongoDB
To view or add a comment, sign in
-
🚨 JavaScript Tricky Question #3 (Advanced) What will be the output? 🤯 Promise.resolve() .then(() => { console.log("A"); throw new Error("Error!"); }) .catch(() => { console.log("B"); }) .then(() => { console.log("C"); }); Think carefully (this is tricky) 💬 Comment your answer 👇 🔁 Follow for daily advanced JS questions #javascriptdeveloper #mernstackdeveloper #frontendinterview #javascriptquestions #webdevelopmenttips #learnjavascript #jsconcepts #asyncjavascript #developersindia #codinginterview #softwaredeveloperlife #nodejsdeveloper #reactdeveloper #techcareers
To view or add a comment, sign in
-
JavaScript Interview Question: How do you cancel API requests in JavaScript? Answer: Using AbortController. Example: 𝘤𝘰𝘯𝘴𝘵 𝘤𝘰𝘯𝘵𝘳𝘰𝘭𝘭𝘦𝘳 = 𝘯𝘦𝘸 𝘈𝘣𝘰𝘳𝘵𝘊𝘰𝘯𝘵𝘳𝘰𝘭𝘭𝘦𝘳() 𝘧𝘦𝘵𝘤𝘩("/𝘢𝘱𝘪/𝘥𝘢𝘵𝘢", { 𝘴𝘪𝘨𝘯𝘢𝘭: 𝘤𝘰𝘯𝘵𝘳𝘰𝘭𝘭𝘦𝘳.𝘴𝘪𝘨𝘯𝘢𝘭 }) // 𝘤𝘢𝘯𝘤𝘦𝘭 𝘳𝘦𝘲𝘶𝘦𝘴𝘵 𝘤𝘰𝘯𝘵𝘳𝘰𝘭𝘭𝘦𝘳.𝘢𝘣𝘰𝘳𝘵() Explanation: AbortController allows you to cancel ongoing requests. Useful for: 1. search inputs (cancel previous queries) 2. component unmount 3. preventing race conditions Without it, outdated responses may overwrite newer data. Follow-up: Have you ever faced race condition bugs in API calls? #javascript #WebDevelopment #AsyncProgramming #FrontendDevelopment
To view or add a comment, sign in
-
Ever wondered where __dirname and __filename actually come from? You’ve probably used __dirname and __filename many times. Let’s unwrap what’s happening behind the scenes. They look like global variables. They behave like globals. But they’re not part of JavaScript. They are injected by Node.js through something called the Module Wrapper. Before executing your code, Node wraps every file inside a function. That’s how values like __dirname, __filename, require, and module are available in every file without you ever defining them. It also explains why things like require and module.exports just work out of the box. A small but a powerful detail when you’re working with Node at scale. Have you come across any other “hidden” internals like this? Would love to hear them. #NodeJS #JavaScript #BackendDevelopment #Engineering #SystemDesign
To view or add a comment, sign in
-
🟢 Node.js Interview Question What happens when Node.js thread pool is full? We write async code. We expect everything to run fast. But under load… things slow down. because Node’s thread pool has a default size of 4. So when we run multiple heavy tasks: • First 4 → start immediately • Rest → wait in a queue Even though our code is async… It doesn’t mean everything runs at the same time. Tasks still compete for limited threads. That is why: - Delays - Slower responses - Reduced throughput But but we can increase thread pool size. Yes you heard right, we can increase thread pool size using: ex - UV_THREADPOOL_SIZE=8 But more threads ≠ better performance. Too many threads → more overhead. Node.js is fast. But it has limits. Understanding those limits is what separates basic usage from real backend understanding. #NodeJS #BackendDevelopment #JavaScript #TechInterview #SystemDesign
To view or add a comment, sign in
-
𝗪𝗵𝗮𝘁 𝗶𝘀 𝘁𝗵𝗲 𝗘𝘃𝗲𝗻𝘁 𝗟𝗼𝗼𝗽 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁? JavaScript is single-threaded, but it can handle asynchronous operations efficiently using the Event Loop. The Event Loop is a mechanism that allows JavaScript to perform non-blocking operations like API calls, timers, and file reading while still running on a single thread. Here’s how it works: 1️⃣ Call Stack – Executes synchronous JavaScript code. 2️⃣ Web APIs – Handles async operations like "setTimeout", "fetch", and DOM events. 3️⃣ Callback Queue / Microtask Queue – Stores callbacks waiting to be executed. 4️⃣ Event Loop – Continuously checks if the call stack is empty and pushes queued callbacks to the stack for execution. This architecture allows JavaScript to manage asynchronous tasks without blocking the main thread, making it ideal for building fast and scalable web applications. Understanding the Event Loop is essential for mastering Promises, async/await, callbacks, and performance optimization in JavaScript. #JavaScript #EventLoop #WebDevelopment #FrontendDevelopment #NodeJS #AsyncJavaScript #CodingInterview #SoftwareEngineering #FullStackDeveloper #LearnToCode
To view or add a comment, sign in
-
🚀 Event Loop in Node.js — The Reason Your API Is Fast (or Slow) Node.js is fast… But only if you understand the Event Loop. If not 👇 👉 Slow responses 👉 Delayed requests 👉 Poor performance 😐 🔹 What is Event Loop? It handles all async operations in Node.js Single thread Non-blocking Processes tasks in phases 🔹 Common mistakes ❌ Blocking code (sync functions) ❌ Heavy computation in main thread ❌ Large loops / CPU-heavy tasks ❌ Ignoring async patterns ❌ Poor promise handling 🔹 What experienced devs do ✅ Use async/await properly ✅ Break heavy tasks into smaller chunks ✅ Use Worker Threads for CPU tasks ✅ Use queues (Bull, RabbitMQ) ✅ Monitor event loop lag ⚡ Simple rule I follow If Event Loop is blocked… Everything is blocked. Node.js doesn’t scale by threads… It scales by non-blocking design. Have you ever faced event loop blocking issues? 👇 #NodeJS #BackendDevelopment #JavaScript #API #EventLoop #WebDevelopment
To view or add a comment, sign in
-
-
🚀 Understanding Recursion + Finding Maximum in Nested Arrays (JavaScript) Today I practiced a powerful concept in JavaScript — recursion with nested arrays — and used it to solve a real problem: 👉 Find the maximum number from a deeply nested array 💡 Example: [1, 0, 7, [2, 5, [10], 4]] 🔍 Approach I followed: ✅ Step 1: Used recursion to flatten the nested array If the element is a number → push into result If it’s an array → call the same function again ✅ Step 2: After flattening, used a loop to find the maximum value 🧠 Key Learnings: • Each recursive call creates its own memory (execution context) • Data is temporarily stored in the call stack • The return keyword helps pass results back step by step • Without capturing the returned value, recursion results can be lost • Breaking problems into smaller parts makes complex logic easier ⚡ Final Output: 👉 Maximum number: 10 💬 This exercise really helped me understand: How recursion works internally How data flows through function calls Difference between primitive and reference types #JavaScript #Recursion #ProblemSolving #WebDevelopment #CodingJourney
To view or add a comment, sign in
-
What if you could guarantee the integrity of your data by validating it at the earliest possible stage in your NestJS application? That's where class-validator comes into play, a popular library used for validating DTOs in NestJS. Let's say you have a simple user registration endpoint, and you want to ensure that the username and password meet certain criteria. You can create a DTO with validation metadata using class-validator. ```javascript import { validate } from 'class-validator'; class UserDTO { @IsString() @MaxLength(20) username: string; @IsString() @MinLength(8) password: string; } ``` In this example, the `@IsString()` decorator checks if the username and password are strings, while `@MaxLength(20)` and `@MinLength(8)` validate their lengths. So, how are you handling validation in your NestJS applications? 💬 Have questions or working on something similar? DM me — happy to help. #NestJS #ClassValidator #Validation #NodeJS #BackendDevelopment #TypeScript #DTO #DataIntegrity
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