<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sandeep on Medium]]></title>
        <description><![CDATA[Stories by Sandeep on Medium]]></description>
        <link>https://medium.com/@sandeep-patel?source=rss-702b35e32ca7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Sandeep on Medium</title>
            <link>https://medium.com/@sandeep-patel?source=rss-702b35e32ca7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:06:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sandeep-patel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Debugging Node.js Child Processes and Cluster with --inspect-brk=0]]></title>
            <link>https://medium.com/nodejsmadeeasy/debugging-node-js-child-processes-and-cluster-with-inspect-brk-0-1a0ab040bead?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a0ab040bead</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[node-js-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[node-js-tutorial]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Tue, 01 Oct 2024 20:06:22 GMT</pubDate>
            <atom:updated>2024-10-01T20:06:22.872Z</atom:updated>
            <content:encoded><![CDATA[<p>Debugging is an essential part of software development, especially when working with complex applications that involve multiple processes. In Node.js, working with child processes or clusters can be tricky to debug, but tools like the --inspect-brk=0 flag make it much easier. In this blog post, we&#39;ll explore what --inspect-brk=0 does, how it works, and how you can use it to debug your Node.js applications effectively.</p><h4>Understanding --inspect-brk=0</h4><p>When you run a Node.js application, the --inspect flag enables the Node.js debugger, allowing you to connect debugging tools like Chrome DevTools or Visual Studio Code. The --inspect-brk flag goes a step further by pausing your application on the very first line of code, giving you a chance to set breakpoints and start debugging from the very beginning.</p><p>But what if you’re running multiple processes, like when using the cluster module or spawning child processes with child_process? By default, the debugger listens on the port 9229. If you have multiple processes trying to debug on the same port, it causes conflicts.</p><p>This is where --inspect-brk=0 comes in. By using =0, you&#39;re telling Node.js to automatically choose an available port for the debugger. This means each process will get its unique port, allowing you to debug multiple processes simultaneously without any conflicts.</p><h4>Why Use --inspect-brk=0?</h4><ul><li><strong>Start Debugging Immediately</strong>: The --inspect-brk flag pauses your application on the first line, letting you set breakpoints before anything else runs.</li><li><strong>Avoid Port Conflicts</strong>: By setting =0, Node.js automatically selects an available port for each process, which is especially useful when working with multiple processes.</li><li><strong>Multi-Process Debugging</strong>: Whether you’re using the cluster module or child_process, --inspect-brk=0 allows you to debug each process individually, making it easier to track down bugs in complex applications.</li></ul><h4>Minimum Node.js Version Required</h4><p>The --inspect-brk=0 the feature works seamlessly in Node.js <strong>version 8.0.0</strong> and above. While earlier versions of Node.js (starting from 6.3.0) introduced the --inspect flag and basic debugging support, it wasn&#39;t until Node.js 8.0.0 that --inspect-brk=0 became fully stable and capable of automatically assigning unique debugging ports to multiple processes. Therefore, if you&#39;re using Node.js 8 or later, you can take full advantage of this feature without any issues.</p><h4>Debugging a Child Process</h4><p>Let’s say you have a Node.js application that spawns a child process. Here’s how you can use --inspect-brk=0 to debug the child process:</p><p><strong>How It Works:</strong></p><ul><li>When you run main.js, it forks a child process, child.js.</li><li>The execArgv: [&#39;--inspect-brk=0&#39;] option in fork enables debugging for child.js and pauses it on the first line.</li><li>Node.js automatically selects a unique debugging port for child.js, avoiding conflicts with other processes.</li></ul><p>You can then attach a debugger (e.g., Chrome DevTools or VS Code) to the port that child.js using. This allows you to step through the code, inspect variables, and understand what’s happening inside the child process.</p><p>parent.js</p><pre>const { fork } = require(&#39;child_process&#39;);<br><br>// Fork a child process with debugging enabled<br>const child = fork(&#39;child.js&#39;, [], {<br>  execArgv: [&#39;--inspect-brk=0&#39;]  // This enables debugging for the child process<br>});<br><br>child.on(&#39;message&#39;, (msg) =&gt; {<br>  console.log(&#39;Message from child:&#39;, msg);<br>});<br><br>child.send({ hello: &#39;world&#39; });</pre><p>child.js</p><pre>process.on(&#39;message&#39;, (msg) =&gt; {<br> console.log(&#39;Message from parent:&#39;, msg);<br> process.send({ reply: &#39;Hello from child!&#39; });<br>});</pre><h4>Debugging with the Cluster Module</h4><p>Since the cluster module internally uses the child process module to fork the worker process the same option --inspect-brk=0 also works for the cluster module.</p><pre>const cluster = require(&#39;cluster&#39;);<br>const http = require(&#39;http&#39;);<br>const numCPUs = require(&#39;os&#39;).cpus().length;<br><br>if (cluster.isMaster) {<br>  console.log(`Master ${process.pid} is running`);<br><br>  // Fork workers with debugging enabled<br>  for (let i = 0; i &lt; numCPUs; i++) {<br>    cluster.fork({<br>      execArgv: [&#39;--inspect-brk=0&#39;]  // Enable debugging for each worker<br>    });<br>  }<br><br>  cluster.on(&#39;exit&#39;, (worker, code, signal) =&gt; {<br>    console.log(`Worker ${worker.process.pid} died`);<br>  });<br>} else {<br>  http.createServer((req, res) =&gt; {<br>    res.writeHead(200);<br>    res.end(&#39;Hello World\n&#39;);<br>  }).listen(8000);<br>  console.log(`Worker ${process.pid} started`);<br>}</pre><p><strong>NOTE: Since each worker gets a random port for debugging you may have to manually attach a debugger (e.g., Chrome DevTools or VS Code) to the port a worker using.</strong></p><h4>Conclusion</h4><p>The --inspect-brk=0 flag is a powerful tool for debugging Node.js applications that use multiple processes, whether through the child_process or cluster modules. By automatically assigning unique debugging ports and pausing execution on the first line of code, --inspect-brk=0 makes it easier to get a handle on complex, multi-process applications.</p><p>Whether you’re building a web server that scales across multiple CPU cores or a script that spawns child processes to perform parallel tasks, --inspect-brk=0 ensures that you can debug each part of your application effectively. Just remember to use Node.js version 8.0.0 or above to take full advantage of this feature.</p><p>Next time you’re working with Node.js and need to debug multiple processes, give --inspect-brk=0 a try!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a0ab040bead" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nodejsmadeeasy/debugging-node-js-child-processes-and-cluster-with-inspect-brk-0-1a0ab040bead">Debugging Node.js Child Processes and Cluster with --inspect-brk=0</a> was originally published in <a href="https://medium.com/nodejsmadeeasy">NodeStack</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NodeJs Clustering: Part2]]></title>
            <link>https://medium.com/nodejsmadeeasy/nodejs-clustering-part2-44cf6f0e513c?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/44cf6f0e513c</guid>
            <category><![CDATA[child-processes]]></category>
            <category><![CDATA[node-js-development]]></category>
            <category><![CDATA[node-js-tutorial]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Mon, 30 Sep 2024 23:40:49 GMT</pubDate>
            <atom:updated>2025-02-12T07:23:01.675Z</atom:updated>
            <content:encoded><![CDATA[<h4>Implementing Clustering using child_process</h4><p>In the first part, we discussed how clustering, port, and load sharing work. In this post, we will write a basic clustering implementation using the Nodejs child_process module, this will further deepen your understanding of clustering, port sharing, and load balancing.</p><h4>Round Robin Policy:</h4><p>In the round-robin approach, the master process accepts the connection and then hands off the connection (client handle) to one of the worker processes. The worker process then handles all communication through a socket created on the handle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YEhEUsbS5d4Wv8E20cCo_g.gif" /><figcaption>Primary distributting the connection in Round Robin</figcaption></figure><p><strong>Primary:</strong></p><pre>const { fork } = require(&#39;child_process&#39;);<br>const net = require(&#39;net&#39;);<br>const os = require(&#39;os&#39;);<br>const numCPUs = os.cpus().length;<br>const workers = [];<br>let workerIndex = 0;<br><br>// Fork workers <br>for (let i = 1; i &lt;=numCPUs; i++) {<br>    const worker = fork(&#39;worker-round-robin-policy.js&#39;); // Fork the worker process<br>    workers.push(worker);<br>}<br><br>// Create the server in the primary process<br>let server = net.createServer();<br><br><br>// Start listening on the server<br>server.listen({ port: 8080 });<br><br>// Once the server starts listening, get the handle for the server<br>server.once(&#39;listening&#39;, () =&gt; {<br>    const serverhandle = server._handle;<br>    console.log(&quot;Server listening on port 8080, server handle fd:&quot;, handle.fd);   <br>    // Start accepting new connections<br>     acceptConnection(serverHandle);<br>});<br><br>// Function to handle new connections<br>function acceptConnection(serverHandle) {<br>    // The server handle will receive new connections<br>    serverHandle.onconnection = (err, clientHandle) =&gt; {<br>        if (err) {<br>            console.error(&quot;Error receiving new connection:&quot;, err);<br>            return;<br>        }<br>        console.log(&quot;New connection received, handle fd:&quot;, clientHandle.fd);<br>        // Distribute the connection to the workers<br>        distribute(clientHandle);<br>    };<br>}<br><br>// Function to distribute connections to workers<br>function distribute(clientHandle) {<br>    workerIndex = (workerIndex + 1) % workers.length;<br>    const worker = workers[workerIndex];<br>    worker.send(&quot;new-conn&quot;, clientHandle);  // Passing the handle properly to the worker<br>}</pre><p><strong>Worker:</strong></p><pre>const net = require(&#39;net&#39;);<br><br>const handleConenction = (socket) =&gt; {<br>    console.log(&quot;New connection&quot;);<br><br>    socket.on(&#39;close&#39;, () =&gt; {<br>        console.log(&#39;Client has disconnected&#39;);<br>    });<br><br>    // Handle &#39;data&#39; event to process data from the client<br>    socket.on(&#39;data&#39;, (data) =&gt; {<br>        console.log(`Data received: ${data}`);<br><br>        // Write a response to the client, but check if writable first<br>        if (socket.writable) {<br>            console.log(&quot;writable&quot;);<br>            const responseBody = &#39;Hello, HTTP World!&#39;;<br>            const response =<br>                `HTTP/1.1 200 OK\r\n` + // Status line<br>                `Content-Type: text/plain\r\n` + // Content-Type header<br>                `Content-Length: ${responseBody.length}\r\n` + // Content-Length header<br>                `Connection: close\r\n` + // Close the connection after response<br>                `\r\n` + // End of headers<br>                `${responseBody}`; // Response body<br><br>            // Write the HTTP response to the socket<br>            socket.write(response);<br>            socket.end();<br>        }<br>    });<br><br>}<br><br><br>const server = net.createServer(handleConenction);<br><br>// Listen for the message from the primary process<br>process.on(&#39;message&#39;, (msg, clientHandle) =&gt; {<br>    if (msg === &#39;new-conn&#39; &amp;&amp; clientHandle) {<br>        console.log(&quot;Received new connection handle in worker&quot;);<br>        onconnection(clientHandle);<br>    }<br>});<br><br>function onconnection(clientHandle) {<br>    // Create a socket from the received handle<br>    const socket = new net.Socket({<br>        handle: clientHandle,<br>        allowHalfOpen: server.allowHalfOpen,<br>        pauseOnCreate: server.pauseOnConnect,<br>        readable: true,<br>        writable: true,<br>        readableHighWaterMark: server.highWaterMark,<br>        writableHighWaterMark: server.highWaterMark,<br>    });<br>    // Attach server properties to the socket<br>    socket.server = server;<br>    socket._server = server;<br>    // Handle connection<br>    server.emit(&#39;connection&#39;, socket);<br>}<br><br>// Handle worker shutdown<br>process.on(&#39;SIGINT&#39;, () =&gt; {<br>    server.close();<br>});<br><br>console.log(`Worker ${process.pid} started`);</pre><h4>Direct Connection (Shared Handle):</h4><p>In this approach, the master process creates the server handle but doesn’t accept connections directly, Instead, it allows each worker process to independently accept and handle incoming connections.</p><p>When a new connection is made to the shared port, the operating system decides which worker process will handle the connection. This could be based on availability or other criteria, ensuring that connections are distributed across multiple processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2gfcWQB7rF13Yp5n1vvtaw.png" /><figcaption>Woker-handling connection direcly, OS will be responsible to assinging connection to one of the worker</figcaption></figure><p><strong>Primary:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8df63d277807c7cdc289b7e7b2d1c5a6/href">https://medium.com/media/8df63d277807c7cdc289b7e7b2d1c5a6/href</a></iframe><p><strong>Worker:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8035b839fdd3fa72a81407178fb59c8b/href">https://medium.com/media/8035b839fdd3fa72a81407178fb59c8b/href</a></iframe><blockquote><strong><em>The second approach should, in theory, give the best performance. In practice however, distribution tends to be very unbalanced due to operating system scheduler vagaries. Loads have been observed where over 70% of all connections ended up in just two processes, out of a total of eight . </em></strong><em>Source: </em><a href="https://nodejs.org/api/cluster.html#how-it-works"><em>https://nodejs.org/api/cluster.html#how-it-works</em></a></blockquote><p>The above is the very basic implementation of two methods of clustering using the child_process module based on my understanding and debugging the cluster module itself. The actual implementation is robust and has full-fledged APIs but the core idea is the same.</p><p>I hope you liked reading it. Please feel free to give your constructive feedback. The f<a href="https://medium.com/nodejsmadeeasy/deep-diving-nodejs-clustering-part1-e59aef603dc0">irst part of this post</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44cf6f0e513c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nodejsmadeeasy/nodejs-clustering-part2-44cf6f0e513c">NodeJs Clustering: Part2</a> was originally published in <a href="https://medium.com/nodejsmadeeasy">NodeStack</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep diving NodeJs Clustering: Part1]]></title>
            <link>https://medium.com/nodejsmadeeasy/deep-diving-nodejs-clustering-part1-e59aef603dc0?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e59aef603dc0</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Mon, 16 Sep 2024 21:03:00 GMT</pubDate>
            <atom:updated>2024-09-30T23:40:18.078Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understanding Port Sharing and Load Balancing</h4><p>Yes, I know what you’re thinking: ‘Yet another post on Node.js clustering? But stick around! While there are countless posts on the topic, this one takes a unique approach by breaking down the magic of port sharing, and showing you how to implement basic clustering from scratch using the `child_process` module in the second part of this post.</p><p>Node.js is popular for building scalable applications due to its non-blocking, event-driven architecture. However, Node.js runs on a single thread by default, which can limit its ability to utilize multi-core processors fully. To address this limitation, Node.js supports clustering, allowing multiple processes to handle incoming connections on the same port. In this blog and the following post, we’ll explore two clustering approaches using the `child_process` module, explain how port sharing works, and provide practical code examples.</p><p>Ok, What is Clustering in Node.js?</p><p>Clustering in Node.js is a technique that allows you to spawn multiple instances (workers) of your application, each running on a separate CPU core. These workers share the same server port and can handle incoming connections independently. This setup improves scalability and performance by fully utilizing all CPU cores on a server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YEhEUsbS5d4Wv8E20cCo_g.gif" /><figcaption>Clustering Visualisation Under Round Robin Scheduling</figcaption></figure><p>It’s important to understand a few basic but essential concepts to understand how clustering works.</p><ul><li><strong>Inter-Process Communication(IPC)</strong></li><li><strong>Listening Socket (Listening FD)</strong></li><li><strong>Connection Socket(Connection FD)</strong></li><li><strong>File descriptor(Linux-based system) or handles(Windows OS)</strong></li></ul><p><strong>Inter-Process Communication(IPC)</strong></p><p>IPC is a mechanism that allows processes to communicate with each other and synchronize their actions via message passing. In the context of Node.js, when using clustering with IPC, the Main process (Master Process) can communicate with its worker processes to share data, send messages, or coordinate tasks.</p><p><strong>IPC in Node.js Clustering</strong></p><p>Master Process:</p><ul><li>The Master Process is responsible for spawning worker processes.</li><li>The cluster module internally uses the child_process module to fork worker processes.</li><li>child_process module also creates an IPC channel so that the primary and child processes can communicate.</li><li>It can send and receive messages from worker processes using IPC channels.</li><li>The Master Process can also monitor and manage worker processes, restarting them if they fail.</li></ul><p>Worker Processes:</p><ul><li>Each worker process is a child process spawned by the Master Process.</li><li>Workers can handle incoming client requests, perform computations, or manage resources.</li><li>Workers can communicate with the Master Process (and potentially other workers) using IPC.</li></ul><p><strong>Listening Socket</strong></p><p><strong>Purpose: </strong>A listening socket is used by a server to listen for incoming connection requests from clients. It does not handle data transfer; instead, its primary role is waiting for and accepting new connections.</p><p><strong>Behavior: </strong>When a server application starts, it creates a socket, binds it to a specific IP address and port, and then listens on that port for incoming connections. The socket in this state is called a listening socket. In Nodejs clustering mode the Primary process creates a listening socket.</p><p><strong>Lifecycle: </strong>The listening socket remains open as long as the server is running and willing to accept new connections. It does not participate in the communication beyond the initial connection setup.</p><p><strong>Connection Socket (Accepted Socket):</strong></p><p>Purpose: A connection socket transfers actual data between the client and the server. Once a connection is established, the connection socket handles all subsequent communication. I</p><p>Behavior: When a listening socket receives an incoming connection request and accepts it, the server(Primary or child) creates a new socket specifically for this connection. This new socket is the connection socket (also known as the accepted socket), and it is used for the entire duration of the communication between the client and the server. In Nodje clustering mode either Primary or child creates a connection socket( Based on the Scheduling policy, more detail in the following) when a listener socket receives a new connection request.</p><p>Lifecycle: The connection socket is created when a connection is accepted and remains open as long as the communication continues. Once the communication is complete, the connection socket is closed.</p><p><strong>FD or Handles:</strong></p><p>A file descriptor or handle is essentially an integer assigned by the operating system to represent an open file, socket, or other I/O resource within a process. When a process opens a socket or file, the operating system returns a file descriptor, which the process can use to read from, write to, or close the socket or resource. Each file descriptor corresponds to an entry in the process’s file descriptor table, which maintains metadata about the open resource, whether it is a socket or a file.</p><h3>The Clustering Overview</h3><p><strong>Primary Process:</strong> This is the main process that manages the worker processes.</p><p><strong>Worker Processes:</strong> These are the separate processes created by the primary process to handle incoming connections.</p><p>The Primary process can keep the listening socket to itself (Round Robin) or share it with the worker processes (Direct Connection Handling<strong>) w</strong>hen a connection request comes in, depending on the approach used.</p><p><strong>Cluster Module structure</strong></p><p>The cluster module has the following components:</p><p><a href="https://github.com/nodejs/node/blob/main/lib/cluster.js">Cluster.js</a></p><ul><li>Cluster: <a href="https://github.com/nodejs/node/blob/main/lib/internal/cluster/primary.js">Primary.js</a></li><li>Cluster: <a href="https://github.com/nodejs/node/blob/main/lib/internal/cluster/child.js">Child.js</a></li></ul><p><a href="https://github.com/nodejs/node/blob/main/lib/internal/cluster/worker.js">Worker.js</a>: Common Worker implementation shared between the cluster primary and workers.</p><p><a href="https://github.com/nodejs/node/blob/main/lib/internal/cluster/utils.js">Utils.js</a>: Utility functions to handle and intercept internal communication between primary and child processes. Internal communication refers to the IPC used between the Primary and child for setting up a cluster.</p><p><a href="https://github.com/nodejs/node/blob/main/lib/internal/cluster/round_robin_handle.js">Round Robile Handle</a>: Responsible for creating FD, listening and accepting incoming connections, and delegating the work(client Handler) to workers in a robin fashion.</p><p><a href="https://github.com/nodejs/node/blob/main/lib/internal/cluster/shared_handle.js">Shared Handler</a>: If the Scheduling policy is set to other than SCHED_RR then the primary will use this to create a shared Server handler and passed to each worker. then each worker listens to incoming connections.</p><h4>Two Approaches to Distribute Connections</h4><p><strong>Round-Robin Approach (Default on most platforms):</strong></p><p>In the round-robin approach, the master process accepts the connection and then hands off the connection socket to one of the worker processes. The worker process then handles all communication through these connection sockets</p><p><strong>Example:</strong> Imagine you have a ticket counter with three workers. Every new customer is directed to the next available worker in turn. This helps ensure that no single worker is overwhelmed.</p><p><strong>Direct Connection Handling: </strong>In this approach, the master process creates the server socket but doesn’t handle connections directly. Instead, it allows each worker process to independently accept and handle incoming connections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FTTZrTomi7XitQ-vIEgxxw.png" /><figcaption>Direct Connection Handling -Shared FD (OS will make sure one of the workers process will get connection)</figcaption></figure><p>When a new connection is made to the shared port, the operating system decides which worker process will handle the connection. This could be based on availability or other criteria, ensuring that connections are distributed across multiple processes.</p><p><strong>Example:</strong> Instead of sending customers, each worker has a ticket counter. This could theoretically speed things up, but in practice, it might lead to uneven distribution of customers (e.g., some workers get a lot more customers than others).</p><blockquote><strong>The second approach should, in theory, give the best performance. In practice however, distribution tends to be very unbalanced due to operating system scheduler vagaries. Loads have been observed where over 70% of all connections ended up in just two processes, out of a total of eight.</strong></blockquote><blockquote><em>Source: </em><a href="https://nodejs.org/api/cluster.html#how-it-works"><em>https://nodejs.org/api/cluster.html#how-it-works</em></a></blockquote><h3>Port Sharing Explained</h3><p>Now it’s time to break down the details of how port sharing works in Nodejs</p><p>Let’s discuss a basic example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/0*OT4n1H--w7OGvM7R.png" /></figure><p>When starting a server with clustering, it first checks if the current process is the primary one using cluster.isPrimary. If it&#39;s the primary process, it creates worker processes cluster.fork() based on the number of available CPU cores. cluster.fork internally use child_process.fork method call. child_proces.fork is responsible for creating a worker(child) process along with an IPC channel for communication between a primary(Parent) and worker(child) process.</p><p>When the worker process is executed the else part of the code is executed</p><p>Now I have two questions for you to reason about :</p><ol><li>If you noticed that Primary has created no listener socket but I mentioned above that the primary process creates a listener socket. How?</li><li>Each worker process seems to create its server listening at port 8080. How?</li></ol><p>Hang on for the moment and think. You should ask yourself what happens when server.listen()is called in each worker process. How can each worker process listen to the same port?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*aucNy6j6SGFrcXST.gif" /></figure><p>Alright, enough chit-chat. Do you want answers? here they are —</p><p><strong>One thing we know is that two processes can not run on the same port. Unless something is shared? Well that something is called file descriptor (FD) or handle.</strong></p><p>The following things happen when server.listen called in the worker process</p><ul><li>Is, basically a call to the <strong>net.Server.prototype.listen. </strong>The net module has internal APIs for clustering and it checks if the worker or Primary calls listen by calling the method listenInCluster :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/0*6Ng976D4nCKQRbNY.png" /></figure><ul><li>When server.listen is invoked in worker(child process) then it further requests for Server handle by calling cluster._getServer function</li></ul><blockquote><strong><em>Note: cluster._getServer is defined in </em></strong><a href="https://github.com/nodejs/node/blob/main/lib/internal/cluster/child.js"><strong><em>child.js</em></strong></a><strong><em> which basically is the cluster.js in the worker. check the </em></strong><a href="https://github.com/nodejs/node/blob/main/lib/cluster.js"><strong><em>cluster.js</em></strong></a><strong><em> for more details.</em></strong></blockquote><ul><li>cluster._getServer (child.js._getServer) will further communicate internally to Primary using IPC to get the handler details. Worker use the <strong>send </strong>method defined in Utils.js to send messages to Primary. The message structure to get handle details from the server looks like this:</li></ul><pre>const message = { act: &#39;queryServer&#39;,index, data: null,...options};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DkXtbA-1lPDSlkOX.png" /></figure><p><strong>NOTE: For simplicity and brevity I have not discussed the initial setup and communication between primary and workers it’s also beyond the scope of this blog.</strong></p><ul><li>When the primary receives a message from the worker, the<strong> queryServer method</strong> is executed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/0*Mnx3YcgByDub9P4F.png" /></figure><p>In the round-robin scheduling, a Robin handle (Server handle) is created by Primary and set itself for listening for the incoming connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nCUiqRbRzNANAlqX.png" /></figure><p>For more details, you can check the code in the <strong><em>distribute </em></strong>and <strong><em>handoff</em></strong> methods defined in <a href="https://github.com/nodejs/node/blob/main/lib/internal/cluster/round_robin_handle.js">robin_handle.js</a>. Also don’t forget to look at the <strong><em>add</em></strong> method defined in there. On connection primary send the following message to the worker to delegate the task (pass the client handle)</p><pre>const message = { act: &#39;newconn&#39;, key: this.key };</pre><pre>sendHelper(worker.process, message, handle, (reply) =&gt; {<br>   ...<br>  });</pre><p>If the Scheduling policy is set to SCHED_NONE, then the Primary only creates a Server handle and sends it to the workers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P37_24B_g0AqpihI.png" /></figure><ul><li>Upon getting a reply back from Primary now let’s see what the worker (refer child.js) does. Have a look at the code snippet for cluster._getServer.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2E6YQSQSAifz0R6I.png" /></figure><ul><li>For the Shared Server handle it sets up things like `handle. close’ and execute callback name “cb” The callback function cb here is a private function ‘<strong>‘listenOnPrimaryHandle“</strong> from the net module.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_dKsgocR4gxuHmuc.png" /></figure><ul><li>listenOnPrimary internally calls setupListenHandle and as the name suggests it configures the handle for listening for the connections. A few lines of code in the function setupListenHandle to look at would be :</li></ul><pre>// this here represet net.Server object<br>  this._handle.onconnection = onconnection;<br>  this._handle[owner_symbol] = this;</pre><ul><li>For Round Robin scheduling, it does a bit more, creates a fack handle object with methods listen, ref, unref, etc then executes the callback function from the net module with fack handle as one of the parameters.</li></ul><blockquote><em>Check onconnection(message, handle) in child.js and callback cb in net module will help you to understand it better.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ObqfpaaMpD3KN6sV.png" /></figure><p>Handle before calling callback <strong>‘listenOnPrimaryHandle’</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xF0F8wshY_8J4LV2.png" /></figure><ul><li>After the call to <strong>‘listenOnPrimaryHandle, “the </strong>handle is ready for handling connection distributed by Primary. See the below screenshot.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3g3_H5r0j2gxjk5p.png" /></figure><p>So basically upon receiving handle details from Primary, a worker configures the server object by setting up the handle as you can see in the above screenshots.<br>Once the handle is set it’s ready for serving connection. For an even better understanding, you can set the breakpoints and debug the whole flow.</p><h3>Summary</h3><p>Clustering in Node.js is a powerful technique that enables you to make full use of multi-core processors, improving the scalability and performance of your application. In this blog post, we explored two approaches to clustering using the `cluster` module:</p><p>1. Master Process Distributing Connections (Round-Robin): This approach uses a round-robin algorithm to evenly distribute connections across workers, providing efficient load balancing.</p><p>2. Workers Directly Accepting Connections: Workers independently accept and handle connections, with the operating system managing the distribution.</p><p>In part 2, I will create basic clustering using the child_process module which will further help you to understand the clustering and port sharing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e59aef603dc0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nodejsmadeeasy/deep-diving-nodejs-clustering-part1-e59aef603dc0">Deep diving NodeJs Clustering: Part1</a> was originally published in <a href="https://medium.com/nodejsmadeeasy">NodeStack</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nodejs Event Loop Lag]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/nodejsmadeeasy/nodejs-event-loop-lag-5d5928fd03c?source=rss-702b35e32ca7------2"><img src="https://cdn-images-1.medium.com/max/1258/1*o-5JEVnpzvGYMXwAplZwgQ.gif" width="1258"></a></p><p class="medium-feed-snippet">Why does it matter?</p><p class="medium-feed-link"><a href="https://medium.com/nodejsmadeeasy/nodejs-event-loop-lag-5d5928fd03c?source=rss-702b35e32ca7------2">Continue reading on NodeStack »</a></p></div>]]></description>
            <link>https://medium.com/nodejsmadeeasy/nodejs-event-loop-lag-5d5928fd03c?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d5928fd03c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Sun, 06 Feb 2022 19:05:29 GMT</pubDate>
            <atom:updated>2024-09-17T03:21:42.490Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Elegant ways to pass env variables to Mocha test cases.]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/nodejsmadeeasy/elegant-ways-to-pass-env-variables-to-mocha-test-cases-4486cb238bb1?source=rss-702b35e32ca7------2"><img src="https://cdn-images-1.medium.com/max/600/1*dp2htT0eVR69zNeY6oFu-w.png" width="600"></a></p><p class="medium-feed-snippet">Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun.</p><p class="medium-feed-link"><a href="https://medium.com/nodejsmadeeasy/elegant-ways-to-pass-env-variables-to-mocha-test-cases-4486cb238bb1?source=rss-702b35e32ca7------2">Continue reading on NodeStack »</a></p></div>]]></description>
            <link>https://medium.com/nodejsmadeeasy/elegant-ways-to-pass-env-variables-to-mocha-test-cases-4486cb238bb1?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4486cb238bb1</guid>
            <category><![CDATA[mocha]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Sun, 31 Jan 2021 17:28:10 GMT</pubDate>
            <atom:updated>2021-02-01T09:55:53.145Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[A Simple Cors Proxy for Javascript applications]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/nodejsmadeeasy/a-simple-cors-proxy-for-javascript-applications-9b36a8d39c51?source=rss-702b35e32ca7------2"><img src="https://cdn-images-1.medium.com/max/1024/1*Gr3T_pkgMBbZw4v6Mjcm0g.png" width="1024"></a></p><p class="medium-feed-snippet">Sometimes there are use cases when we have to call third party services (APIs) where cors are not allowed or be enabled only for&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/nodejsmadeeasy/a-simple-cors-proxy-for-javascript-applications-9b36a8d39c51?source=rss-702b35e32ca7------2">Continue reading on NodeStack »</a></p></div>]]></description>
            <link>https://medium.com/nodejsmadeeasy/a-simple-cors-proxy-for-javascript-applications-9b36a8d39c51?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b36a8d39c51</guid>
            <category><![CDATA[node-js-tutorial]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[proxy-server]]></category>
            <category><![CDATA[cors]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Tue, 17 Mar 2020 00:44:03 GMT</pubDate>
            <atom:updated>2024-09-17T07:53:47.262Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[A few tips to improve Nodejs performance]]></title>
            <link>https://medium.com/nodejsmadeeasy/a-few-tips-to-improve-nodejs-performance-44aad81d95c2?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/44aad81d95c2</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[event-loop]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Tue, 25 Feb 2020 14:03:30 GMT</pubDate>
            <atom:updated>2020-03-19T12:32:14.451Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*zqNi3LWr15YIy2gTGoJkpw.jpeg" /><figcaption>Image courtesy: <a href="https://stackify.com/node-js-performance-tuning/">https://stackify.com/</a></figcaption></figure><p>In order to write performant and clean code, one should understand the working of language(or platform) and its design principles and patterns. In this post, I will list a few common points that every Nodejs developer should know which will ultimately help you write better-performing code.</p><p>There are a few things below you should learn and understand as much as you can. This will give you good knowledge of the Nodejs event loop and will help you understand this post better.</p><ul><li><strong>To know how Nodejs the Event loop works.</strong></li><li><strong>To know the differences between CPU intensive vs IO intensive tasks.</strong></li><li><strong>To understand blocking(synchronous) and non -blocking(asynchronous) code.</strong></li></ul><p>I am not going to explain each of the items above as they are broad topics to cover. There are others more experienced who have already explained it better. You can learn more here:</p><ul><li><a href="https://nodejs.org/en/docs/guides/blocking-vs-non-blocking/">Overview of Blocking vs Non-Blocking | Node.js</a></li><li><a href="https://nodejs.org/uk/docs/guides/event-loop-timers-and-nexttick/">The Node.js Event Loop, Timers, and process.nextTick() | Node.js</a></li><li><a href="https://www.dynatrace.com/news/blog/all-you-need-to-know-to-really-understand-the-node-js-event-loop-and-its-metrics/">All you need to know to really understand the Node.js Event Loop and its Metrics</a></li><li><a href="https://www.codementor.io/@simenli/demystifying-asynchronous-programming-part-1-node-js-event-loop-7r503akaj">Demystifying Asynchronous Programming Part 1: Node.js Event Loop | Codementor</a></li></ul><p>I would truly recommend going through all the above links.</p><p><strong>Nodejs Golden Rule</strong></p><blockquote><strong><em>Don’t block the event loop, keep it running and avoid anything that could block the thread-like synchronous network calls or infinite loops.</em></strong></blockquote><p>I believe that by reading the above posts now you understand the event loop and its core. So now we can discuss a few points where we can tune Node performance. Most of the points are centered around the event loop(Reactor pattern) only as it’s the core of Nodejs responsible for asynchronous IO.</p><p><strong>Tip#1</strong></p><p>Don’t read big files synchronously. Avoid it, and use streams whenever possible (<strong><em>Be aware of </em></strong><a href="https://nodejs.org/en/docs/guides/backpressuring-in-streams/"><strong><em>back pressuring in streams</em></strong></a>).</p><p><strong>Tip#2</strong></p><p>Don’t write long-running blocking code in callbacks. It will stall the event loop and prevent other code from being executed.</p><p><strong>Tip#3</strong></p><p>Avoid recursive calls to <strong><em>process.nextTick.</em></strong> Use <strong><em>setImmediate</em></strong> whenever possible for such use cases.</p><p><strong>Tip#4: Complex calculations without blocking the Event Loop</strong></p><p>Suppose you want to do complex calculations in JavaScript without blocking the Event Loop. You have two options: partitioning or offloading.</p><p><strong>Partitioning</strong></p><p>Consider below: Partitioned average, each of the n asynchronous steps costs O(1).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37767c9ab3035813b4a3dbfa0ca6d253/href">https://medium.com/media/37767c9ab3035813b4a3dbfa0ca6d253/href</a></iframe><p><strong>Offloading</strong></p><p>If you need to do something more complex, partitioning is not a good option. This is because partitioning uses only the Event Loop, and you won’t benefit from multiple cores almost certainly available on your machine. <em>Remember, the Event Loop should orchestrate client requests, not fulfill them itself.</em> For a complicated task, move the work off of the Event Loop onto a Worker Pool. We can use child_process, cluster module or Worker threads as per the need. But there are few downsides as well. <a href="https://nodejs.org/en/docs/guides/dont-block-the-event-loop/"><em>Read </em></a><em>more here.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34581d1d29e063c579a02af5d473cc0d/href">https://medium.com/media/34581d1d29e063c579a02af5d473cc0d/href</a></iframe><p><strong>Tip#5 Utilize all Cors of CPU</strong></p><blockquote><strong>Use this when worker threads are not useful for the use cases you have.</strong></blockquote><p>A Node.js application runs on a single thread. On multicore machines that means that the load isn’t distributed over all cores. Using the <a href="https://nodejs.org/api/cluster.html">cluster module</a> that comes with Node it’s easy to spawn a child process per CPU. Each child process maintains its own event loop and the master process transparently distributes the load between all childs.</p><p><strong>Tip#6 Tune the Thread Pool</strong></p><p>Libuv will create a thread pool with a size of 4. The default size of the pool can be overridden by setting the environment variable UV_THREADPOOL_SIZE. While this can solve load problems on I/O-bound applications. I’d recommend excessive load testing as a larger thread pool might still exhaust the memory or the CPU.</p><p><strong>Tip# 7 Offload the work to Services</strong></p><p>If Node.js spends too much time with CPU heavy operations, offloading work to services maybe even using another language that better suits a specific task might be a viable option.</p><p><strong>Tip#8: Know, how </strong><a href="https://medium.com/@michael.gokhman/nodejs-how-even-quick-async-functions-can-block-the-event-loop-starve-io-8c416d76daa3"><strong>even quick async functions can block the Event-Loop, starve I/O</strong></a></p><p><strong>Tip#9</strong></p><p>Use lib like <a href="https://www.npmjs.com/package/JSONStream"><em>JSONStream</em></a><em> </em>instead of<em> JSON.stringify and JSON.parse</em> for large JSON.</p><p><strong>Tip#10: Set NODE_ENV</strong></p><p>Always set NODE_ENV according to your development activity(‘development’,’test’,’production’ etc.). Setting NODE_ENV to production makes your application 3 times faster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOzDs3fpnH5JAmcSdvfSoA.png" /><figcaption>Source:<a href="https://github.com/goldbergyoni/nodebestpractices/blob/master/sections/production/setnodeenv.md">https://github.com/goldbergyoni/nodebestpractices/blob/master/sections/production/setnodeenv.md</a></figcaption></figure><h4>Tip#11:</h4><p>Prefer native JS methods over user-land utils like Lodash whenever possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yHOI_77SweiaTzaKTrEDJw.png" /><figcaption>Source: <a href="https://github.com/sandeepp2016/nodebestpractices/blob/master/sections/performance/nativeoverutil.md">https://github.com/sandeepp2016/nodebestpractices/blob/master/sections/performance/nativeoverutil.md</a></figcaption></figure><h4>Tip#12<strong> Use async-await and promises wisely:</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4b4e7b822ad7a6be8f4eae10bc011d3/href">https://medium.com/media/c4b4e7b822ad7a6be8f4eae10bc011d3/href</a></iframe><h4>Tip#13: <strong>Go Parallel</strong></h4><p>Considering the previous point, try to do all your blocking operations — that is, requests to remote services, DB calls, and file system access — in parallel. This will reduce latency to the slowest of the blocking operations rather than the sum of each one in sequence. To keep the callbacks and error handling clean you can leverage control flow library like ‘async’ or can use built-in Promise library</p><p><strong>Tip#14: Use binary modules</strong></p><p>When available, use binary<strong> m</strong>odules instead of JavaScript modules. For example, when you switched from a crypto-js module written in JavaScript to the compiled version that comes with Node.js, you see a big performance bump.</p><p><strong>Tip#15: Do logging wisely</strong></p><p>In general, there are two reasons for logging from your app: For debugging and for logging app activity (essentially, everything else). Using console.log() or console.error() to print log messages to the terminal is common practice in development. But <a href="https://nodejs.org/api/console.html#console_console_1">these functions are synchronous</a> when the destination is a terminal or a file, so they are not suitable for production unless you pipe the output to another program.</p><p><strong>For debugging</strong></p><p>If you’re logging for purposes of debugging, then instead of using, use a special debugging module like <a href="https://www.npmjs.com/package/debug">debug</a>. This module enables you to use the DEBUG environment variable to control what debug messages are sent to console.error(), if any. To keep your app purely asynchronous, you’d still want to pipe console.error() to another program. But then, you’re not really going to debug in production, are you?</p><p><strong>For app activity</strong></p><p>If you’re logging app activity (for example, tracking traffic or API calls), instead of using console.log(), use a logging library like <a href="https://www.npmjs.com/package/winston">Winston</a> or <a href="https://www.npmjs.com/package/bunyan">Bunyan</a>. For a detailed comparison of these two libraries, see the StrongLoop blog post <a href="https://strongloop.com/strongblog/compare-node-js-logging-winston-bunyan/">Comparing Winston and Bunyan Node.js Logging</a>.</p><p><strong>Tip#16 Use tool like </strong><a href="https://clinicjs.org/documentation/doctor/05-fixing-event-loop-problem/"><strong>Node-Clinic </strong></a><strong>to detect event loop problem and Identify the bottlenecks.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*kO8zvc8uGV7SQaNs3c9ssA.gif" /><figcaption>courtesy: <a href="https://clinicjs.org/doctor/">https://clinicjs.org/doctor/</a></figcaption></figure><p>See live example here <a href="https://upload.clinicjs.org/public/bfd578cbe5157c53080bea935667dc7523099050f4b0bc6f7394695021be21bd/18034.clinic-doctor.html">https://upload.clinicjs.org/public/bfd578cbe5157c53080bea935667dc7523099050f4b0bc6f7394695021be21bd/18034.clinic-doctor.html</a></p><p><strong>Summary:</strong></p><p>Most of the things I have discussed here are centered around the event loop as it is the core of Nodejs which enables asynchronous IO. It&#39;s very important to learn and understand the Event loop. This event loop is maybe the most misunderstood concept of the platform. Most people fail their first few NodeJS apps merely due to the lack of understanding of the concepts such as the Event Loop, Error handling and asynchrony.</p><p>Operations with high complexity, large JSON parsing, applying logic over huge arrays, unsafe regex queries, and large IO operations are some of the operations that can cause the Event Loop to stall. Avoid this off-loading CPU intensive tasks to a dedicated service (e.g. job server), or breaking long tasks into small steps then using the Worker Pool are some examples of how to avoid blocking the Event Loop.</p><p>This is it for now. I hope you learned something by reading it. Feel free to drop your comments. If you like it please share it with your friends.</p><p><strong>Further Reading</strong></p><ul><li><a href="https://blog.insiderattack.net/event-loop-best-practices-nodejs-event-loop-part-5-e29b2b50bfe2">https://blog.insiderattack.net/event-loop-best-practices-nodejs-event-loop-part-5-e29b2b50bfe2</a></li><li><a href="https://nodejs.org/en/docs/guides/">https://nodejs.org/en/docs/guides/</a></li><li><a href="https://nodejs.org/en/docs/guides/dont-block-the-event-loop/">https://nodejs.org/en/docs/guides/dont-block-the-event-loop/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44aad81d95c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nodejsmadeeasy/a-few-tips-to-improve-nodejs-performance-44aad81d95c2">A few tips to improve Nodejs performance</a> was originally published in <a href="https://medium.com/nodejsmadeeasy">NodeStack</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Https for Localhost]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/etc-a2z/setting-up-https-for-localhost-7e9a18253ca?source=rss-702b35e32ca7------2"><img src="https://cdn-images-1.medium.com/max/600/0*QhiqWyLknwyNuXTe.png" width="600"></a></p><p class="medium-feed-snippet">In this blog post, I will show you how to set up working https with a green lock. Before we start let&#x2019;s talk about a few terminologies:</p><p class="medium-feed-link"><a href="https://medium.com/etc-a2z/setting-up-https-for-localhost-7e9a18253ca?source=rss-702b35e32ca7------2">Continue reading on $/etc »</a></p></div>]]></description>
            <link>https://medium.com/etc-a2z/setting-up-https-for-localhost-7e9a18253ca?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e9a18253ca</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[https]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Mon, 27 Jan 2020 23:50:07 GMT</pubDate>
            <atom:updated>2024-09-30T22:47:44.471Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Worker  Threads examples in Nodejs]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/nodejsmadeeasy/workers-threads-in-node-js-part2-ec45ac084963?source=rss-702b35e32ca7------2"><img src="https://cdn-images-1.medium.com/max/660/1*x7z8fnI3PKau1o_2u31U3g.jpeg" width="660"></a></p><p class="medium-feed-link"><a href="https://medium.com/nodejsmadeeasy/workers-threads-in-node-js-part2-ec45ac084963?source=rss-702b35e32ca7------2">Continue reading on NodeStack »</a></p></div>]]></description>
            <link>https://medium.com/nodejsmadeeasy/workers-threads-in-node-js-part2-ec45ac084963?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec45ac084963</guid>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[node-js-tutorial]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Sun, 29 Dec 2019 17:39:08 GMT</pubDate>
            <atom:updated>2024-09-21T06:01:07.989Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Worker Threads In Node.js]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/nodejsmadeeasy/workers-threads-in-node-js-part1-30e0285753d4?source=rss-702b35e32ca7------2"><img src="https://cdn-images-1.medium.com/max/2100/0*B3H2gSr9s6obeGRF.jpg" width="2100"></a></p><p class="medium-feed-snippet">Workers thread were introduced in Node v10.x as an experimental API and now stable since v12.x. As we all know Nodejs single-threaded(kind&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/nodejsmadeeasy/workers-threads-in-node-js-part1-30e0285753d4?source=rss-702b35e32ca7------2">Continue reading on NodeStack »</a></p></div>]]></description>
            <link>https://medium.com/nodejsmadeeasy/workers-threads-in-node-js-part1-30e0285753d4?source=rss-702b35e32ca7------2</link>
            <guid isPermaLink="false">https://medium.com/p/30e0285753d4</guid>
            <category><![CDATA[node-js-tutorial]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Sandeep]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 07:20:23 GMT</pubDate>
            <atom:updated>2024-09-21T05:56:13.842Z</atom:updated>
        </item>
    </channel>
</rss>