<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Understanding Network Devices]]></title><description><![CDATA[Understanding Network Devices]]></description><link>https://blog.bipinbhatt.com.np</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Nov 2026 18:52:01 GMT</lastBuildDate><atom:link href="https://blog.bipinbhatt.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How ChatGPT Understands Your Questions?
]]></title><description><![CDATA[This blog is about generative AI. This is complete LLM part that a GenAI engineer need to know about.]]></description><link>https://blog.bipinbhatt.com.np/how-chatgpt-understands-your-questions</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/how-chatgpt-understands-your-questions</guid><category><![CDATA[genai]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[chatgpt]]></category><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Wed, 01 Jul 2026 17:08:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/f257ec97-ab13-4a29-9e9d-0295c2b5b09a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Back in the days we used to ask questions to teachers, friends or we used to google it. But nowadays we don't do that anymore. Today, many of us simply open ChatGPT and ask our question in natural language.</p>
<p>But have you ever wondered how chatGPT understand everything we say and gives us answers?</p>
<p>Today, in this blog I will try to explain how chatGPT understand questions and give us answers. The topics will be covered are:</p>
<ul>
<li><p>What is an LLM?</p>
</li>
<li><p>How ChatGPT processes your message</p>
</li>
<li><p>Tokenization and Encoding</p>
</li>
<li><p>Embeddings and Positional Encoding</p>
</li>
<li><p>Transformers and Self-Attention</p>
</li>
<li><p>Multi-Head Attention and Feed Forward Networks</p>
</li>
<li><p>Logits, Temperature, and Softmax</p>
</li>
<li><p>How the next token is selected</p>
</li>
<li><p>Context Window</p>
</li>
<li><p>Training vs. Inference</p>
</li>
<li><p>Putting it all together: <strong>Prompt → Response</strong></p>
</li>
</ul>
<p>By the end of this article, you'll understand what happens inside an LLM from the moment you type a prompt until ChatGPT generates its response.</p>
<h2>What is an LLM?</h2>
<h3>What does LLM stand for?</h3>
<p>LLM stands for Large Language Model.</p>
<p><strong>Large:</strong> The model is trained on enormous amount of text data. It has been trained on most of the available data on internet ( like books, blogs, websites, code etc).</p>
<p><strong>Language:</strong> It is called a Language Model because it is designed to understand and generate human language.</p>
<p><strong>Model:</strong> In machine learning, a model is a mathematical system that <strong>learns patterns from data</strong>. It isn't a database of facts—it learns statistical relationships between words and tokens.</p>
<blockquote>
<p>So, the LLM is a machine learning model that has been trained using large amount of data to make it able to communicate in human language by predicting next token</p>
</blockquote>
<h3>What problems the LLMs solve?</h3>
<p>Before LLMs, humans often had to communicate with computers using commands or programming languages. LLMs solved that and Language related problems like answering quetions, text generation, writing and debugging code, translation, summarization.</p>
<h3>Popular examples of LLM</h3>
<p>Popular LLMs are: GPT (OpenAI), Claude (Anthropic), Gemini (Google), Llama (Meta), Mistral, Qwen, DeepSeek, and Command (Cohere)</p>
<h2>What Happens When You Send a Message to ChatGPT?</h2>
<img src="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/d64680e6-9429-401d-bbac-0dece6ce6734.png" alt="" style="display:block;margin:0 auto" />

<p>When you send a message to chatGPT, first it breaks prompt into tokens(we will talk later about it) and converts the prompt into tokens and numerical representations so that LLM (GPT) could understand that and do processing and give us what we want.</p>
<p>After converting prompt to it's understandable form GPT predicts one token at a time append that token and again generate next token and keep predicting until it generates whole response. The whole response is not generated at once but one by one token.</p>
<h3>Why responses are not copied from the internet?</h3>
<p>LLMs are not something like the databases to retrieve instead they generate. LLMs generate reponses on the go based the pattern they have learned from the training data. LLMs are not connected to the live, and does not store any documents they predict next token based on the training data. (That's why they are called GPT: generative pre-trained transformer).</p>
<h2><strong>Why Computers Don't Understand Human Language</strong></h2>
<p>As we know computers process mathematical logic through binary code (1s and 0s). But human language is messy and contextual . So it is hard for computer to understand human language.</p>
<p>Are you sure?</p>
<p>Are you sure? 😡</p>
<p>Are you sure?😂</p>
<p>Are you sure? 😉</p>
<p>Are you sure? 😢</p>
<p>Computers don’t understand emojis as emotions — they only see them as different Unicode numbers. But we as a human can clearly see the difference.<br />The main thing that makes computers bad at understanding human language is <mark class="bg-yellow-200 dark:bg-yellow-500/30">Context and Intent.</mark></p>
<p>To make computers to understand we need to covert natural language into number. For that thing we use concept called Tokennization.</p>
<h2>Tokenization</h2>
<p>When we give a prompt to ChatGPT the first step is tokenization. Our input text is broken into chunks called tokens. Different LLMs may use different tokenizers and vocabularies.</p>
<p>Each token has a unique number associated with it called a token ID. If we assign a number to every single character that would be inefficient. A token is a sequence of characters, not necessarily a complete word.</p>
<p>A word is what humans read and write, while a token is the unit an LLM processes. A token is not always a complete word—it can be a whole word, part of a word, punctuation, a number, or an emoji. The exact tokenization depends on the model's tokenizer.</p>
<p>For example:</p>
<p><em>"Write a poem about Nepal."</em></p>
<p>There are just 5 words. But Using the GPT-4/GPT-3.5 tokenizer, this sentence is split into 6 tokens as shown below.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/ea863167-c3d9-4fa6-86ff-6685285a178f.png" alt="" style="display:block;margin:0 auto" />

<p><strong><mark class="bg-yellow-200 dark:bg-yellow-500/30">And Token IDs are like : </mark></strong> <mark class="bg-yellow-200 dark:bg-yellow-500/30">[8144, 264, 33894, 922, 50064, 13].</mark></p>
<blockquote>
<p>The process of converting tokens into corresponding numbers is called Encoding.</p>
</blockquote>
<p>Every model has its own vocabulary, which is a dictionary that maps tokens to their corresponding token IDs. So our text is broken into tokens based on that dictionary so it can easily be converted into numbers for further processing.</p>
<h2>Transformer</h2>
<p>Before 2017, many AI language models struggled to understand long sentences because they processed words one by one. This made it difficult to remember information from earlier parts of a sentence.</p>
<p>A transformer is the core architecture of modern Large Language Models (LLMs). Its job is to understand the relationships between all the tokens in the input and use that understanding to predict the next token.</p>
<p>Everything changed with the publication of Attention Is All You Need, a research paper that introduced the Transformer architecture. Today, almost every modern Large Language Model (LLM), including GPT, Gemini, Claude, and Llama, is built on this architecture.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/5ae04296-42e9-4bf6-add9-65e4c8092901.png" alt="" style="display:block;margin:0 auto" />

<p>A Transformer is called a Transformer because it transforms simple token representations into rich, context-aware representations. Instead of treating every word independently, it learns the meaning of each word based on the words around it.</p>
<h3>Embeddings</h3>
<p>After tokenization and encoding, Now LLM has the token ID's like: [8144, 264, 33894, 922, 50064, 13]. These numbers themself don't have real world meaning.</p>
<p>This is where the Embeddings comes into picture.</p>
<p>An embedding is a high-dimensional vector (we use 3d for visualization) that represent a meaning of token. Instead of treating words as plain text, the model places them in a mathematical space where similar concepts are located close to one another and form clusters.</p>
<p>Embeddings place similar concepts near each other, and similar semantic relationships are represented by similar vectors.</p>
<p><mark class="bg-yellow-200 dark:bg-yellow-500/30">Embeddings capture two important properties:<br />a.semantics similarities and</mark></p>
<p><mark class="bg-yellow-200 dark:bg-yellow-500/30">b. semantic relationships</mark></p>
<p>For example:</p>
<p>Countries like Nepal, India , USA, France naturally form a cluster.<br />Similary pet animals like cat , dog are close to eachother than a truck .</p>
<blockquote>
<p>Words that have similar meanings or play similar roles tend to be close together in this embedding space.</p>
</blockquote>
<p>As shown in the diagram above, embeddings don't just group similar words together—they also learn <strong>relationships</strong> between them.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/c6f72ade-23a9-4890-a853-2eb4f38f1542.png" alt="" style="display:block;margin:0 auto" />

<p>For example, <strong>Nepal → Kathmandu</strong> represents the same relationship as <strong>India → New Delhi</strong></p>
<p>Mathematically, we can write:</p>
<pre><code class="language-plaintext">Kathmandu − Nepal ≈ New Delhi − India
</code></pre>
<p>This doesn't mean the values are exactly equal. The symbol <strong>≈</strong> means <strong>approximately equal</strong>. It shows that both vectors represent a similar semantic relationship:</p>
<p><strong>Country → Capital City</strong></p>
<p>Similarly, moving from <strong>Nepal</strong> to <strong>India</strong> is somewhat similar to moving from <strong>Kathmandu</strong> to <strong>New Delhi</strong> because the concepts are related in a similar way.</p>
<p>Embeddings allow the model to understand both <strong>similarity</strong> and <strong>relationships</strong>, which is one of the reasons modern LLMs perform so well.</p>
<h3>Positional Encoding</h3>
<p>Embeddings tell the model <strong>what a word means</strong>, but they don't tell it <strong>where the word appears</strong> in the sentence.</p>
<p>Consider following two sentences:</p>
<p>Bipin loves coffee.<br />Coffee loves Bipin.</p>
<p>Both sentences contain exactly the same words. Without knowing the order of those words, the model would struggle to understand that the meanings are completely different.</p>
<p>This is where <strong>Positional Encoding</strong> comes in. Positional encoding adds information about the position of every token before it enters the Transformer. This helps the model understand not only the meaning of words but also their order.</p>
<h3>Self Attention</h3>
<p>One of the biggest innovations introduced by Transformers is the <strong>Self-Attention mechanism</strong>.</p>
<p>Some words have multiple meanings depending on the context.</p>
<p>NIC Bank<br />River Bank</p>
<p>Both sentences contain the word <strong>Bank</strong>, but the meaning is completely different.<br />How does the model know which meaning to choose? Ans: Self Attention</p>
<p>Self-attention allows every token to "look at" every other token in the sentence before deciding its meaning. In the first sentence , the word bank pays attention to NIC , similarly in second sentence Bank pays attention to River and the model can determine the correct meaning of the word based on its context.</p>
<p>Instead of processing words independently, every token exchanges information with the other tokens in the sentence. This allows the model to build a much richer understanding of the context.</p>
<p>This is why Transformers are so good at understanding language.</p>
<h3>Multi-head Attention</h3>
<p><strong>Multi-Head Attention</strong> simply means that the Transformer performs this attention process <strong>multiple times in parallel</strong>.</p>
<p>Each attention head can focus on a different type of relationship.</p>
<p>For example, in the sentence:</p>
<blockquote>
<p>"Bipin gave his book to Ram because he had finished reading it."</p>
</blockquote>
<p>One attention head might learn:</p>
<ul>
<li>Who <strong>he</strong> refers to.</li>
</ul>
<p>Another head might learn:</p>
<ul>
<li>What <strong>it</strong> refers to.</li>
</ul>
<p>Another might focus on:</p>
<ul>
<li>The grammatical structure.</li>
</ul>
<p>The outputs from all these attention heads are then combined, giving the model a richer understanding of the sentence than a single attention mechanism could provide.</p>
<h2>Feed Forward Network (FFN)</h2>
<p>After the attention mechanism gathers information from other tokens, the result passes through a <strong>Feed Forward Neural Network (FFN).</strong></p>
<p>You can think of the FFN as another processing step that refines the information learned by self-attention.</p>
<p>While self-attention helps a token understand its relationship with other tokens, the Feed Forward Network helps the model learn more complex patterns before passing the information to the next Transformer layer.</p>
<p>This process is repeated many times across multiple Transformer layers, gradually building a richer understanding of the input.</p>
<h2>Logits</h2>
<p>After the input passes through all the Transformer layers, the model still hasn't chosen the next token.</p>
<p>Instead, it produces a raw score for <strong>every token in its vocabulary</strong>.</p>
<p>These scores are called <strong>logits</strong>.</p>
<p>For example, suppose the prompt is:</p>
<pre><code class="language-plaintext">The capital of Nepal is
</code></pre>
<p>The model might produce something like:</p>
<table>
<thead>
<tr>
<th>Token</th>
<th>Logit</th>
</tr>
</thead>
<tbody><tr>
<td>Kathmandu</td>
<td>12.4</td>
</tr>
<tr>
<td>Pokhara</td>
<td>6.8</td>
</tr>
<tr>
<td>India</td>
<td>2.1</td>
</tr>
<tr>
<td>Banana</td>
<td>-3.7</td>
</tr>
</tbody></table>
<p>These numbers are <strong>not probabilities</strong>.</p>
<p>They simply represent how strongly the model believes each token could be the next one.</p>
<h3>Temperature</h3>
<p>Temperature controls <strong>how confident or random</strong> the model becomes. Instead of changing logits themselves it scales them</p>
<pre><code class="language-javascript">newLogit = logit/temperature

Where, 
    T = 1 → no change
    T &lt; 1 → more confident
    T &gt; 1 → more random
</code></pre>
<p>With a <strong>low temperature</strong> (for example <strong>0.2</strong>), the model almost always chooses the highest-probability token.</p>
<p>This makes the response more focused and predictable.</p>
<p>With a <strong>high temperature</strong> (for example <strong>1.2</strong>), the probabilities become more balanced, making it more likely that less probable tokens are selected.</p>
<p>As a result, responses become more creative, but they may also become less accurate.</p>
<h3>Softmax</h3>
<p>After temperature is applied we get the numbers but they are still not probabilities . The new logits are passed through a mathematical function called <strong>Softmax</strong>. It makes everything sum to exactly <strong>1</strong>.</p>
<p>Now we finally have a <strong>probability distribution</strong>.</p>
<p>A probability distribution is simply</p>
<blockquote>
<p><strong>the probability assigned to every possible next token.</strong></p>
</blockquote>
<p>Once the probability distribution is calculated, the model selects the next token. In many cases, it chooses the most probable token, although depending on the decoding strategy and temperature, it may also sample from several likely tokens. The selected token is appended to the input, and the entire process repeats until the response is complete.</p>
<h2>Putting Everything Together</h2>
<p>Let's see the complete journey of your prompt.</p>
<p>Suppose you ask ChatGPT:</p>
<blockquote>
<p><strong>Write a poem about Nepal.</strong></p>
</blockquote>
<p>The following steps happen:</p>
<ol>
<li><p>The text is broken into <strong>tokens</strong>.</p>
</li>
<li><p>Tokens are converted into <strong>Token IDs</strong> (Encoding).</p>
</li>
<li><p>Token IDs become <strong>Embeddings</strong>.</p>
</li>
<li><p><strong>Positional Encoding</strong> is added.</p>
</li>
<li><p>The Transformer processes the tokens using <strong>Multi-Head Attention</strong> and <strong>Feed Forward Networks</strong> across multiple layers.</p>
</li>
<li><p>The model generates <strong>Logits</strong> for every possible token.</p>
</li>
<li><p><strong>Temperature</strong> adjusts these logits.</p>
</li>
<li><p><strong>Softmax</strong> converts them into probabilities.</p>
</li>
<li><p>The next token is selected.</p>
</li>
<li><p>That token is appended to the sentence.</p>
</li>
<li><p>The process repeats until the response is complete.</p>
</li>
</ol>
<img src="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/38151fd5-65c5-45fe-b193-f473ed7adad3.png" alt="" style="display:block;margin:0 auto" />

<h2>Context Window</h2>
<p>An LLM doesn't only look at the last word you typed. It also considers a limited amount of previous conversation called the <strong>context window</strong>.</p>
<p>For example:</p>
<p>User:</p>
<blockquote>
<p>My name is Bipin.</p>
</blockquote>
<p>Later:</p>
<blockquote>
<p>What's my name?</p>
</blockquote>
<p>ChatGPT can answer <strong>Bipin</strong> because your earlier message is still inside its context window.</p>
<p>If the conversation becomes too long and earlier messages fall outside the context window, the model may no longer remember them.</p>
<h2>Training vs Inference</h2>
<p>Everything we've discussed so far happens during <strong>Inference</strong>, which is the phase we use when chatting with ChatGPT.</p>
<p>However, before the model can answer questions, it must first go through a <strong>Training Phase</strong>.</p>
<p>During training, the model is shown billions of examples of text.</p>
<p>Suppose the training sentence is:</p>
<pre><code class="language-plaintext">&lt;BOS&gt; Bipin is handsome &lt;EOS&gt;
</code></pre>
<p>Here:</p>
<ul>
<li><p><strong>BOS</strong> means Beginning of Sequence.</p>
</li>
<li><p><strong>EOS</strong> means End of Sequence.</p>
</li>
</ul>
<p>Initially, the model makes random predictions.</p>
<p>Instead of predicting <strong>handsome</strong>, it might predict something completely different.</p>
<p>The correct next token is called the <strong>label</strong>.</p>
<p>The model compares its prediction with the correct label using a mathematical function called <strong>Cross Entropy Loss</strong>, which measures how wrong the prediction is.</p>
<p>The larger the loss, the worse the prediction.</p>
<p>Using this loss, the model updates its internal parameters through <strong>backpropagation</strong>, allowing it to make better predictions in the future.</p>
<p>This process is repeated billions of times until the model becomes good at predicting the next token.</p>
<h3>Inference Phase</h3>
<p>Once training is complete, the model enters the <strong>Inference Phase</strong>.</p>
<p>This is the phase we use every day when interacting with ChatGPT.</p>
<p>During inference:</p>
<ul>
<li><p>No labels are provided.</p>
</li>
<li><p>No Cross Entropy Loss is calculated.</p>
</li>
<li><p>No backpropagation takes place.</p>
</li>
</ul>
<p>The model simply uses everything it learned during training to predict the next token.</p>
<h2>Conclusion</h2>
<p>Although ChatGPT may seem like magic, it follows a sequence of well-defined steps. Your prompt is first tokenized, converted into numerical representations, processed through multiple Transformer layers, and finally used to predict one token at a time until a complete response is generated.</p>
<p>The next time you ask ChatGPT a question, you'll know that it isn't searching a database for the answer—it is generating one token at a time using patterns learned during training.</p>
]]></content:encoded></item><item><title><![CDATA[Node.js Internals Explained in Simple Words]]></title><description><![CDATA[Node.js is a JavaScript runtime environment that allows JavaScript to run outside the browser. But internally, Node.js is not just JavaScript. It is built…]]></description><link>https://blog.bipinbhatt.com.np/node-js-internals-explained-in-simple-words</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/node-js-internals-explained-in-simple-words</guid><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Fri, 10 Apr 2026 07:32:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/fe0f0df4-749d-4b5b-b061-acb2b2f4d5cd.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>🧠 What is Node.js?</h2>
<p>Node.js is a <strong>JavaScript runtime environment</strong> that allows JavaScript to run outside the browser.</p>
<p>But internally, Node.js is not just JavaScript.</p>
<p>It is built using:</p>
<blockquote>
<p><strong>V8 Engine + libuv + C++ bindings</strong></p>
</blockquote>
<ul>
<li><p><strong>V8 Engine</strong> → Executes JavaScript code (turns JS into machine code)</p>
</li>
<li><p><strong>libuv</strong> → Handles asynchronous operations (event loop + thread pool)</p>
</li>
<li><p><strong>C++ bindings</strong> → Bridge between JavaScript and system (OS)</p>
</li>
</ul>
<h2>🏗️ Core Architecture of Node.js</h2>
<h3>1. Process (What happens when Node starts)</h3>
<p>When you run a Node.js file, a process is created.</p>
<p>A <strong>process</strong> means:</p>
<blockquote>
<p>A running instance of a program with memory, resources, and execution flow.</p>
</blockquote>
<p>Node.js also provides a built-in global object called <code>process</code>, which allows you to interact with the running process. Using this object, you can:</p>
<ul>
<li><p>Access environment variables (<code>process.env</code>)</p>
</li>
<li><p>Get process information like ID (<a href="http://process.pid"><code>process.pid</code></a>)</p>
</li>
<li><p>Handle process events (e.g., exit, signals)</p>
</li>
<li><p>Control execution (e.g., <code>process.exit()</code>)</p>
</li>
</ul>
<h3>2. Main Thread (Very Important Concept)</h3>
<p>Node.js runs on a <strong>single main thread</strong>.</p>
<p>This main thread is responsible for:</p>
<ul>
<li><p>executing JavaScript code</p>
</li>
<li><p>handling callbacks</p>
</li>
<li><p>managing the event loop</p>
</li>
<li><p>delegating heavy tasks</p>
</li>
</ul>
<p>👉 BUT it does NOT handle heavy work directly.</p>
<p>Instead, it delegates them to <strong>libuv thread pool</strong> or <strong>OS system APIs</strong>.</p>
<h2><strong>🔄 What happens inside the Main Thread?</strong></h2>
<p>When Node starts execution, it follows these steps:</p>
<h3>A. Project Initialization Phase</h3>
<p>Node loads your project:</p>
<ul>
<li><p>reads entry file (index.js / app.js)</p>
</li>
<li><p>initializes memory</p>
</li>
<li><p>prepares runtime environment</p>
</li>
</ul>
<h3>B. Top-Level Code Execution</h3>
<p>All synchronous code runs first:</p>
<ul>
<li><p>variable declarations</p>
</li>
<li><p>console logs</p>
</li>
<li><p>function definitions</p>
</li>
</ul>
<p>👉 This is the <strong>first execution phase</strong></p>
<h3><strong>C.</strong> Import / Module Loading Phase</h3>
<p>When you write:</p>
<pre><code class="language-plaintext">import fs from "fs";
</code></pre>
<p>Node does this:</p>
<h3>What happens internally:</h3>
<ul>
<li><p>Resolves module path</p>
</li>
<li><p>Loads built-in modules (fs, crypto, path, etc.)</p>
</li>
<li><p>Wraps your file inside a function scope</p>
</li>
<li><p>Executes module code BEFORE your main logic continues</p>
</li>
</ul>
<p>👉 That’s why imports are NOT random — they are resolved first.</p>
<h3>D. Callback Registration Phase</h3>
<p>At this stage:</p>
<p>Node sees async functions like:</p>
<ul>
<li><p>setTimeout</p>
</li>
<li><p>setImmediate</p>
</li>
<li><p>fs.readFile</p>
</li>
<li><p>Promises</p>
</li>
</ul>
<p>👉 It does NOT execute them immediately.</p>
<p>Instead, it:</p>
<blockquote>
<p>Registers them in the background system (event loop queues / thread pool / OS handlers)</p>
</blockquote>
<h3>E. Event Loop Starts</h3>
<p>After top-level code is done:</p>
<p>👉 libuv starts the event loop</p>
<p>Now Node continuously checks:</p>
<ul>
<li><p>timers</p>
</li>
<li><p>I/O operations</p>
</li>
<li><p>callbacks</p>
</li>
<li><p>thread pool results</p>
</li>
</ul>
<h2><strong>🔁 Event Loop Phases</strong></h2>
<h3>1. Timers phase(expired callbacks):</h3>
<p>This phase runs:</p>
<ul>
<li><p><code>setTimeout</code></p>
</li>
<li><p><code>setInterval</code></p>
</li>
</ul>
<p><em>Why called “expired callbacks”?</em></p>
<p>Because:</p>
<blockquote>
<p>Only timers whose delay has finished are executed here.</p>
</blockquote>
<p>If delay = 0 → it becomes eligible immediately, but still depends on event loop timing.</p>
<h3>2. I/O Polling Phase:</h3>
<p>I/O polling is the phase of the event loop where Node.js interacts with the background system to handle asynchronous operations. When tasks like file reading, crypto hashing, or DNS lookups are triggered, Node.js first delegates them to the libuv thread pool or OS, so the main thread doesn’t get blocked. During the polling phase, the event loop continuously checks whether these background tasks are completed, collects their results once they finish, and prepares their callbacks to be executed in the next appropriate phase of the event loop.</p>
<p>👉 Event loop does NOT do heavy work itself.</p>
<p>Instead:</p>
<ul>
<li><p>libuv thread pool does the work</p>
</li>
<li><p>event loop just <strong>waits + checks results</strong></p>
</li>
</ul>
<p>That waiting + checking is called:</p>
<blockquote>
<p><strong>I/O Polling</strong></p>
</blockquote>
<h3>3. setImmediate() Phase :</h3>
<p>The setImmediate() phase is the part of the event loop where Node.js executes all callbacks scheduled using <code>setImmediate()</code>. After the I/O polling phase finishes collecting results from background tasks, the event loop moves into this stage and runs these callbacks right away in the same iteration. This phase ensures that tasks scheduled with <code>setImmediate()</code> are executed immediately after I/O operations are completed, but before the event loop proceeds to handle close callbacks or begins the next loop cycle.</p>
<p><code>setImmediate()</code> is a Node.js function used to schedule a callback to run after the I/O polling phase of the event loop completes. It does not depend on time like <code>setTimeout</code>; instead, it depends on the event loop cycle. When <code>setImmediate()</code> is called, its callback is placed into the <strong>check queue</strong>, and it is executed in the same event loop iteration right after I/O tasks are finished.</p>
<h3>4. Close callback() phase :</h3>
<p>The Close Callback phase is the part of the event loop where Node.js executes callbacks that are triggered when certain resources are closed or cleaned up. This includes events like closing a socket, ending a file stream, or shutting down a connection. After all other phases like timers, I/O polling, and <code>setImmediate()</code> are completed, Node.js enters this phase to safely handle cleanup-related tasks so that resources are properly released before the event loop moves to the next iteration or exits if nothing is left to process.</p>
<p>example :</p>
<pre><code class="language-bash">socket.on("close", callback)
</code></pre>
<p>or</p>
<pre><code class="language-bash">process.on("SIGINT", () =&gt; {
  console.log("Ctrl + C pressed (SIGINT received)");
  console.log("Cleaning up before exit...");
  process.exit();
});

console.log("Running... Press Ctrl + C");
</code></pre>
<h3>5. Check for pending tasks :</h3>
<p>After each cycle:<br />Node checks:</p>
<ul>
<li><p>Is anything pending?</p>
</li>
<li><p>Any timer left?</p>
</li>
<li><p>Any I/O left?</p>
</li>
</ul>
<p>👉 If YES → next loop iteration<br />👉 If NO → process exits</p>
<p>After each event loop cycle, Node.js checks whether there is any pending work such as active timers, ongoing I/O operations, or open handles like servers and streams. If any of these exist, the event loop continues to the next iteration. If nothing is left, Node.js safely exits the process. <code>setImmediate()</code> is not directly part of this exit check; it is simply executed during the event loop cycle when reached.</p>
<h2>🧪 Example 1 (Basic Event Loop Understanding)</h2>
<pre><code class="language-javascript">import fs from "fs";

setTimeout(() =&gt; {
  console.log("inside setTimeout");
}, 0);

setImmediate(() =&gt; {
  console.log("inside setImmediate 1");
});

fs.readFile("sample.txt", "utf-8", function (err, data) {
  console.log("file read success");

  setTimeout(() =&gt; {
    console.log("inside setTimeout 2");
  }, 0);

  setTimeout(() =&gt; {
    console.log("inside setTimeout 3");
  }, 0);

  setImmediate(() =&gt; {
    console.log("inside setImmediate 2");
  });
});

console.log("top level code");
</code></pre>
<h2>🧠 Execution Explanation (Step by Step)</h2>
<p>Step 1: Top-level code runs first</p>
<p>Step 2: Timers &amp; Immediate are registered</p>
<p>They go into event loop queues:</p>
<ul>
<li><p>setTimeout → timer queue</p>
</li>
<li><p>setImmediate → check queue</p>
</li>
</ul>
<p>Step 3: File reading starts</p>
<ul>
<li><p>libuv thread pool handles it</p>
</li>
<li><p>main thread continues</p>
</li>
</ul>
<p>Step 4: Event loop begins</p>
<p>Order depends on phases:</p>
<p>Typical output:</p>
<pre><code class="language-plaintext">top level code
inside setTimeout
inside setImmediate 1
file read success
inside setImmediate 2
inside setTimeout 2
inside setTimeout 3
</code></pre>
<p>👉 BUT exact order can vary slightly depending on system timing.</p>
<h2>⚡ Example 2 (CPU Intensive + Thread Pool Deep Understanding)</h2>
<pre><code class="language-javascript">import fs from "fs";
import crypto from "crypto";

const start = Date.now();

// Thread pool size
process.env.UV_THREADPOOL_SIZE = 4;

setTimeout(() =&gt; {
  console.log("Hello from Timer");
}, 0);

setImmediate(() =&gt; {
  console.log("Hello from Immediate");
});

fs.readFile("sample.txt", "utf-8", function (err, data) {
  console.log("File Reading Complete");

  setTimeout(() =&gt; console.log("Time 2"), 0);
  setTimeout(() =&gt; console.log("Time 3"), 0);

  setImmediate(() =&gt; console.log("Immediate 2"));

  // CPU intensive tasks (thread pool)
  crypto.pbkdf2("password", "salt", 300000, 1024, "sha256", () =&gt; {
    console.log("Password 1 hashed", Date.now() - start);
  });

  crypto.pbkdf2("password", "salt", 300000, 1024, "sha256", () =&gt; {
    console.log("Password 2 hashed", Date.now() - start);
  });

  crypto.pbkdf2("password", "salt", 300000, 1024, "sha256", () =&gt; {
    console.log("Password 3 hashed", Date.now() - start);
  });

  crypto.pbkdf2("password", "salt", 300000, 1024, "sha256", () =&gt; {
    console.log("Password 4 hashed", Date.now() - start);
  });

  crypto.pbkdf2("password", "salt", 300000, 1024, "sha256", () =&gt; {
    console.log("Password 5 hashed", Date.now() - start);
  });
});

console.log("Hello from Top Level Code");
</code></pre>
<p><strong>🧠 What happens internally?</strong></p>
<ol>
<li>First 4 crypto tasks run in thread pool</li>
</ol>
<p>Because default pool size = 4</p>
<ol>
<li>5th crypto task waits</li>
</ol>
<p>Because no thread is free</p>
<ol>
<li>As soon as one finishes</li>
</ol>
<p>5th task starts</p>
<p>⚡ Key Insight</p>
<p>👉 Thread pool is like a small worker team 👉 If workers are busy → tasks wait in queue</p>
<h2>📦 Queues in Node.js Event Loop</h2>
<p>Node.js event loop has several important queues where different types of callbacks are stored before execution:</p>
<h3>1. ⏱️ Timer Queue:</h3>
<ul>
<li><p>Stores callbacks from setTimeout() and setInterval()</p>
</li>
<li><p>Runs when the timer duration has expired</p>
</li>
</ul>
<h3>2. 📡 I/O Queue (Poll Queue)</h3>
<ul>
<li><p>Stores callbacks from I/O operations like: file reading (fs) network requests database operations</p>
</li>
<li><p>These are executed after background tasks are completed</p>
</li>
</ul>
<h3>3.⚡ Check Queue</h3>
<ul>
<li><p>Stores callbacks from setImmediate()</p>
</li>
<li><p>Runs immediately after the I/O polling phase</p>
</li>
</ul>
<h3>4. 🔚 Close Queue</h3>
<ul>
<li><p>Stores callbacks for cleanup events</p>
</li>
<li><p>Example: socket close events stream close events</p>
</li>
</ul>
<h3>5. 🔁 Microtask Queue (Higher Priority)</h3>
<ul>
<li>Runs between phases:</li>
</ul>
<p>- process.nextTick() (highest priority)</p>
<p>- Promises (.then, .catch)</p>
<p>👉 Microtasks run before moving to the next queue</p>
<blockquote>
<p>Note: Different internal systems (like libuv’s timer system, thread pool, and OS) are responsible for pushing callbacks into their respective queues when they become ready, while the event loop’s job is simply to process and execute those callbacks phase by phase.</p>
</blockquote>
<h2>🧠 Who puts expired callbacks into queues?</h2>
<blockquote>
<p><strong>Node.js internal systems (libuv + timers system + OS) put callbacks into queues — NOT the event loop itself.</strong></p>
</blockquote>
<h3>1. Timers (<code>setTimeout</code>, <code>setInterval</code>)</h3>
<p>When you write:</p>
<pre><code class="language-plaintext">setTimeout(fn, 1000);
</code></pre>
<p>What happens:</p>
<ul>
<li><p>Node registers the timer and starts counting time</p>
</li>
<li><p>Internally, <strong>libuv maintains a timer system (like a timer list/heap)</strong></p>
</li>
</ul>
<p>👉 When time expires:</p>
<blockquote>
<p>libuv moves the callback into the <strong>timer queue</strong></p>
</blockquote>
<p>✔ Event loop did NOT do this<br />✔ libuv/timer system did it</p>
<h3>2. I/O operations (<code>fs</code>, network, crypto)</h3>
<p>When you write:</p>
<pre><code class="language-plaintext">fs.readFile("file.txt", fn);
</code></pre>
<p>What happens:</p>
<ul>
<li><p>Task goes to <strong>thread pool or OS</strong></p>
</li>
<li><p>Work happens in background</p>
</li>
</ul>
<p>👉 When task finishes:</p>
<blockquote>
<p>OS / libuv pushes the callback into the <strong>I/O queue</strong></p>
</blockquote>
<h3>3. setImmediate()</h3>
<pre><code class="language-plaintext">setImmediate(fn);
</code></pre>
<p>👉 This is simpler:</p>
<ul>
<li><p>Callback is directly placed into the <strong>check queue</strong> during registration</p>
</li>
<li><p>libuv stores the callback in the <strong>check queue</strong></p>
</li>
</ul>
<p>(No waiting, no background work)</p>
<h3>4. Close callbacks</h3>
<pre><code class="language-plaintext">socket.on("close", fn);
</code></pre>
<p>👉 When resource closes:</p>
<blockquote>
<p>Node pushes callback into <strong>close queue</strong></p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Setting up a Project with Express and TypeScript]]></title><description><![CDATA[first make a folder and npi init run tsc --init change root directory on tsconfig.json file :"rootDir": "./src","outDir": "./dist", (/dist = distributable…]]></description><link>https://blog.bipinbhatt.com.np/setting-up-a-project-with-express-and-typescript</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/setting-up-a-project-with-express-and-typescript</guid><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Thu, 09 Apr 2026 05:02:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/e3d5ee0c-d0a5-4bdb-80b6-5424b2363cf3.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3>Bare minimum Typescript Setup</h3>
<ol>
<li><p>first make a folder and <code>npi init</code></p>
</li>
<li><p>run <code>tsc --init</code></p>
</li>
<li><p>change root directory on <code>tsconfig.json</code> file :<br />"rootDir": "./src",<br />"outDir": "./dist",  </p>
<p>(/dist = distributable file)</p>
</li>
<li><p>to compile <code>tsc -p .</code> YOU NEED TO DO IT EVERY time you make some changes to your code</p>
</li>
<li><p>to run <code>node /dist/filename.js</code></p>
</li>
<li><p>make .gitignore file and add ( dist/, node_modules/ , .env)<br />and run <code>npx gitignore Node</code></p>
</li>
<li><p>even if you have typscript installed on your machine globally, it is good idea to instal typescript in your project too. (Better install as dev dependency)  </p>
<p><code>npm i typescript -D</code></p>
</li>
<li><p>to get rid of problem described in number 4 .. install<br /><code>npm i tsc-watch -D</code><br />and<br />set up a script dev as following:</p>
<pre><code class="language-json">"dev": " tsc-watch --onSuccess \"node dist/index.js\""
</code></pre>
</li>
<li><p>you can change</p>
<pre><code class="language-json">  "type": "module", //commonjs---&gt; module
</code></pre>
</li>
</ol>
<h3>Installing Express and Its Type Definitions in TypeScript</h3>
<p>After setting up your TypeScript , you usually install Express like this:</p>
<pre><code class="language-plaintext">npm install express
</code></pre>
<p><strong>But here’s the catch:</strong> if you try to use Express in your <code>.ts</code> files immediately, TypeScript will complain:</p>
<pre><code class="language-plaintext">Cannot find module 'express' or its corresponding type declarations.
</code></pre>
<p>This happens because <strong>Express is written in plain JavaScript</strong>, so TypeScript can’t automatically know the types of its functions, objects, or middleware.</p>
<p>There are two ways to fix this:</p>
<ul>
<li><p><strong>Write your own types</strong> – You can create type definitions (<code>.d.ts</code>) for the functions, objects, or methods you plan to use in Express. But this can be tedious.</p>
</li>
<li><p><strong>Install existing type definitions</strong> – The easier way is to use the community-maintained types from npm. Packages with the <code>@types/</code> prefix are exactly for this.</p>
</li>
</ul>
<pre><code class="language-plaintext">npm i @types/express -D
</code></pre>
<p>Here’s what happens when you run this:</p>
<ul>
<li><p>TypeScript now knows the structure of Express, including functions, request/response objects, and middleware.</p>
</li>
<li><p>Your editor (like VS Code) will give you <strong>autocomplete, hints, and error checking</strong> for Express code. any previous “Cannot find module” errors will disappear.</p>
</li>
</ul>
<p><strong>Pro tip:</strong> On the npm website, look at the <strong>top-right corner of the package name</strong>. If you see <code>DT</code> or <code>ts</code>, it means this package <strong>includes TypeScript type definitions</strong>.</p>
<p><strong>DT</strong> → comes from <strong>DefinitelyTyped</strong>, the community-maintained repository of type definitions.<br /><strong>ts</strong> → the package itself is written in TypeScript or includes its own types.</p>
<p>This is a quick way to check if a JavaScript library is TypeScript-ready before installing it.</p>
<h3>Node.js Type Definitions in TypeScript</h3>
<p>TypeScript doesn’t know the types of Node’s built-in modules (<code>fs</code>, <code>http</code>, <code>path</code>, etc.) by default. To fix this, install the Node type definitions:</p>
<pre><code class="language-plaintext">npm i -D @types/node
</code></pre>
<p>This lets TypeScript understand Node modules and provides <strong>autocomplete, hints, and error checking</strong> in your editor.</p>
]]></content:encoded></item><item><title><![CDATA[Introduction to Node.js]]></title><description><![CDATA[Node.js is widely known for its speed and non-blocking nature, but under the hood, it relies on a few powerful components that make all of this possible…]]></description><link>https://blog.bipinbhatt.com.np/introduction-to-node-js</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/introduction-to-node-js</guid><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Wed, 08 Apr 2026 04:18:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/51299728-99a9-4956-bb4f-9ec615e0a783.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Node.js is widely known for its speed and non-blocking nature, but under the hood, it relies on a few powerful components that make all of this possible. The three most important ones are the <strong>V8 Engine</strong>, <strong>libuv</strong>, and <strong>Node.js bindings</strong>.</p>
<p>Before diving into these components, it’s important to understand how JavaScript itself is executed.</p>
<h2>🧠 How JavaScript Executes Inside Node.js</h2>
<p>JavaScript execution is often misunderstood as simply being parsed and executed line by line. While parsing does happen first to check for syntax errors, modern engines like the V8 Engine go a step further.</p>
<p>After parsing the code and generating an internal structure (AST), V8 uses <strong>Just-In-Time (JIT) compilation</strong> to convert JavaScript into machine code. This allows the code to run much faster compared to traditional interpreted languages.</p>
<p>Execution then takes place using mechanisms like the <strong>call stack</strong> and <strong>memory heap</strong>, where functions are executed as they are invoked, rather than strictly following a simple top-to-bottom flow.</p>
<blockquote>
<p>In short, JavaScript is neither purely interpreted nor purely compiled—it uses JIT compilation, combining the best of both worlds.</p>
</blockquote>
<h2>1. 🔥 V8 Engine: Executing JavaScript at High Speed</h2>
<p>The V8 engine, developed by Google, is responsible for running JavaScript code in Node.js.</p>
<p>It uses <strong>Just-In-Time (JIT) compilation</strong>, which means it converts JavaScript directly into machine code at runtime instead of interpreting it line by line. This makes execution extremely fast.</p>
<blockquote>
<p>When you write JavaScript in Node.js, V8 is the component that actually runs it.</p>
</blockquote>
<p>V8 also manages:</p>
<ul>
<li><p><strong>Heap memory</strong> (for storing objects)</p>
</li>
<li><p><strong>Call stack</strong> (for tracking function execution)</p>
</li>
</ul>
<p>However, V8 has its limits. It does <strong>not</strong> handle:</p>
<ul>
<li><p>File system operations</p>
</li>
<li><p>Network requests</p>
</li>
<li><p>Timers</p>
</li>
</ul>
<p><strong>In short:</strong><br />👉 V8 executes JavaScript and manages memory, but knows nothing about async tasks.</p>
<h2>2. 🔄 libuv: The Backbone of Asynchronous Behavior</h2>
<p>While V8 executes code, it does not handle asynchronous operations like file reading, network requests, or timers. That responsibility is handled by <strong>libuv</strong>.</p>
<p>It is libuv is a C library that is responsible for</p>
<ul>
<li><p><strong>Event loop</strong> (core of async behavior)</p>
</li>
<li><p><strong>Thread pool</strong> (for handling heavy tasks)</p>
</li>
<li><p><strong>OS-level asynchronous I/O</strong> (files, network, etc.)</p>
</li>
<li><p><strong>DNS lookups</strong></p>
</li>
</ul>
<p>Node.js is single-threaded by design, but thanks to libuv, it can handle multiple operations at the same time without blocking the main thread.</p>
<p>For example, when you read a file or make an API call, libuv interacts with the operating system and processes the task without blocking the main thread.</p>
<p><strong>In short:</strong><br />👉 libuv handles everything V8 cannot—especially async operations.</p>
<h2>3. 🔗 Node.js Bindings: The Bridge to the System</h2>
<p>JavaScript alone cannot directly interact with low-level system operations like file systems or networking. This is where <strong>Node.js bindings</strong> come in.</p>
<p>Bindings are written in C/C++ and act as a bridge between JavaScript and the underlying system libraries (including libuv).</p>
<p>When you use built-in modules like <code>fs</code> or <code>http</code>, you are indirectly using these bindings. They pass your JavaScript requests to the system and bring the results back.</p>
<p><strong>In short:</strong><br />👉 Bindings = Connect JavaScript with system-level operations</p>
]]></content:encoded></item><item><title><![CDATA[Scopes and Hoisting in JavaScript]]></title><description><![CDATA[Hoisting is a behavior of JavaScript that moves the declaration of variable and function to the top of their respective scope. As we know, let and const…]]></description><link>https://blog.bipinbhatt.com.np/scopes-and-hoisting-in-javascript</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/scopes-and-hoisting-in-javascript</guid><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Mon, 06 Apr 2026 04:59:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/d8d2cfb9-ee2a-4c01-9894-0c986c0b0bcc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hoisting is a behavior of JavaScript that moves the declaration of variable and function to the top of their respective scope.</p>
<p>As we know, let and const are block-scoped and variable is function-scoped. Let's talk about scope let, var, and const</p>
<ol>
<li><p>Let : <code>let</code> gives block scope. Variable declared with let have block scope, meaning they are only accessible within the block in which they are declared. <code>let</code> prevents redeclaration within the same scope, reducting errors.  </p>
</li>
<li><p>var : <code>var</code> is function-scoped, meaning a variable declared with var is accessible within the function it is declared in , or globally if declared outside any function. When declared outside any function, a <code>var</code> variable becomes a global variable.</p>
</li>
<li><p>const : Like <code>let</code>, const is block scoped. It does not allow ressaiging. While const prevents reassigning a value to a variable, it does not prevent modifying the contents of objects or arrrays. This is because const is applied to the binding( the reference) of the variable not the data stored in the object and array.</p>
</li>
</ol>
<h2>Hoisting</h2>
<p>We talked in the previous blog that all code is scanned, and every variable and function is loaded into memory during the memory phase.</p>
<p><code>var</code> declarations are hoisted to the top of their scope with values undefined. This means you can reference the variable before its declaration, but it will return <code>undefined</code> until it is assigned a value.</p>
<pre><code class="language-bash">console.log(x)//undefined
var x = 20
console.log(x)//20
</code></pre>
<h3><em><mark class="bg-yellow-200 dark:bg-yellow-500/30">NOTE: Only the declaration is hoisted, not the initialization.</mark></em></h3>
<p><code>let</code> and <code>const</code> are loaded to the memory phase, but they remain uninitialized and stay in the Temporal Dead Zone (TDZ) until their declaration is executed.</p>
<p>Temporal Dead Zone:<br />It is the period between when a variable is hoisted and when it is declared. During this time accessing the variable results reference error.</p>
<ul>
<li><p>This only occrus with the let and const.</p>
</li>
<li><p>Starts at the befinning of the block and ends when the variable is initialized.</p>
</li>
<li><p>Prevents the use of variable before declaration, avoiding unintended behavior.</p>
</li>
</ul>
<blockquote>
<p>let and const variable are hoisted but stay in the TDZ until the declaration is reached.</p>
</blockquote>
<pre><code class="language-bash">console.log(x)// throws reference errror(TDZ)
consoel.log(y) // says variable is not declared
let x// TDZ ends here

console.log(x)// throws undefined

x = 5 

console.log(x) // print 5
</code></pre>
<p>So if someone ask you if <code>let</code> and <code>const</code> are hoisted in JavaScript?<br />Say :<br />Yes they are hoisted , but unlike var they remains in the TDZ until their declaration. This means you can not access them before the declaration or you will get a reference error.</p>
<p>In case of functions, tfunctions are fully hoisted. Maybe clarify:</p>
<ul>
<li><p><code>function foo() {}</code> → fully hoisted (callable before definition)</p>
</li>
<li><p><code>var foo = function() {}</code> → behaves like <code>var</code>, only the variable is hoisted, not the function body.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Understanding Execution Context  in JS]]></title><description><![CDATA[You are here means you must have written some code in JavaScript and have seen your code do magic-like things. But have you ever wondered what happens…]]></description><link>https://blog.bipinbhatt.com.np/understanding-execution-context-in-js</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/understanding-execution-context-in-js</guid><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Wed, 01 Apr 2026 07:25:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/73ab0561-4676-433e-8bd3-7b2b3e7d388b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You are here means you must have written some code in JavaScript and have seen your code do magic-like things. But have you ever wondered what happens behind the scenes when your code runs?<br />Let's try to get it.</p>
<h2>What is the Execution Context?</h2>
<p>JavaScript first prepares the workspace/container/environment that holds all the information needed for JavaScript to run the piece of code. That environment is called the execution context.</p>
<ul>
<li><p>Global context: It is the default context when code runs outside any functions. Or we can say the global code runs in this execution context.</p>
</li>
<li><p>Local Execution Context: Every time a function is called, a new execution context (local execution context) is created and pushed onto the call stack. It has its own memory location for the variable and the functions declared inside the function. This context is removed after the execution of the function</p>
</li>
</ul>
<h2>Execution Context Phases</h2>
<img src="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/d64c02c0-9c20-473b-8b6f-1dbebbe624e4.png" alt="" style="display:block;margin:0 auto" />

<p><img src="align=%22center%22" alt="" /></p>
<h3>1. Memory Phase</h3>
<blockquote>
<p>setting up your tools on a desk</p>
</blockquote>
<p>This is the first phase where JavaScript sets up the environment for your code before actually running it. The memory phase is also known as the creation phase.</p>
<p>JavaScript scans all code before executing it. All variables are loaded into memory with the value "undefined," and functions are stored with their full definitions(<em><mark class="bg-yellow-200 dark:bg-yellow-500/30">fully hoisted)</mark></em>.</p>
<p>In the above example, the name variable is loaded in the memory with the value "undefined". And the greet function is loaded with the full definition. This is why we can access the function before its declaration. This concept is called <a href="https://blog.bipinbhatt.com.np/scopes-and-hoisting-in-javascript">hoisting</a> in JavaScript.</p>
<h3>2. Code Execution Phase</h3>
<blockquote>
<p>actually using the tools to do the work</p>
</blockquote>
<p>Now JavaScript starts running your code line by line. This is where values are assigned, expressions are evaluated, and functions are called.</p>
<p>What happens here:</p>
<ul>
<li><p>Variables get their assigned values.</p>
</li>
<li><p>Function calls create new local execution contexts, which are pushed onto the call stack.</p>
</li>
<li><p>Code executes in order.</p>
</li>
</ul>
<p>Let's see the table for how the code in the above figure works.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/9b80b0d0-ded8-4006-920c-d2b6e5d6af71.png" alt="" style="display:block;margin:0 auto" />

<p>JavaScript first prepares memory and then executes code. Understanding these two phases makes it easier to follow how your code runs.</p>
<p>Now that you know this, you’re ready to dive deeper into JavaScript!</p>
<p>Read more about hoisting in this blog : <a href="https://blog.bipinbhatt.com.np/scopes-and-hoisting-in-javascript">scope and hoisting in js</a></p>
]]></content:encoded></item><item><title><![CDATA[Before you write the code in JS]]></title><description><![CDATA[Here’s a simple fact: Programming is all about: What we should do with what? a. Data (numbers, text, true/false…) b. Processing (loops, functions, etc.)…]]></description><link>https://blog.bipinbhatt.com.np/before-you-write-the-code-in-js</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/before-you-write-the-code-in-js</guid><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Tue, 31 Mar 2026 04:22:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/ec2ae1e9-266f-403f-b3ff-d1262a4a3f57.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here’s a simple fact:</p>
<p>Programming is all about:</p>
<blockquote>
<p><strong>What we should do with what?</strong></p>
<p>a. Data (numbers, text, true/false…)</p>
<p>b. Processing (loops, functions, etc.)</p>
</blockquote>
<img src="https://cdn.hashnode.com/uploads/covers/696bb2f4eedaf078a34da0eb/228aa0fe-a065-4377-b51b-bf1ee09ee24e.png" alt="" style="display:block;margin:0 auto" />

<p>Let's talk about terminologies:</p>
<ol>
<li><p><strong>Data type:</strong> Data types are like labels that tell the computer what kind of value a variable holds. They define<br />a. What kind of data can be stored (numbers, text, true/false, etc.)<br />b. What operations can be done on that data</p>
</li>
<li><p><strong>Context:</strong> It is the environment in which a piece of code runs. It consist of :<br />a. execution thread and<br />b. memory</p>
</li>
<li><p><strong>Global Context:</strong> This is the default context when code runs outside any function. In browsers, this in global context refers to the window object. Variables and functions declared globally belong to this context.</p>
</li>
<li><p><strong>Local Context:</strong> When code runs inside a function, it has a local context.</p>
</li>
<li><p><strong>Execution Thread :</strong> An execution thread is the part of the JavaScript engine that runs your code line by line. It is like the “worker” that executes instructions in your program.<br />Main thread and local exectuion thread are it's type.. based on the context.</p>
</li>
<li><p><strong>Call stack:</strong> It is a structure in js that keeps track of funcitons. When function is encountered by exectuion thread(main thread), it pushes the function in to the stack. This call stack works in LIFO manner. After the execution function is popped out.</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Git for Beginners: Basics and Essential Commands]]></title><description><![CDATA[This blog is about most popular version control system: git.]]></description><link>https://blog.bipinbhatt.com.np/git-for-beginners-basics-and-essential-commands</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/git-for-beginners-basics-and-essential-commands</guid><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[version control]]></category><category><![CDATA[Git Commands]]></category><category><![CDATA[github-actions]]></category><category><![CDATA[Gitcommands]]></category><category><![CDATA[git-init]]></category><category><![CDATA[git rebase]]></category><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Fri, 30 Jan 2026 08:22:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769761215826/8a3e3fb6-e6ae-4b2b-9dfb-f707d8ed559c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction-what-is-git">Introduction: What is git?</h2>
<p>Git is a version control system. It helps developers to track changes in files. It tracks all the information like: who changes the code, what changes are done, when the changes are done. It also lets you revert any changes if needed. Git uses diffing algorithm to track changes. Git enables developers to work on same project independently without breaking others code. Git allows every user to have the local copy of the repository(so that we call it distriubuted)</p>
<p>we use platform like github, gitlab,bitbucket, aws code commit, azure, git tea etc to store our local repository on the internet and enable collaboration with other developers.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769402333626/5ea9f70d-a4e2-4044-8998-b44df3642a85.png" alt /></p>
<h2 id="heading-why-git-is-used">Why git is used?</h2>
<p>Git is used because it solves the real problems of developers:</p>
<ul>
<li><p>Keep track of every change in code(when it is made, who made it)</p>
</li>
<li><p>Provide better collaborative environment</p>
</li>
<li><p>Prevents code loss</p>
</li>
<li><p>Helps to roll back if you realised the change was a mistake.</p>
</li>
</ul>
<h2 id="heading-how-to-install-git">How to install git?</h2>
<p>To get started with git, we need to install git in our machine first</p>
<p><strong>For windows:</strong><br />visit the officail git website: <a target="_blank" href="https://git-scm.com/install/windows">https://git-scm.com/install/windows</a></p>
<p>Download the latest installer (64-bits is recommended) and run it.</p>
<p><strong>For MacOs:</strong> install home brew if not already and then run following command</p>
<p><code>brew install git</code></p>
<p>After installing git successfully, you need to set your email address and username. This is important because git commit willl use this information and permanently save in the commits you create.</p>
<p><code>git config --global</code> <a target="_blank" href="http://user.name"><code>user.name</code></a> <code>"Your Name"</code><br /><code>git config --global</code> <a target="_blank" href="http://user.email"><code>user.email</code></a> <code>"</code><a target="_blank" href="mailto:youremail@example.com"><code>youremail@example.com</code></a><code>"</code></p>
<p>In this , —global means your information will be used by all the repository in your machine.</p>
<p>Make sure by running command below:</p>
<p><code>git config --list</code></p>
<p>this will show something like this:</p>
<p><a target="_blank" href="http://user.name"><code>user.name</code></a><code>="Your Name"</code> <a target="_blank" href="mailto:user.email=bipinbhatt280@gmail.com"><code>user.email=</code></a><code>"your email address”</code></p>
<p>Now every commit you create will contain your your name and email address as author.</p>
<h2 id="heading-git-core-terminologies">Git core terminologies</h2>
<ol>
<li><p><strong>Repository</strong></p>
<p> Any project maintained by git is called repository. A repository is the main project folder that git tracks. Every changes in the files inside this folder. This folder contains project files, git history and the branch information. Once we run <code>git init</code> command, git starts tracking changes on our files and the folder becomes repository.</p>
</li>
<li><p><strong>Commit</strong></p>
<p> Commit is the snapshot of your code at a point of time. It has a unique id(hash) and message. Or we can say any version of your project is a commit. If you permanenlty save your changes to your project with git, it is a commit. You basically move changes in your staging area to the repository area, that’s a commit. To move you use <code>git commit -m “message to explain the change”.</code></p>
</li>
<li><p><strong>Branch</strong></p>
<p> When many developer works on the same project or even when you are working on new feature by yourself, you do not want to break your code, then you use soemthing called branch. Branch is a independent and separate line of development in your repository. It allows developers to work on new feature , bug fix etc without affecting the main version or stable version. Once your work is done you have to merge it into the default branch i.e. master or main.</p>
</li>
<li><p><strong>Head</strong></p>
<p> Head is a pointer that points to the current branch you are working on and the latest commit on that branch. When you make new commit, head updates HEAD to point to the new commit. You can move HEAD to a different branch or commit using <code>git checkout</code> or <code>git switch</code>.</p>
</li>
<li><p><strong>Remote</strong></p>
<p> Remote refers to the online-hosted version of your repository. It allows many developers to collab and share changes. Default remote name is usually ‘origin’.</p>
<p> You can run:</p>
<p> <code>git remote -v</code> shows the remote repository linked to your local repository.</p>
<p> <code>git remote add &lt;any_name_(origin is default)&gt; &lt;url&gt;</code> to add new remote repository to your local repository</p>
<p> Similary you can remove and rename too.</p>
<p> After adding remote repo to your local repository , you push your commits over there.<br /> <code>git push -u origin main</code></p>
<p> <code>-u</code> sets <code>origin</code> as the default so future <code>git push</code> commands can be run without specifying it.(<code>-u</code> sets the default remote and branch for your local branch, so you don’t have to type the remote and branch every time you push or pull.)</p>
</li>
<li><p><strong>Clone</strong></p>
<p> Clone is used to copy the remote repository to your local machine.</p>
<p> <code>git clone &lt;repo_url&gt;</code></p>
<p> This creates local repository with all the commits, files, and branches for the remote repository and allow you to work on the project locally.</p>
</li>
<li><p><strong>Merge</strong></p>
<p> Merge is the process of combining changes from one branch into another, usually merging a feature or bug-fix branch into the main branch. Git automatically integrates the changes, but if the same lines were edited in both branches, you may need to resolve conflicts manually. After merging, the target branch contains all commits from both branches, preserving their history.</p>
<p> <code>git checkout main</code> // swich to main branch(where you wanna merge other branch)</p>
<p> <code>git merge &lt;brancName&gt;</code> // this will merge</p>
</li>
<li><p><strong>Push</strong></p>
<p> Push refers to sending commits you did on the local repository to the remote repository so that other can see and access the change.</p>
</li>
<li><p><strong>Pull</strong></p>
<p> Let's say some collaborator to your project added some code on the remote repository and you want sync your local repository with the new changes, for doing this we need to download the repository changes. We can do it using the <code>git pull origin main</code> command.</p>
</li>
</ol>
<h2 id="heading-three-areas-in-git">Three areas in Git</h2>
<p>To maintains our files git uses three areas:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769407179161/a599b683-34a4-4394-82a5-82ff562406d3.png" alt /></p>
<h3 id="heading-1-working-area">1. Working Area</h3>
<p>Wokring area or working directory is the actual folder that we are writing code on. This is where we write code, make changes or delte files. Once we run <code>git init</code> command on this folder, git starts tracking changes on our files. Git just notices the changes does not save them in its history yet.</p>
<h3 id="heading-2-staging-area">2. Staging Area</h3>
<p>Working area is where we write, edit code. Once git notices these all changes if we decided to save the change, git put those changes in the staging area. Git does not do it automatically we have to run <code>git add &lt;filename&gt;</code> or if you want all the changes <code>git add .</code> . Any changes if file/files present in this area are those which wil be part of next version/commit*(in the world of git version is also referred as commit).*</p>
<h3 id="heading-2-repository-area">2. Repository Area</h3>
<p>Repository area or local repository where we hve those changes which are already part of some earlier vesion. When the files in the staging area are committed using the <code>git commit</code> command, Git stores those changes in the repository along with a commit message, date, and unique commit ID.</p>
<p>Read about git command <a target="_blank" href="https://blog.bipinbhatt.com.np/git-commands">here</a></p>
]]></content:encoded></item><item><title><![CDATA[Why Version Control Exists: The Pendrive Problem]]></title><description><![CDATA[This blog is about the need of version control systems.]]></description><link>https://blog.bipinbhatt.com.np/why-version-control-exists-the-pendrive-problem</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/why-version-control-exists-the-pendrive-problem</guid><category><![CDATA[Why Version Control Exists: The Pendrive Problem]]></category><category><![CDATA[versioncontrol]]></category><category><![CDATA[Git]]></category><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Fri, 30 Jan 2026 08:14:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769760837723/c819995e-7259-4781-9024-401387bf597f.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-why-version-control-exists">Why version control exists?</h2>
<p>let’s suppose you have a song lyrics file. Now you want to change one verse. You keep changing a lot of times. But after some time, you realise that the older one was better. So what will you do? nothing but regret. Cause you don’t have backup and history of the change.</p>
<p>Now one of your friends says, <em>“ let’s do this song together.”</em> And ask you for lyrics file to write his lyrics on. How would you give that to him ?I believe, you will either send it via email / whatsApp or you copy file in a pendrive and give him pendrive. Imagine,</p>
<ul>
<li><p>One good line got triggered on your mind and you want to add that right now on the file. You can not do it because file is with him.</p>
</li>
<li><p>He does not write his lyrics but modified yours too.</p>
</li>
<li><p>He records the song himself that it’s his own song. You will lose the ownership**.**</p>
</li>
</ul>
<p>This is problematic, right?</p>
<p>So, this is where version control comes into the picture. Version control is a system that</p>
<ul>
<li><p>keeps track of all the changes in your files(l<em>ike: when changes are made, who made the changes</em>)</p>
</li>
<li><p>allows Multiple people collaborate independently.</p>
</li>
<li><p>allows you to rollback to the previous version if needed</p>
</li>
</ul>
<h2 id="heading-the-pendrive-analogy-in-software-development">The Pendrive Analogy in Software Development</h2>
<p>Before version control came into the picture, developers used to write code back then too. They used to use pendrive. Pendrive used to be shared among all the developer in the team. So typical workflow used to be like this:</p>
<ul>
<li><p>Developer A writes code</p>
</li>
<li><p>Copies it to a pendrive</p>
</li>
<li><p>Gives it to developer B</p>
</li>
<li><p>B edits the same file</p>
</li>
<li><p>Copies it back to the pendrive</p>
</li>
<li><p>gives it to developer</p>
</li>
</ul>
<p>It’s look simple but if B can overwirte the codes and there will be no history for that. They don’t wanna take risk they used to make copies. B will make a new version instead updating it so that they can track changes later. That led to name project like final, final, final_real, final_actual_real. This can cause a lot of confusions to get which is the final.</p>
<p>To solve all these kind of issues, version control is used.</p>
]]></content:encoded></item><item><title><![CDATA[How DNS Resolution Works?]]></title><description><![CDATA[This blog is about what is DNS, how does it map domain name to IP address.]]></description><link>https://blog.bipinbhatt.com.np/how-dns-resolution-works</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/how-dns-resolution-works</guid><category><![CDATA[tiktok-banned-in-nepal]]></category><category><![CDATA[dns]]></category><category><![CDATA[dns resolver]]></category><category><![CDATA[#DNS Resolution]]></category><category><![CDATA[dns-records]]></category><category><![CDATA[dns server]]></category><category><![CDATA[Domain Name System]]></category><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Fri, 30 Jan 2026 08:06:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769760348076/ec63bf1b-0ee3-4702-8cec-60fea4652758.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-problem-without-dns">Problem without DNS</h2>
<p>Before I start, I expect you to have basic understanding of IP addresses. You know, they are just numerical label that is given to each devices in a computer network to uniquely identify them, right?</p>
<p>So, let suppose I wanna talk to a web server. I must have the IP address of that server right? So basically if I wanna access anything in the internet(network of computer network) I must need to know the IP addresses. Wait, wouldn’t this gonna give you a headache? Internet is suppose to make your life easier now it is making you remember lots of things.</p>
<h2 id="heading-solution-before-dns">Solution before DNS</h2>
<p>To solve this, computers started using a hosts.txt file to map hostname to IP address. It was manual text file stored in each computer(you can still finds that file : etc/hosts).</p>
<p>It looks sth like:</p>
<pre><code class="lang-bash">192.168.1.10        server1
192.168.03.12       server2
</code></pre>
<p>This file was manually maintained/ updated by system administrators. Even today, every computer still has a hosts file. It’s mainly used for testing or blocking websites.</p>
<h2 id="heading-dns">DNS</h2>
<p>As you know more manual work quickly become problem. And we know every problem has a solution(either it’s already found or we will have to… haha). Don’t worry somebody has already found the solution.<br />Do you remember every contact numbers that you have in your phone? Hell No. Then what you do? you just open phonebook and type name and you can get number and make a phone call.</p>
<p>So there is something named DNS that is like the phonebook of the internet.</p>
<p>DNS is distributed(<em>no single server controls DNS, it’s spread across many servers worldwide</em>), robust(<em>keeps working even some servers fail</em>) and scalable(<em>can handle billions of request</em> ) system of the interne. It translates human-readable domain names like(<code>www.google.com</code>) into IP address that computers use to communicate. Without DNS we would have to remember IP address for every website.</p>
<p><strong>DNS does note exist to serve browsers. Browers are just one of its users. Email, security, cloud, verification all use DNS</strong></p>
<p><strong><mark>DNS tells you who should you talk to next.</mark></strong></p>
<p>But DNS does not only translate the human readable domain names to an IP address. It does much more than that:</p>
<ul>
<li><p>translates domain names into IP addresses.</p>
</li>
<li><p>Guides your request to the correct server across the internet.</p>
<p>  ex. Your browser asks DNS for <code>cs.harvard.edu</code> → DNS tells which authoritative server to contact.</p>
</li>
<li><p>Directs emails to the right mail servers (MX records)</p>
<p>  ex. Sending email to example@mail.com → DNS points to Gmail’s mail servers</p>
</li>
<li><p>Handles subdomains and organizes services</p>
<p>  ex. cs.harvar.edu .. cs is subdomain</p>
</li>
<li><p>Supports load balancing and faster content delivery (CDNs)</p>
<p>  ex. www.netflix.com DNS may give IP of the nearest server to your location.</p>
</li>
<li><p>Caches results to make internet access faster</p>
<p>  ex: Visiting www.youtube.com again → your local DNS cache returns IP instantly</p>
</li>
</ul>
<h2 id="heading-dns-hierarchy">DNS Hierarchy</h2>
<p>DNS hierarchy is the structured organization of domain servers. It is tree like structure starting from root server branching down to subdomain. This structure makes DNS distributed, robust and scalable.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769755682860/9e791fdf-86a1-49c0-8d6f-d36269848075.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769754352216/9c5a1208-e769-4e30-a870-e7bc64dc7ea3.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-1-root-server">1. Root Server</h3>
<p>This is the top most level in the DNS system. This is the first POC(point of contact). Root servers know the location of all TLD(top-level domains) servers. There are 13 root server groups globally(with many copies). So in reality, there are <strong>hundreds of physical root server instances worldwide</strong>, but <strong>only 13 logical root servers</strong> from the DNS perspective.</p>
<p>This is the top most level in the DNS system. There are the first POC(point of contact). Root serves know the location of all TLD(top level domains) servers. There are 13 root server groups globally(with many copies). So in reality, there are <strong>hundreds of physical root server instances worldwide</strong>, but <strong>only 13 logical root servers</strong> from the DNS perspective.</p>
<h3 id="heading-2-top-level-domain">2. Top Level Domain</h3>
<p>TLD is the last part of the domain name that comes after the last dot(.). TLD servers manages domains under specific TLD like .com, .edu, .org etc.</p>
<p>Example: .edu TLD server knows where the <code>cs.harvard.edu</code>’s authoritative server is.</p>
<p>.edu is Top level deomain</p>
<p>.edu’s <strong>TLD server</strong> doesn’t know the exact IP of <code>cs.harvard.edu</code> itself.<br />But it <strong>knows which server is authoritative for</strong> <code>harvard.edu</code> (the second-level domain).</p>
<h3 id="heading-3-second-level-domain">3. Second level Domain</h3>
<p>The second-level domain is the part of a domain name that comes directly before the top-level domain (TLD). It is usually the name of organization, company etc.</p>
<p>Second level domain’s authoritative server stores the actual DNS record for this domain.</p>
<p><code>harvard.edu</code> → <code>harvard</code> is second level domain and <strong>.</strong><code>edu</code> is the TLD</p>
<p>Authoritative server for second level domain is where DNS records live.</p>
<h3 id="heading-4-sub-domain">4. Sub Domain</h3>
<p>A subdomain is a part of a domain that comes before the second-level domain.<br />It is used to organize different sections or services of a website and can have its own DNS records.<br />If needed, it can also have its own authoritative server, separate from the main domain.</p>
<p><code>cs.harvard.edu</code> → <code>cs</code> is the <strong>subdomain</strong> of <code>harvard.edu</code> (second-level domain) with <code>.edu</code> as the TLD.</p>
<p>Subdomains let you divide or manage a domain without buying a new domain.</p>
<h2 id="heading-dns-resolution">DNS Resolution</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769758618989/c9943ed4-e5ea-469e-a6a1-96af7f1020e0.png" alt class="image--center mx-auto" /></p>
<p>when you type <code>google.com</code> in browser, what happens actually? let’s discuess</p>
<h3 id="heading-1-check-hosttxt-file">1. Check host.txt file</h3>
<p>Your computer first checks the <strong>hosts file</strong> (already discussed above) If it finds an entry here (for <code>google.com</code> <strong>→ ip address</strong>), it skips all other steps and uses this IP.</p>
<h3 id="heading-2-query-initiation">2. Query Initiation</h3>
<p>Now, your computer or device verifies its local DNS cache to see if it already has the IP address corresponding to <strong><mark>google.com</mark></strong> . If it doesn't have the IP address, the DNS resolution process begins.</p>
<h3 id="heading-3-recursive-dns-server">3. Recursive DNS Server</h3>
<p>Next, your computer sends a query to a recursive DNS server, often provided by your internet service provider or a public DNS resolver like Google Public DNS. These servers are responsible for carrying out DNS resolution on behalf of the client. This is the point of contact. Recursive DNS server <mark>first check its local cache</mark> .</p>
<p><em><mark>If you are from Nepal, do you remember Nepal once banned tiktok. The authorities did not block TikTok’s IP addresses directll but they blocked access only at the DNS level. This means that the ISPs’ DNS servers refused to translate TikTok’s domain name (like www.tiktok.com) into its corresponding IP address, making it impossible for users to reach the site using default settings. However, users who switched to public DNS servers such as Cloudflare’s </mark></em> <code>1.1.1.1</code> <em><mark>or Google’s </mark></em> <code>8.8.8.8</code> <em><mark>were still able to access TikTok, because these DNS servers could resolve the domain normally. In other words, the ban affected only the domain resolution at the ISP DNS level and did not block the actual TikTok servers or their IP addresses.</mark></em></p>
<h3 id="heading-4-dns-hierarchy">4. DNS Hierarchy</h3>
<p>If the recursive DNS server doesn't have the IP address for the <code>google.com</code> either, it initiates the DNS resolution process by sending a request to the root DNS servers. These servers are critical to the DNS infrastructure and store a list of the top-level domain (TLD) servers for each domain extension like .com, .org, .net, etc. g1 TLD servers: The root DNS servers respond to the recursive DNS server with the IP address (i.e. <code>.com</code> ) of the TLD server that manages the specific domain extension requested like .com, .org, etc. The recursive DNS server then sends a query to the <code>.com</code> TLD server.</p>
<h3 id="heading-5-authoritative-dns-servers">5. Authoritative DNS Servers</h3>
<p>The TLD server responds to the recursive DNS server with the IP address of the authoritative DNS server for <code>google.com</code>. The authoritative DNS servers store the DNS records (such as A records, CNAME records, MX records, etc.) for specific domain names. The recursive server fetches the IP from here and sends it back to your device. Usually, the IP is also cached locally to speed up future requests.</p>
]]></content:encoded></item><item><title><![CDATA[Git Commands]]></title><description><![CDATA[This blog is about the git commands. I have included most used git commands in this blog in the simplest way i could do.]]></description><link>https://blog.bipinbhatt.com.np/git-commands</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/git-commands</guid><category><![CDATA[Git]]></category><category><![CDATA[Git Commands]]></category><category><![CDATA[git-init]]></category><category><![CDATA[git rebase]]></category><category><![CDATA[git remote]]></category><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Thu, 29 Jan 2026 05:52:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769761502116/601a4de2-9585-4c01-92d8-d562555a12ef.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Git commands are instructions that we give to git to perform action such as tracking changes, switching branch, creating commits etc (Rebase ko barem pani yesmia lekha).</p>
<p>Following are some usefull git commands</p>
<h2 id="heading-git-init">git init</h2>
<p>This initializes a new git repository in an existing project. This command creates a new hidden folder (.git). It contains all the necessary repository files and subdirectories to manage version control for your project.</p>
<p>To initialize the git in your project, go to root folder and run following command</p>
<pre><code class="lang-plaintext">git init
</code></pre>
<h2 id="heading-git-status">git status</h2>
<p>This command is used to check and display the current status of your project. This command tells the informaiton like which files are modified, which files are staged for the next commit, and which files are untracked. This is very helpful command to know the state of your project.</p>
<pre><code class="lang-bash">git status
</code></pre>
<h2 id="heading-git-add">git add</h2>
<p>The git add command is used in order to begin tracking a new file or stage changes in the working directory so that the changes can be included in the next commit. Staging is an essential step in the Git workflow because it allows you to choose which changes should be included in the commit and which ones should be excluded.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#1 to add all the changes and new files</span>
git add . 
<span class="hljs-comment">#2 to add single file</span>
git add filename
<span class="hljs-comment">#3 to add multiple file </span>
git add filename filename
</code></pre>
<h2 id="heading-git-commit">git commit</h2>
<p>Commit is a snapshot of the project at any specific point in time. Each commit has a unique identifier (a hash) and includes a message that describes the changes made in that commit. The git commit command is used <mark>to save staged changes in your Git repository as a new commit.</mark></p>
<pre><code class="lang-bash">git commit -m <span class="hljs-string">"message that describes the change made"</span>
</code></pre>
<h2 id="heading-git-log">git log</h2>
<p>This command is used to list the commit history of a repository. It shows information about past commits, including hashes, authors, dates, and commit messages.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#1 displays history commits</span>
git <span class="hljs-built_in">log</span>

<span class="hljs-comment">#2 Displays commits history in short</span>
git <span class="hljs-built_in">log</span> -oneline

<span class="hljs-comment">#3 Displays details of a commit</span>
git <span class="hljs-built_in">log</span> -p &lt;commit_has&gt;

<span class="hljs-comment">#4 Display last n number of commits</span>
git <span class="hljs-built_in">log</span> -n &lt;number_of_commit&gt;

<span class="hljs-comment">#5 display for specific branch</span>
git <span class="hljs-built_in">log</span> &lt;branch_name&gt;

<span class="hljs-comment">#6 display commits by auther</span>
git <span class="hljs-built_in">log</span> --author &lt;author_name&gt;
</code></pre>
<h2 id="heading-git-diff">git diff</h2>
<p>This command is used to compare various parts of your git repository</p>
<pre><code class="lang-bash"><span class="hljs-comment">#1 Compares working direcotry to last commit </span>
git diff

<span class="hljs-comment">#2 compares two commits</span>
git diff &lt;commit_has&gt; &lt;commit_hash&gt;

<span class="hljs-comment">#3 compare staged changes to last commit</span>
git diff --staged
</code></pre>
<h2 id="heading-git-pull">git pull</h2>
<p>The git pull command is used to fetch changes from a remote repository (usually the origin) and merge them into your current branch. It essentially combines two operations git fetch and git merge.</p>
<p><strong>Fetching changes (git fetch)</strong> -  Git fetches new changes from the remote repository (usually named "origin" by default) into your local repository without immediately merging them into your current branch. <strong>Merging Changes (git merge)</strong> - After fetching changes, Git automatically tries to merge them into your current branch.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#1 fetch form remote main branch and merge to current branch</span>
git pull
<span class="hljs-comment">#2 fetch from another remote branch to current brach </span>
git pull origin branchname
</code></pre>
<h2 id="heading-git-clone">git clone</h2>
<p>The git clone command is used to make a copy of a remote Git repository on a local machine. It allows us to start working on a project that is hosted on a remote server by downloading all the project’s files, commit history, and branches</p>
<pre><code class="lang-bash">git <span class="hljs-built_in">clone</span> &lt;url&gt;
</code></pre>
<h2 id="heading-git-push">git push</h2>
<p>This command is used to upload local commits to a remote repository, allowing developers to share their work and synchronize changes across multiple machines.</p>
<pre><code class="lang-bash">git push -u origin main <span class="hljs-comment"># for first time then  git push</span>
</code></pre>
<h2 id="heading-git-stash">git stash</h2>
<p>The git stash is a useful Git command used to temporarily save the changes in your working directory and index without committing them. This is particularly handy when you need to switch to a different branch or perform some other operation that requires a clean working directory.</p>
<p>The main purpose of git stash is to save changes that are not ready to be committed yet but need to be temporarily stored. This allows you to switch branches or perform other operations without committing to halffinished work.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#to save changes without commit</span>
git stash

<span class="hljs-comment"># retrieve stashed change</span>
git stash apply

<span class="hljs-comment">#list all the stashed changes</span>
git stash  list
</code></pre>
<h2 id="heading-git-checkout">git checkout</h2>
<p>This is versatile command with the multiple uses.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#1 to switch to existing branch</span>
git checkout branch_name

<span class="hljs-comment">#2 create and switch to a new branch</span>
git checkout -b branch_name
</code></pre>
<h2 id="heading-git-branch">git branch</h2>
<p>The git branch command in Git is used to list, create delete, and manage branches with a Git repository. Branches are used to isolate development work and manage different lines of code.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#1 list all branchs</span>
git branch

<span class="hljs-comment">#2 create a new barnch</span>
git branch &lt;branchName&gt;

<span class="hljs-comment">#3 delete </span>
git branch -D &lt;branchname&gt;

<span class="hljs-comment">#4 rename</span>
git branch -m newname
</code></pre>
<h2 id="heading-git-reset">git reset</h2>
<p>The git reset is a powerful Git command that allows you to reset the current branch to a specified state. It’s used to undo changes, unstaged files, or move the branch to a pointer to a different commit.</p>
<p>It is a Git command used to move the HEAD (and the current branch pointer) to a specified commit and optionally update the staging area and working directory.</p>
<p><mark>HEAD points to the current branch, while the branch pointer points to a commit; when a branch moves, HEAD follows it</mark>.</p>
<p>There are three primary options for git resets<br />1. Soft reset: This moves HEAD and the current branch pointer to the specified commit <mark>without changing the staging area or working directory</mark>. All changes remain staged for the next commit.</p>
<ol start="2">
<li><p>Mixed reset: Moves HEAD and the branch pointer to the specified commit, <mark>unstages all changes, but keeps them in the working directory</mark>. Useful when you accidentally staged files.</p>
</li>
<li><p>Hard reset : Moves HEAD and the branch pointer to the specified commit, removes all staged and unstaged changes from the working directory, effectively discarding all changes. Use with caution.</p>
</li>
</ol>
<p>Use cases are give below</p>
<pre><code class="lang-bash"><span class="hljs-comment">#1 Undo the last commit(When you commit to early or with the wrong message</span>
git reset -- soft HEAD^
(Keeps changes staged)

<span class="hljs-comment">#2 Unstage files accidentally added ( you did git add. and wanna unstage some )</span>
git reset &lt;file_name&gt;

<span class="hljs-comment">#3 Discard all local changes.....( you tried some changes but want to start fresh)</span>
git reset --hard HEAD 
(Removes all staged and unstaged changes <span class="hljs-keyword">in</span> the current branch.)

<span class="hljs-comment">#4 Move the branch to a specific commit</span>
git reset --&lt;commit_hash&gt;

etc,..
</code></pre>
<h2 id="heading-git-merge">git merge</h2>
<p>The git merge is a Git command that is used to integrate changes from one branch to another branch. This is typically used to combine the changes made in a features branch back into the main branch.</p>
<pre><code class="lang-bash">git merge &lt;branch_name&gt;
</code></pre>
<h2 id="heading-git-squash">git squash</h2>
<p>The git squash is not a standalone Git command, but it refers to a technique used to combine multiple Git commits into a single, more meaningful commit. This is typically done to maintain a cleaner and more organized Git history.</p>
<pre><code class="lang-bash">git merge --squash &lt;branch_name&gt;

//Squash combines changes ... you need a single commit to save them.
</code></pre>
<h2 id="heading-git-rebase">git rebase</h2>
<p>Git rebase is a Git command used to move or reapply commits from one branch onto another, creating a linear commit history. It rewrites commit hashes for the rebased commits. After rebasing, you won’t see a merge commit, but all the changes from your branch will appear as if they were applied on top of the target branch from the beginning. In other words, it acts as if the branch was created from the latest state of the main branch, even though it originally started earlier. Rebase is used instead of merging to avoid unnecessary merge commits and keep the history clean.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#suppose you have a branch feature  and you want to rebase on top of the main branch</span>

<span class="hljs-comment">#1. make sure you are on the main branch</span>
git checkout main
git pull origin main

<span class="hljs-comment">#2. switch to the feature brahcn</span>
 git checkout feature

<span class="hljs-comment">#3 rebase the feature branch on the main branch</span>
git rebase main
</code></pre>
<h2 id="heading-git-revert">git revert</h2>
<p>The git revert command is used to create a new commit that undoes the changes made by a previous commit or a range of commits.  It effectively applies the inverse of the specified commit(s) to the current branch, allowing you to ‘revert the changes without altering the commit history</p>
<pre><code class="lang-bash"><span class="hljs-comment">#single commit  revert</span>
git rever &lt;commit_hash&gt;

<span class="hljs-comment">#range of commit </span>
git revert &lt;commit_hash&gt; .. &lt;commit_hash&gt;
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Network And Network Devices]]></title><description><![CDATA[This blog is about network and the networking device. It show how data travel from over the netwokr]]></description><link>https://blog.bipinbhatt.com.np/network-and-network-devices</link><guid isPermaLink="true">https://blog.bipinbhatt.com.np/network-and-network-devices</guid><category><![CDATA[networking]]></category><category><![CDATA[#NetworkDevices]]></category><category><![CDATA[router]]></category><category><![CDATA[modem]]></category><dc:creator><![CDATA[Bipin Bhatt]]></dc:creator><pubDate>Sun, 25 Jan 2026 00:15:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769761537710/1626383a-8971-445b-a709-3e74fbe08f98.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction-to-network">Introduction to Network</h2>
<p>If any two or more than two entities are connected to communicate with each other, then that connection is called as network. Example of network can be social network (connection between two or more people), network or highways etc.</p>
<p>Similary, when the two or more computers are connected, it is called computer network. Computer network make communication possible for computers. The network of multiple computer networks is internet. We need certain physical appliances to establish a network for computers , these physical appliances are know as network devices. Some of network devices are : Router, Modem, Switch, firewall etc. these devices help you to access the internet.</p>
<h2 id="heading-function-of-network-devices">Function of Network Devices</h2>
<ol>
<li><p>Enabling communication between computers</p>
</li>
<li><p>Managing and controlling data traffic to avoid congestion</p>
</li>
<li><p>Amplifies weak signal to boost speed and extend network coverage</p>
</li>
<li><p>Provice secure connection</p>
</li>
</ol>
<h2 id="heading-network-devices">Network Devices</h2>
<p>When you open a website, your data travels through multiple devies before reaching its destination.</p>
<ul>
<li><p>your device genereates data(like http request)</p>
</li>
<li><p>NIC converts data into signal to travel over local network</p>
</li>
<li><p>Hub or switch or access point directs data within your local network</p>
</li>
<li><p>router choose the best path for data to leave your network</p>
</li>
<li><p>modem converts your LAN signal into analog signal suitable for transimsiion over the ISP medium then you get connected to the internet</p>
</li>
</ul>
<p>Finally your request reach to the server and it gerenates the response and it come back to you same way it went.</p>
<h3 id="heading-1-nic">1. NIC</h3>
<p>NIC stands for network interface card. This is the chip(used to be an external card) inside your device that makes your device able to connect to network physically or wirelessly. NIC is present in every network-connected device. NIC has mac address assigned to which is required for the communication inside local aread network. NIC converts data to the electrical signal(if you are connecting with ethernete cable) or radio waves(if using wi-fi) so it can travel over the medium. The receiving device’s NIC converts the signal back into digital form tha computer can understand</p>
<h3 id="heading-2-hub">2. HUB</h3>
<p>HUB Is used to connect multiple computers in a local area network. When hub receives data from any devices connectd to it’s port, it broadcast the data to all other ports. It does not know MAC address, IP address. It is dumb. So every device connected to its port wil get the data but only the intended device will receive it, others just ignore. The transmission mode in hub is dubplex, meaning sending and receiving of data can not be done simultaneouly.</p>
<h3 id="heading-3-repeater">3. Repeater</h3>
<p>When signal travels through the medium like wire, air they might lose weight with the distance. In order to make the signal sharp as the original we need some extra work to do. This is where repeater are used. Repeater does not understand data but they just signals. Let’s suppose you max length for a ethernet cable is 100m, if you need 200m you have to put a repeater in between.</p>
<h3 id="heading-4-modem">4. Modem</h3>
<p>Word modem came from the work it does; modulation and demodulation. Modem converts signal(generated by NIC) from your network to the form requried by your ISP’s physical medium and vice verca. It acts as a translator between your network and your internert. It is placed between your router and ISP connection. Modem provides internet to the network that is connected through a hub or switch.</p>
<h3 id="heading-5-switch">5. Switch</h3>
<p>Switch is the better version of HUB that is used to connect all the fevices is a local area network. It is much smarter. It forwards data only tot the device that needs it using mac address. It stores mac of all the connected devices and upon receiving a message from sender it checks mac address of the message and then sends the message to the receiver that mathces the mac address.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769298078924/e169db85-47b3-451c-9cae-bc0038c8f931.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-6-bridge">6. Bridge</h3>
<p>Bridge is a network device that connects two LAN segments and manage traffic between them. You can think it as a small overpass connecting two neighborhood allowing only relevant traffic to pass. Bridge uses MAC address to decide whether to send data between LAN segments. Suppose you have LAN1 and LAN2. Device A in LAN1 wants to send data to device B in LAN2. Bridge check MAC address table: if the destination MAC is in the other LAN , it forwards the data, and if same it blocks the data.</p>
<h3 id="heading-7-access-point-ap">7. Access Point (AP)</h3>
<p>AP is a networking device that allows wireless devices to conne t to a wired network (LAN). AP is connected to a switch or router using ethernet cable. Wireless devices connet to the AP via wi-fi. AP forwards wireless traffic to the wired network, and vice-versa.</p>
<h3 id="heading-8-router">8. Router</h3>
<p>Router is a device that connects two or more networks and forwads data between these based on IP address. It connets a LAN to the WAN or Internet. It maintains MAC address of local devices using an ARP(address resolution protocol) table. When a router receives a packet it checks the destination IP address. If destination IP belongs to the local network the router forward the packet by creating frame with the destination device’s MAC address and sends it to the switch. If the destination IP is outside the local network , the router forwards to ISP gateway by encapsulatin it in a new frame with the ISP gateway’s MAC address.</p>
<h3 id="heading-9-firewall">9. Firewall</h3>
<p>Firewall is network device that sits between. your local network and the outside world to control and filter the traffic. It monitors and filters incomming and outgoing traffic according to predefined rules. This is the best place to control the traffic because it is right in between the router and outside world. All of the traffic or packets have to pass through this. Imagine you wanna put a security guard at your home to block all of the unknown person to enter, where would you let him stand? at the main gate from where the any unknown person can come right? So firewall is also a gatekeeper for you LAN.</p>
<h3 id="heading-10-load-balancer">10. Load Balancer</h3>
<p>It is a networking device that distributes network traffic across multiple servers to make sore no single server get overloaded. Load balancers are used in the server side. Server use it to share the load. Suppose you have 3 servers. If any user requuest come load balancer will direct it to the server that has less requests, to make sure user get response faster and no server become overloaded.</p>
]]></content:encoded></item></channel></rss>