<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 💻 Bleeding Code-By John Jardin</title>
    <description>The latest articles on DEV Community by 💻 Bleeding Code-By John Jardin (@bleedingcode).</description>
    <link>https://dev.to/bleedingcode</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F180475%2Ff2cb6836-2ae6-4ac5-82a8-99710f86b39b.jpg</url>
      <title>DEV Community: 💻 Bleeding Code-By John Jardin</title>
      <link>https://dev.to/bleedingcode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bleedingcode"/>
    <language>en</language>
    <item>
      <title>JavaScript's Clipboard Copy: Crafting with AI</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Fri, 07 Jul 2023 11:20:57 +0000</pubDate>
      <link>https://dev.to/bleedingcode/javascripts-clipboard-copy-crafting-with-ai-5h7e</link>
      <guid>https://dev.to/bleedingcode/javascripts-clipboard-copy-crafting-with-ai-5h7e</guid>
      <description>&lt;p&gt;When it comes to &lt;a href="https://www.javascript.com/"&gt;JavaScript&lt;/a&gt;, the devil is often in the details. Even seemingly simple functions can contain a world of complexity, especially when we aim to make our code &lt;strong&gt;robust&lt;/strong&gt;, &lt;strong&gt;reusable&lt;/strong&gt;, &lt;strong&gt;readable&lt;/strong&gt;, and adaptable to varying browser capabilities.&lt;/p&gt;

&lt;p&gt;Take, for instance, a function that copies text to the clipboard. It might seem straightforward, but there are multiple aspects to consider: What if the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API"&gt;Clipboard API&lt;/a&gt; is not supported? How can we handle different types of input?&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter Artificial Intelligence
&lt;/h2&gt;

&lt;p&gt;To address these questions, I embarked on a journey to craft a &lt;code&gt;copyTextToClipboard&lt;/code&gt; function that could stand the test of real-world applications. I had an AI partner on this journey: &lt;a href="https://openai.com/research/gpt-4"&gt;GPT-4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So why choose this particular function? While I haven't encountered issues with existing Copy To Clipboard functions, the goal was to create one that not only functions effectively but is also built according to the latest JS standards and best practices.&lt;/p&gt;

&lt;p&gt;Here's what we developed (&lt;strong&gt;Note&lt;/strong&gt;: &lt;a href="https://codepen.io/Bleeding-Code/pen/eYQEXRv"&gt;Click here&lt;/a&gt; to open the below code on &lt;strong&gt;CodePen.io&lt;/strong&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Copies the provided text to the clipboard.
 *
 * @param {string} text - The text to be copied to the clipboard.
 * @returns {Promise} A promise that resolves when the text has been successfully copied, or rejects when an error occurs or the Clipboard API is not supported.
 */
const copyTextToClipboard = (text) =&amp;gt; {
  return new Promise((resolve, reject) =&amp;gt; {
    // Check if the text is a string and not empty.
    if (typeof text !== "string" || text.trim() === "") {
      reject(new Error("Invalid text: Text should be a non-empty string."));
      return;
    }

    // Check if the Clipboard API is supported.
    if (!navigator.clipboard) {
      reject(new Error("Clipboard API not supported"));
      return;
    }

    // Try to write the text to the clipboard.
    navigator.clipboard
      .writeText(text)
      .then(resolve) // If successful, resolve the promise.
      .catch(reject); // If an error occurs, reject the promise with the error.
  });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, why should you consider using this function over others? Here are some key reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Robust Error Handling:&lt;/strong&gt; This function checks if the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API"&gt;Clipboard API&lt;/a&gt; is supported and ensures that the text to be copied is a non-empty string. This makes it more robust against potential misuse.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous Operation:&lt;/strong&gt; The function leverages &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"&gt;JavaScript Promises&lt;/a&gt; for asynchronous execution, making it compatible with &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function"&gt;async/await&lt;/a&gt; syntax and suitable for applications that need non-blocking operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Best Practices:&lt;/strong&gt; The function is designed with modern JavaScript best practices in mind, from the use of &lt;code&gt;const&lt;/code&gt; for function declaration, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions"&gt;arrow functions&lt;/a&gt;, to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals"&gt;template strings&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Learn To Prep AI Before Asking Questions
&lt;/h2&gt;

&lt;p&gt;Working with GPT on this was quite an experience. I learned &lt;a href="https://youtube.com/live/c1Et1-iiDGU?feature=share"&gt;the hard way&lt;/a&gt; that it's essential to &lt;strong&gt;define GPT's persona&lt;/strong&gt; and provide as much &lt;strong&gt;context&lt;/strong&gt; as possible-the more precise and specific the instructions, the more satisfactory and applicable the results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here's an example of what I asked GPT:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Act as a JavaScript Developer using the latest stable ECMA Script standards that are supported on modern browsers. You only write robust, reusable, readable, well-documented, performant, and secure code that conforms to best practices for production environments. Perform a code review of the following JavaScript function and if it fails your standards and practices, rewrite it with explanations of what you changed and why:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I then pasted a version of &lt;code&gt;copyTextToClipboard&lt;/code&gt; that I felt was quite good.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In response, GPT not only followed my instructions but also added additional value, enhancing readability, reusability, and error handling in the function. The collaboration resulted in a piece of code I was happy to add to my project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Considerations
&lt;/h2&gt;

&lt;p&gt;It's important to understand the caveats when working with a function like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The use of the Clipboard API:&lt;/strong&gt; The Clipboard API requires &lt;strong&gt;permission&lt;/strong&gt; and only works in a secure context (HTTPS), which could limit the usability of your function in some situations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser Compatibility:&lt;/strong&gt; Although the Clipboard API is widely supported, there may be &lt;strong&gt;compatibility issues&lt;/strong&gt; with older browsers or less popular ones that do not fully support this API.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; While this function is unlikely to be a performance bottleneck, one has to keep in mind that varied results could occur depending on the &lt;strong&gt;size of the text&lt;/strong&gt; to be copied.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;As we continue to adopt AI tools like &lt;a href="https://chat.openai.com/"&gt;GPT&lt;/a&gt; and &lt;a href="https://bard.google.com/"&gt;Google Bard&lt;/a&gt; in our coding journeys, we not only enhance our coding practices but also create new opportunities for innovation and improvement.&lt;/p&gt;

&lt;p&gt;Feel free to use this function in your projects and, more importantly, reference &lt;a href="https://codepen.io/Bleeding-Code/pen/eYQEXRv"&gt;this function on CodePen.io&lt;/a&gt; for the latest version. &lt;/p&gt;

&lt;p&gt;Till next time - John 🙂&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>ai</category>
      <category>programming</category>
    </item>
    <item>
      <title>Finally!! A Blockchain For Any Programming Language (Video)</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Thu, 18 Aug 2022 12:51:53 +0000</pubDate>
      <link>https://dev.to/bleedingcode/finally-a-blockchain-for-any-programming-language-video-37e4</link>
      <guid>https://dev.to/bleedingcode/finally-a-blockchain-for-any-programming-language-video-37e4</guid>
      <description>&lt;p&gt;I have exciting news for any developer who programs using a modern language like JavaScript, Python, C#, etc.&lt;/p&gt;

&lt;p&gt;A new blockchain called &lt;a href="https://medium.com/r/?url=http%3A%2F%2Fqanplatform.com"&gt;QANplatform&lt;/a&gt; allows you to design &lt;strong&gt;Smart Contracts&lt;/strong&gt; using your existing skillset and programming environment. And even better, the blockchain automatically &lt;strong&gt;pays you royalties&lt;/strong&gt; in crypto if your contracts are generic so that other applications can use them.&lt;/p&gt;

&lt;p&gt;In this video, I discuss problems with Web3 and how the QANplatform will solve many of them. Whether you’re a technical or non-technical person, you must understand what’s coming, so you can take full advantage as a developer and a business.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/bjtRfcenSWE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Video Chapters
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=bjtRfcenSWE&amp;amp;t=0s"&gt;0:00&lt;/a&gt; Intro&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=bjtRfcenSWE&amp;amp;t=39s"&gt;0:39&lt;/a&gt; How I started with Web3 as a NodeJS Dev&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=bjtRfcenSWE&amp;amp;t=101s"&gt;1:41&lt;/a&gt; The problem with Web3 preventing Mass Adoption&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=bjtRfcenSWE&amp;amp;t=704s"&gt;11:44&lt;/a&gt; How can we fix Web3 for Mass Adoption&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=bjtRfcenSWE&amp;amp;t=1215s"&gt;20:15&lt;/a&gt; What is the QANplatform&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=bjtRfcenSWE&amp;amp;t=1435s"&gt;23:55&lt;/a&gt; Unique features that QANplatform offers&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=bjtRfcenSWE&amp;amp;t=2038s"&gt;33:58&lt;/a&gt; A message from John Jardin&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=bjtRfcenSWE&amp;amp;t=2071s"&gt;34:31&lt;/a&gt; How QANplatform benefits developers and businesses&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=bjtRfcenSWE&amp;amp;t=3071s"&gt;51:11&lt;/a&gt; Final Notes about the QANplatform&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reference Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.qanplatform.com"&gt;QANplatform Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.qanplatform.com"&gt;QANplatform Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.qanplatform.com/community/social-media"&gt;QANplatform Social Media&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://t.me/QANplatform"&gt;QANplatform Telegram Group&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://discord.com/invite/PYBxQsudTE"&gt;QANplatform Discord Server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://research.ibm.com/blog/ibm-quantum-roadmap"&gt;IBM Quantum Computer Roadmap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/vercel/pkg"&gt;PKG NodeJS Compiler By Vercel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://faucet.egorfine.com"&gt;rETH Faucet For Ropsten Ethereum Testnet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://daodao.io/d/Web3Simplified"&gt;Web3 Simplified DAO&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtube.com/web3simplified"&gt;Web3 Simplified YouTube Channel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtube.com/bleedingcode"&gt;Bleeding Code YouTube Channel&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>blockchain</category>
      <category>programming</category>
      <category>web3</category>
      <category>javascript</category>
    </item>
    <item>
      <title>What is the DeSo Blockchain 💎  | Post-2-Earn Crypto</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Mon, 02 May 2022 11:36:47 +0000</pubDate>
      <link>https://dev.to/bleedingcode/what-is-the-deso-blockchain-post-2-earn-crypto-een</link>
      <guid>https://dev.to/bleedingcode/what-is-the-deso-blockchain-post-2-earn-crypto-een</guid>
      <description>&lt;p&gt;In this tutorial, you will learn exactly what &lt;a href="https://www.deso.org/"&gt;DeSo&lt;/a&gt; is, how it compares to applications like &lt;a href="https://twitter.com/"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.facebook.com/"&gt;Facebook&lt;/a&gt;, how you can earn crypto just by posting a message and why it's the future of &lt;a href="https://www.investopedia.com/terms/s/social-media.asp"&gt;social media&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/5jHXBYUb7X4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What is DeSo
&lt;/h2&gt;

&lt;p&gt;DeSo stands for &lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Decentralization"&gt;Decentralized&lt;/a&gt;&lt;/strong&gt; &lt;strong&gt;Social&lt;/strong&gt; and is a new kind of internet where all social media content exists openly on a blockchain. Because the content is on a blockchain, which is scaled across many computers all around the world, no one person or central authority can own the data, hence the term &lt;strong&gt;Decentralized&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--julYGGRa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w87j33o1vzgty6dsy81f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--julYGGRa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w87j33o1vzgty6dsy81f.jpg" alt="DeSo is a decentralized social media platform" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Centralized vs Decentralized
&lt;/h2&gt;

&lt;p&gt;You might be wondering, "Is DeSo then like Twitter or Facebook"? And the answer is "no", because DeSo is so much bigger. To understand it, let's use the following example:&lt;/p&gt;

&lt;p&gt;When you posted a Tweet on Twitter's website, did that tweet appear on Facebook, &lt;a href="https://instagram.com/"&gt;Instagram&lt;/a&gt; or &lt;a href="https://www.linkedin.com/"&gt;LinkedIn&lt;/a&gt;? It didn't. This is because behind the Twitter app is a platform that is owned by Twitter, where all tweets, user profiles, images and videos are stored. Twitter is what is known as a &lt;strong&gt;centralized&lt;/strong&gt; social media platform, because they own the data and govern what content or user accounts can exist. Nearly every other social media platform at present falls into this category.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SDQ6qqm0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rjqykl97dnbw1xv0zw88.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SDQ6qqm0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rjqykl97dnbw1xv0zw88.jpg" alt="Most social media platforms to date are centralized" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem with this setup is that you, the &lt;strong&gt;User&lt;/strong&gt;, have become the product and advertisers, the &lt;strong&gt;Customer&lt;/strong&gt;. Absolutely everything you say and do on these platforms is analyzed by the company that owns it. This data is then used to sell targeted advertising and worse, influence you via your social feed to better benefit advertisers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QcoKaeam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kd6e1i8g31to8thjkfec.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QcoKaeam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kd6e1i8g31to8thjkfec.jpg" alt="Centralized social media platforms use your data to sell targeted advertising" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A new kind of Social Media
&lt;/h2&gt;

&lt;p&gt;But what if your post didn't exist only on Facebook's platform, but rather on an open platform that can be used by any social media application? What if you were a Twitter user and decided to start using Instagram, but instead of having to create a new account there, and rebrand yourself on a new platform, your current profile, followers, who you're following and all your activities are automatically available. You would be able to continue on Instagram where you left off on Twitter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Xo6-1Hq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6j7y2rgeend5j9sj3u1d.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Xo6-1Hq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6j7y2rgeend5j9sj3u1d.jpg" alt="Social media content shared across all applications" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DeSo&lt;/strong&gt; is the solution that makes all of this possible and eliminates the downsides of a centralized social media platform. It's not a Facebook or Twitter lookalike, but rather, it's the underlying system that stores and manages all content that would be created and referenced by social media applications.&lt;/p&gt;

&lt;p&gt;On DeSo, you will only ever need a &lt;strong&gt;single user account&lt;/strong&gt; to access any of the applications that have been developed on the DeSo blockchain. Everything you say and do on any of the applications will be linked to your account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pBKQ_en5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u39isdyh35qmmolukj1p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pBKQ_en5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u39isdyh35qmmolukj1p.jpg" alt="One social media account across all applications" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Applications on the DeSo Blockchain
&lt;/h2&gt;

&lt;p&gt;At the time of this tutorial, there are over &lt;strong&gt;200&lt;/strong&gt; applications that exist on the DeSo blockchain. A few that are worth mentioning are:&lt;/p&gt;

&lt;h3&gt;
  
  
  Diamond App
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://diamondapp.com/"&gt;Diamond&lt;/a&gt; is one of the first applications to be developed on DeSo. Diamond's features are similar to Twitter, in that you can post, like, retweet, follow and send direct messages. However, because Diamond is built on top of a blockchain, there are a number of additional features:&lt;/p&gt;

&lt;p&gt;Using DeSo's crypto coin (&lt;strong&gt;$DESO&lt;/strong&gt;), you can reward users crypto for their posts or be rewarded for yours&lt;/p&gt;

&lt;p&gt;Any post can also be converted into a &lt;strong&gt;NFT&lt;/strong&gt;, which can be transferred, sold or auctioned on the DeSo blockchain&lt;/p&gt;

&lt;p&gt;Every user profile has their own crypto token called &lt;strong&gt;Creator Coin&lt;/strong&gt;. This allows others to invest in you as a content creator and vice versa&lt;/p&gt;

&lt;h3&gt;
  
  
  Overclout
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://overclout.com/"&gt;Overclout&lt;/a&gt; is similar to Diamond, but allows you to post &lt;strong&gt;stories&lt;/strong&gt;, &lt;strong&gt;livestream&lt;/strong&gt; or create rich text content such as &lt;strong&gt;articles&lt;/strong&gt; and &lt;strong&gt;tutorials&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  DeSocialWorld
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://desocialworld.com/"&gt;DeSocialWorld&lt;/a&gt; provides social media content in multiple languages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mousai
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://mousai.stream/"&gt;Mousai&lt;/a&gt; allows you to stream music and invest in your favorite artists.&lt;/p&gt;

&lt;h3&gt;
  
  
  Entre
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://joinentre.com/"&gt;Entre&lt;/a&gt; is a professional network similar to LinkedIn.&lt;/p&gt;

&lt;p&gt;These are but a few of the many applications that exist on the DeSo blockchain and the list continues to grow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i9ztgk3F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqgiamcrtco7ax6vepwy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i9ztgk3F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqgiamcrtco7ax6vepwy.jpg" alt="Some of the apps built on top of the DeSo Blockchain" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;With decentralized content, &lt;strong&gt;post-2-earn&lt;/strong&gt; capabilities and a vast range of social media applications, DeSo has become a blockchain like no other and is truly the future of social media.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VsVuz77d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxmd3038cjlw79bg9ed6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VsVuz77d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxmd3038cjlw79bg9ed6.jpg" alt="DeSo for the win" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>deso</category>
      <category>blockchain</category>
      <category>web3</category>
      <category>decentralized</category>
    </item>
    <item>
      <title>How To Create Your First Flow In Node-RED</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Tue, 25 May 2021 04:48:37 +0000</pubDate>
      <link>https://dev.to/bleedingcode/how-to-create-your-first-flow-in-node-red-4ap1</link>
      <guid>https://dev.to/bleedingcode/how-to-create-your-first-flow-in-node-red-4ap1</guid>
      <description>&lt;p&gt;This post introduces a deep dive video tutorial where I teach you the fundamentals of &lt;a href="https://nodered.org"&gt;Node-RED&lt;/a&gt; and at the same time, show you how to build a &lt;strong&gt;Weather Forecast Dashboard&lt;/strong&gt;. To make the dashboard work, we'll need to integrate with 3 online APIs that will provide the current weather forecast, a 5 day forecast, and information about the country connected to the town or city being searched.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7DZc1P3w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hwuwuhd3okhzohqy61z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7DZc1P3w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hwuwuhd3okhzohqy61z.png" alt="Alt Text" width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This video tutorial shows you step by step, how we bring these APIs together in &lt;strong&gt;Node-RED&lt;/strong&gt;, to produce a weather service in the form of a UI dashboard. Once you've completed this tutorial, you will have a good enough understanding of Node-RED, enough to be able to get up and running with your own flows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; This is my first deep dive video and I would really appreciate honest feedback as to if this kind of content adds value and if yes, how can I better it for future videos to come.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Also see below references to mentioned websites, online tools as well as GitHub resources for the &lt;strong&gt;Node-RED Weather Dashboard&lt;/strong&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Video Tutorial
&lt;/h1&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/cVWVr_T7kQ0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/bleedingcode/node-red-weather-dashboard"&gt;Weather Dashboard GitHub Repo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://openweathermap.org"&gt;Open Weather Map&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://restcountries.eu"&gt;Rest Countries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.postman.com"&gt;Postman API Testing Tool&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/janl/mustache.js"&gt;MustacheJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/playlist?list=PLISqeoHsXJYBriF8VE_CrDvNGURq2c2m6"&gt;Up And Running With Node-RED Playlist - Bleeding Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/Xm35Xk5mnwg"&gt;Advanced Setup of Node-RED - Bleeding Code Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodered.org/docs/getting-started/"&gt;Node-RED Getting Started Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jsbin.com"&gt;JSBin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://bootsnipp.com"&gt;Bootsnip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://youtube.com/bleedingcode"&gt;Bleeding Code - YouTube Channel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://twitter.com/bleedcode"&gt;Bleeding Code - Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.facebook.com/bleedingcode"&gt;Bleeding Code - Facebook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Advanced Setup Of Node-RED In Easy Steps</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Thu, 20 May 2021 03:53:58 +0000</pubDate>
      <link>https://dev.to/bleedingcode/advanced-setup-of-node-red-in-easy-steps-466b</link>
      <guid>https://dev.to/bleedingcode/advanced-setup-of-node-red-in-easy-steps-466b</guid>
      <description>&lt;p&gt;In this article I'm going to show you how to install a &lt;a href="https://nodered.org"&gt;Node-RED&lt;/a&gt; Server that includes optional advanced capabilities, that are not available by default with the standard installs mentioned in Node-RED's &lt;a href="https://nodered.org/docs/getting-started/"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're following my &lt;a href="https://www.youtube.com/playlist?list=PLISqeoHsXJYBriF8VE_CrDvNGURq2c2m6"&gt;Up and Running with Node-RED&lt;/a&gt; series, you'll know that my intention is to teach you how to use Node-RED as a tool for business app development and integration, instead of just home automation and hobby-based projects. To achieve this, we cannot setup Node-RED the traditional way, which is installing it as a global module on our local machine. We need more control and flexibility. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To run multiple instances of Node-RED&lt;/li&gt;
&lt;li&gt;To containerize and deploy to various on-prem and cloud environments&lt;/li&gt;
&lt;li&gt;To integrate with 3rd party services&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything needs to be achievable from one Node-RED instance, and today's install will give us just that.&lt;/p&gt;

&lt;h1&gt;
  
  
  Watch Video On YouTube
&lt;/h1&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Xm35Xk5mnwg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Node JS and NPM Required
&lt;/h1&gt;

&lt;p&gt;To start, you need to have at least Node JS &lt;a href="https://nodejs.org/download/release/v12.18.4/"&gt;12.18&lt;/a&gt; or higher installed on your machine. If you have an older version or don't have &lt;a href="https://nodejs.org/en/"&gt;Node&lt;/a&gt; installed, I highly recommend using a Node Version Manager to be able to install one or multiple versions of Node. There are many great Version Managers out there, but for an immediate recommendation, &lt;a href="https://github.com/nvm-sh/nvm"&gt;NVM&lt;/a&gt; is one that we at &lt;a href="https://agilite.io"&gt;Agilit-e&lt;/a&gt; use and it works very well. Not only will you be able to easily switch between various versions of Node, but NVM also takes care of permission issues on your Operating System that sometimes occur when installing Node directly.&lt;/p&gt;

&lt;h1&gt;
  
  
  Find "agilite-node-red" on GitHub
&lt;/h1&gt;

&lt;p&gt;Now, the boilerplate Node-RED server we're going to be using can be found on GitHub and is called &lt;a href="https://github.com/agilitehub/agilite-node-red"&gt;agilite-node-red&lt;/a&gt;. This repo is maintained by the team at &lt;a href="https://agilite.io"&gt;Agilit-e&lt;/a&gt; and provides the control and flexibility mentioned earlier.&lt;/p&gt;

&lt;h1&gt;
  
  
  Download Relevant Version
&lt;/h1&gt;

&lt;p&gt;Once the boilerplate repo is open in your browser, switch the branch from Master to &lt;a href="https://github.com/agilitehub/agilite-node-red/tree/7.3.1"&gt;7.3.1&lt;/a&gt;. This is the current boilerplate version as per the release of this article, is compatible with &lt;strong&gt;Node 12.18&lt;/strong&gt; and runs &lt;strong&gt;Node-RED 1.3.4&lt;/strong&gt;. Should you be reading this article long after it was released, you can switch to newer branches which will support upgraded versions of Node and Node-RED. Reference the &lt;strong&gt;README&lt;/strong&gt; file for these versions.&lt;/p&gt;

&lt;p&gt;Once you've switched to branch &lt;strong&gt;7.3.1&lt;/strong&gt;, click on the &lt;strong&gt;Code&lt;/strong&gt; button, following by clicking on &lt;strong&gt;download zip&lt;/strong&gt; to download the boilerplate to your local environment. One downloaded, extract the zip file, which will extract the boilerplate to a folder called &lt;strong&gt;agilite-node-red-7.3.1&lt;/strong&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Install Node Modules
&lt;/h1&gt;

&lt;p&gt;Via your Terminal or Command Prompt, navigate to the boilerplate folder and run the following command &lt;code&gt;npm ci - only=production&lt;/code&gt;. This installs the main project dependencies based on the &lt;strong&gt;package-lock.json&lt;/strong&gt; file and ignores the dev dependencies which you don't need. This ensures the boilerplate's node modules are installed the way we intended, to avoid possible inconsistencies and problems.&lt;/p&gt;

&lt;p&gt;Once the NPM install is complete, enter the command &lt;code&gt;npm run main&lt;/code&gt;. This starts up the Node-RED server, which you can now access by opening your preferred web browser and entering the URL: &lt;a href="http://localhost:6020"&gt;http://localhost:6020&lt;/a&gt;. If all was successful, you will see the &lt;strong&gt;Node-RED Editor&lt;/strong&gt; open in your browser's window. You are now ready to start using Node-RED.&lt;/p&gt;

&lt;h1&gt;
  
  
  Closing
&lt;/h1&gt;

&lt;p&gt;As mentioned before, this boilerplate offers everything of Node-RED and more, which I'll be taking everyone through step by step in my &lt;a href="https://www.youtube.com/playlist?list=PLISqeoHsXJYBriF8VE_CrDvNGURq2c2m6"&gt;Up and Running with Node-RED&lt;/a&gt; series. So if you haven't yet, be sure to subscribe to my &lt;a href="https://www.youtube.com/bleedingcode"&gt;YouTube channel&lt;/a&gt;, or alternatively follow me on this site. In the meantime though, I welcome you to peruse the configuration for this boilerplate, which can be found in the &lt;strong&gt;config/templates&lt;/strong&gt; folder, in a file called &lt;strong&gt;default-config.json&lt;/strong&gt;. This is where much of the magic happens, but more on that very soon.&lt;/p&gt;

&lt;p&gt;Until next time though…cheers :)&lt;/p&gt;

</description>
      <category>node</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Visual NodeJS Programming Using Node-RED</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Thu, 13 May 2021 04:40:53 +0000</pubDate>
      <link>https://dev.to/bleedingcode/visual-nodejs-programming-using-node-red-56n6</link>
      <guid>https://dev.to/bleedingcode/visual-nodejs-programming-using-node-red-56n6</guid>
      <description>&lt;p&gt;In this article I'm going to introduce you to a &lt;a href="http://nodejs.org"&gt;NodeJS&lt;/a&gt; module that allows you to create and deploy server-side processes by using a visual, drag n drop style interface in your Web Browser. The module I'm referring to is called &lt;a href="http://nodered.org"&gt;Node-RED&lt;/a&gt;: A flow-based programming tool that allows you to design processes (aka Flows) by wiring together &lt;a href="https://microservices.io"&gt;microservices&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Watch The Video on YouTube
&lt;/h1&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ZXzdzJ9ZYKQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Created in 2013, Node-RED was initially intended for visually wiring together the &lt;a href="https://en.wikipedia.org/wiki/Internet_of_things"&gt;Internet of Things&lt;/a&gt;, but as it matured, it evolved into something way more powerful, enough to be deployed as middleware within enterprise production environments. The power behind Node-RED is how it hides boilerplate code from the design interface, allowing you to quickly build and deploy processes and integrations.&lt;/p&gt;

&lt;p&gt;To demonstrate this, I'm going to compare a simple Node App with a Node-RED Flow, which will show you the time saving to be had and why you should be excited to learn this tech:&lt;/p&gt;

&lt;h1&gt;
  
  
  Simple NodeJS Express App
&lt;/h1&gt;

&lt;p&gt;The code below is for a simple &lt;a href="https://expressjs.com"&gt;Express&lt;/a&gt; application that outputs &lt;strong&gt;Hello World&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  server.js
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Express = require('express')
const App = Express()
const HTTP = require('http')
const Cron = require('node-cron')
const Functions = require('./functions')

// Create Route
App.get('/api/greet', (req, res) =&amp;gt; {
   const result = Functions.greet()
   res.send(result)
})

// Start Server
const port = 6025
HTTP.createServer(App).listen(port, () =&amp;gt; {
   console.log('NodeJS App Listening on: ', port)

   // Schedule CRON Job
   Cron.schedule('*/5 * * * * *', () =&amp;gt; {
      Functions.greet()
   })
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  functions.js
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = () =&amp;gt; {
   const result = 'Hello World'
   console.log(result)
   return result
}
exports.greet = greet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;strong&gt;server.js&lt;/strong&gt;, we've got some logic for our Express server, a scheduled process, as well as an endpoint called &lt;strong&gt;/api/greet&lt;/strong&gt;. We then have a &lt;strong&gt;functions.js&lt;/strong&gt; file that exports a &lt;strong&gt;greet()&lt;/strong&gt; function, which returns the text &lt;strong&gt;Hello World&lt;/strong&gt;. The CRON job in &lt;strong&gt;server.js&lt;/strong&gt; runs every 5 seconds, triggering the &lt;strong&gt;greet()&lt;/strong&gt; function on every run. This function is also triggered by the &lt;strong&gt;/api/greet&lt;/strong&gt; endpoint.&lt;/p&gt;

&lt;p&gt;So the point of this exercise is that we're going to trigger the &lt;strong&gt;greet()&lt;/strong&gt; function using 3 events:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Manually via Terminal&lt;/li&gt;
&lt;li&gt;Via a Web API&lt;/li&gt;
&lt;li&gt;Via a schedule&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  package.json
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   "name": "node-red-intro-nodejs-app",
   "version": "0.0.1",
   "description": "Node-RED Intro - NodeJS App",
   "main": "server.js",
   "scripts": {
      "manual": "node -e \"require('./functions').greet()\"",
      "endpoint": "curl http://localhost:6025/api/greet"
   },
   "engines": {
      "node": "12.18.4"
   },
   "author": "Agilit-e",
   "license": "MIT",
   "dependencies": {
      "express": "4.17.1",
      "node-cron": "3.0.0"
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We trigger the function manually by requiring the &lt;strong&gt;functions.js&lt;/strong&gt; in terminal or command prompt, and executing the &lt;strong&gt;greet()&lt;/strong&gt; function. You can see I've added this as a manual script in &lt;strong&gt;package.json&lt;/strong&gt;, which I will trigger by running &lt;code&gt;npm run manual&lt;/code&gt;. This will write &lt;strong&gt;Hello World&lt;/strong&gt; as a response to the console.&lt;/li&gt;
&lt;li&gt;For our next test we start the NodeJS server and trigger the &lt;strong&gt;greet()&lt;/strong&gt; function via an HTTP request. Our endpoint will be &lt;code&gt;http://127.0.01:6025/api/greet&lt;/code&gt;. Because it's a simple &lt;strong&gt;GET&lt;/strong&gt; request, we can just use &lt;strong&gt;curl&lt;/strong&gt; command in Terminal or alternatively open the URL in a browser window. For ease of execution, I have this also as a script in &lt;strong&gt;package.json&lt;/strong&gt;, which I will trigger using &lt;code&gt;npm run endpoint&lt;/code&gt;. You can see &lt;strong&gt;Hello World&lt;/strong&gt; is returned as a response.&lt;/li&gt;
&lt;li&gt;Finally, we can also see that in the background, the scheduled &lt;strong&gt;CRON&lt;/strong&gt; job is printing the response to the console every 5 seconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, excluding the time that was taken to set up the base of this project, i.e. the &lt;strong&gt;package.json&lt;/strong&gt;, dependencies and HTTP server…creating the HTTP endpoint, the &lt;strong&gt;greet()&lt;/strong&gt; function and the CRON job will take you a couple of minutes if you know what you're doing. For fun, let's see how fast we can achieve this in Node-RED:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; For the Node-RED demo, &lt;a href="https://youtu.be/ZXzdzJ9ZYKQ?t=162"&gt;click here&lt;/a&gt; to watch my video on YouTube or alternatively watch the embedded video above (Fast Forward to minute &lt;a href="https://youtu.be/ZXzdzJ9ZYKQ?t=162"&gt;2:42&lt;/a&gt;). Because we're still at the beginning stages of my &lt;a href="https://www.youtube.com/playlist?list=PLISqeoHsXJYBriF8VE_CrDvNGURq2c2m6"&gt;Node-RED Series&lt;/a&gt; and this is more an introduction article, it will be tough to explain what I'm doing in Node-RED in writing. Apologies for any inconvenience caused.&lt;/p&gt;

&lt;p&gt;Assuming you've watched the the video demo, I trust you enjoyed the fun comparison of native NodeJS and Node-RED. What can take minutes in NodeJS can be achieved in a fraction of the time using Node-RED. Scale that up to a much bigger project and you're going to see a massive time saving.&lt;/p&gt;

&lt;p&gt;Now this is the first article of my &lt;a href="https://www.youtube.com/playlist?list=PLISqeoHsXJYBriF8VE_CrDvNGURq2c2m6"&gt;Up and Running with Node-RED&lt;/a&gt; series, with many more to come that will focus on all areas of Node-RED, from basic to advanced functionality, to real world scenarios. If you're not yet &lt;a href="https://www.youtube.com/bleedingcode"&gt;subscribed&lt;/a&gt; or &lt;a href="https://dev.to/johnjardincodes"&gt;following&lt;/a&gt; me, now would be a great time to do so, so that you're notified when new content is released.&lt;/p&gt;

&lt;p&gt;I want to close off by providing you with a reference to resources that will help you learn more about Node-RED:&lt;/p&gt;

&lt;p&gt;Your first stop will be Node-RED's website - &lt;a href="https://nodered.org"&gt;nodered.org&lt;/a&gt;. This site will give you a lot of insight into what Node-RED is, how it works, and provides proper end to end documentation on how to achieve almost anything you want with it. You can find almost anything you need regarding Node-RED, including links to online communities and forums which can be found at the bottom of the home page.&lt;/p&gt;

&lt;p&gt;Finally, I highly recommend you subscribe to the &lt;a href="https://www.youtube.com/channel/UCQaB8NXBEPod7Ab8PPCLLAA"&gt;Node-RED channel&lt;/a&gt; on YouTube, managed by the creators of Node-RED. It includes a number of tutorials as well as live webinars and streams.&lt;/p&gt;

&lt;p&gt;That's it for now. Thanks so much for reading/watching and stayed tuned for much more to come.&lt;br&gt;
Cheers :)&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Manage Multiple Threads in Node JS</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Wed, 31 Mar 2021 17:16:44 +0000</pubDate>
      <link>https://dev.to/bleedingcode/managing-multiple-threads-in-node-js-3mpc</link>
      <guid>https://dev.to/bleedingcode/managing-multiple-threads-in-node-js-3mpc</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftzclyvv31mzy9r1p8v8x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftzclyvv31mzy9r1p8v8x.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this post I'm going to show you how to potentially triple your &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node&lt;/a&gt; application's performance by managing multiple threads. This is an important tutorial, where the methods and examples shown, will give you what you need to set up production-ready thread management.&lt;/p&gt;

&lt;h1&gt;
  
  
  Watch The Video on YouTube
&lt;/h1&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/W0go0ve1XE0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Child Processes, Clustering and Worker Threads
&lt;/h1&gt;

&lt;p&gt;For the longest time, Node's had the ability to be multi-threaded, by using either &lt;a href="https://nodejs.org/dist/latest-v14.x/docs/api/child_process.html" rel="noopener noreferrer"&gt;Child Processes&lt;/a&gt;, &lt;a href="https://nodejs.org/dist/latest-v14.x/docs/api/cluster.html" rel="noopener noreferrer"&gt;Clustering&lt;/a&gt;, or the more recent preferred method of a module called &lt;a href="https://nodejs.org/dist/latest-v14.x/docs/api/worker_threads.html" rel="noopener noreferrer"&gt;Worker Threads&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Child processes were the initial means of creating multiple threads for your application and have been available since version 0.10. This was achieved by spawning a node process for every additional thread you wanted created.&lt;/p&gt;

&lt;p&gt;Clustering, which has been a stable release since around version 4, allows us to simplify the creation and management of Child Processes. It works brilliantly when combined with &lt;a href="https://pm2.keymetrics.io/" rel="noopener noreferrer"&gt;PM2&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now before we get into multithreading our app, there are a few points that you need to fully understand:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Multithreading already exists for I/O tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is a layer of Node that's already multithreaded and that is the &lt;a href="https://libuv.org/" rel="noopener noreferrer"&gt;libuv&lt;/a&gt; thread-pool. I/O tasks such as files and folder management, TCP/UDP transactions, compression and encryption are handed off to libuv, and if not asynchronous by nature, get handled in the libuv's thread-pool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Child Processes/Worker Threads only work for synchronous JavaScript logic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Implementing multithreading using Child Processes or Worker Threads will only be effective for your synchronous JavaScript code that's performing heavy duty operations, such as looping, calculations, etc. If you try to offload I/O tasks to Worker Threads as an example, you will not see a performance improvement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Creating one thread is easy. Managing multiple threads dynamically is hard&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Creating one additional thread in your app is easy enough, as there are tons of tutorials on how to do so. However, creating threads equivalent to the number of logical cores your machine or VM is running, and managing the distribution of work to these threads is way more advanced, and to code this logic is above most of our pay grades 😎.&lt;/p&gt;

&lt;p&gt;Thank goodness we are in a world of open source and brilliant contributions from the Node community. Meaning, there is already a module that will give us full capability of dynamically creating and managing threads based on the CPU availability of our machine or VM.&lt;/p&gt;

&lt;h1&gt;
  
  
  Worker Pool
&lt;/h1&gt;

&lt;p&gt;The module we will work with today is called &lt;a href="https://github.com/josdejong/workerpool" rel="noopener noreferrer"&gt;Worker Pool&lt;/a&gt;. Created by &lt;a href="http://josdejong.com/" rel="noopener noreferrer"&gt;Jos de Jong&lt;/a&gt;, Worker Pool offers an easy way to create a pool of workers for both dynamically offloading computations as well as managing a pool of dedicated workers. It's basically a thread-pool manager for Node JS, supporting Worker Threads, Child Processes and Web Workers for browser-based implementations.&lt;/p&gt;

&lt;p&gt;To make use of the Worker Pool module in our application, the following tasks will need to be performed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Install Worker Pool&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First we need to install the Worker Pool module - npm install workerpool&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Init Worker Pool&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, we'll need to initialize the Worker Pool on launch of our App&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Create Middleware Layer&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We'll then need to create a middleware layer between our heavy duty JavaScript logic and the Worker Pool that will manage it&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Update Existing Logic&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, we need to update our App to hand off heavy duty tasks to the Worker Pool when required&lt;/p&gt;

&lt;h1&gt;
  
  
  Managing Multiple Threads Using Worker Pool
&lt;/h1&gt;

&lt;p&gt;At this point, you have 2 options: Use your own NodeJS app (and install &lt;a href="https://www.npmjs.com/package/workerpool" rel="noopener noreferrer"&gt;workerpool&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/bcryptjs" rel="noopener noreferrer"&gt;bcryptjs&lt;/a&gt; modules), or download the &lt;a href="https://github.com/bleedingcode/nodejs-performance-optimizations" rel="noopener noreferrer"&gt;source code&lt;/a&gt; from GitHub for this tutorial and my &lt;a href="https://www.youtube.com/watch?v=ol56smloW2Q&amp;amp;list=PLISqeoHsXJYAIfu4-mgNY0tloWz2uut1t" rel="noopener noreferrer"&gt;NodeJS Performance Optimization&lt;/a&gt; video series.&lt;/p&gt;

&lt;p&gt;If going for the latter, the files for this tutorial will exist inside the folder &lt;strong&gt;06-multithreading&lt;/strong&gt;. Once downloaded, enter into the root project folder and run npm install. After that, enter into the &lt;strong&gt;06-multithreading&lt;/strong&gt; folder to follow along.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcpauhovc7fhxr6gtl9u7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcpauhovc7fhxr6gtl9u7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;worker-pool&lt;/strong&gt; folder, we have 2 files: one is the controller logic for the Worker Pool (controller.js). The other holds the functions that will be triggered by the threads…aka the middleware layer I mentioned earlier (thread-functions.js).&lt;/p&gt;

&lt;h2&gt;
  
  
  worker-pool/controller.js
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict'

const WorkerPool = require('workerpool')
const Path = require('path')

let poolProxy = null

// FUNCTIONS
const init = async (options) =&amp;gt; {
  const pool = WorkerPool.pool(Path.join(__dirname, './thread-functions.js'), options)
  poolProxy = await pool.proxy()
  console.log(`Worker Threads Enabled - Min Workers: ${pool.minWorkers} - Max Workers: ${pool.maxWorkers} - Worker Type: ${pool.workerType}`)
}

const get = () =&amp;gt; {
  return poolProxy
}

// EXPORTS
exports.init = init
exports.get = get
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The controller.js is where we require the &lt;strong&gt;workerpool&lt;/strong&gt; module. We also have 2 functions that we export, called &lt;strong&gt;init&lt;/strong&gt; and &lt;strong&gt;get&lt;/strong&gt;. The &lt;strong&gt;init&lt;/strong&gt; function will be executed once during the load of our application. It instantiates the Worker Pool with options we'll provide and a reference to the &lt;strong&gt;thread-functions.js&lt;/strong&gt;. It also creates a proxy that will be held in memory for as long as our application is running. The &lt;strong&gt;get&lt;/strong&gt; function simply returns the in memory proxy.&lt;/p&gt;

&lt;h2&gt;
  
  
  worker-pool/thread-functions.js
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict'

const WorkerPool = require('workerpool')
const Utilities = require('../2-utilities')

// MIDDLEWARE FUNCTIONS
const bcryptHash = (password) =&amp;gt; {
  return Utilities.bcryptHash(password)
}

// CREATE WORKERS
WorkerPool.worker({
  bcryptHash
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;strong&gt;thread-functions.js&lt;/strong&gt; file, we create worker functions that will be managed by the Worker Pool. For our example, we're going to be using &lt;strong&gt;BcryptJS&lt;/strong&gt; to hash passwords. This usually takes around 10 milliseconds to run, depending on the speed of one's machine, and makes for a good use case when it comes to heavy duty tasks. Inside the &lt;strong&gt;utilities.js&lt;/strong&gt; file is the function and logic that hashes the password. All we are doing in the thread-functions is executing this &lt;strong&gt;bcryptHash&lt;/strong&gt; via the workerpool function. This allows us to keep code centralized and avoid duplication or confusion of where certain operations exist.&lt;/p&gt;

&lt;h2&gt;
  
  
  2-utilities.js
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict'

const BCrypt = require('bcryptjs')

const bcryptHash = async (password) =&amp;gt; {
  return await BCrypt.hash(password, 8)
}

exports.bcryptHash = bcryptHash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  .env
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NODE_ENV="production"
PORT=6000
WORKER_POOL_ENABLED="1"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The .env file holds the port number and sets the &lt;strong&gt;NODE_ENV&lt;/strong&gt; variable to "production". It's also where we specify if we want to enable or disable the Worker Pool, by setting the &lt;strong&gt;WORKER_POOL_ENABLED&lt;/strong&gt; to "1" or "0".&lt;/p&gt;

&lt;h2&gt;
  
  
  1-app.js
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict'

require('dotenv').config()

const Express = require('express')
const App = Express()
const HTTP = require('http')
const Utilities = require('./2-utilities')
const WorkerCon = require('./worker-pool/controller')

// Router Setup
App.get('/bcrypt', async (req, res) =&amp;gt; {
  const password = 'This is a long password'
  let result = null
  let workerPool = null

  if (process.env.WORKER_POOL_ENABLED === '1') {
    workerPool = WorkerCon.get()
    result = await workerPool.bcryptHash(password)
  } else {
    result = await Utilities.bcryptHash(password)
  }

  res.send(result)
})

// Server Setup
const port = process.env.PORT
const server = HTTP.createServer(App)

;(async () =&amp;gt; {
  // Init Worker Pool
  if (process.env.WORKER_POOL_ENABLED === '1') {
    const options = { minWorkers: 'max' }
    await WorkerCon.init(options)
  }

  // Start Server
  server.listen(port, () =&amp;gt; {
    console.log('NodeJS Performance Optimizations listening on: ', port)
  })
})()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, our &lt;strong&gt;1-app.js&lt;/strong&gt; holds the code that will be executed on launch of our App. First we initialize the variables in the &lt;strong&gt;.env&lt;/strong&gt; file. We then setup an &lt;a href="https://www.npmjs.com/package/express" rel="noopener noreferrer"&gt;Express&lt;/a&gt; server and create a route called &lt;strong&gt;/bcrypt&lt;/strong&gt;. When this route is triggered, we will check to see if the Worker Pool is enabled. If yes, we get a handle on the Worker Pool proxy and execute the &lt;strong&gt;bcryptHash&lt;/strong&gt; function that we declared in the &lt;strong&gt;thread-functions.js&lt;/strong&gt; file. This will in turn execute the &lt;strong&gt;bcryptHash&lt;/strong&gt; function in &lt;strong&gt;Utilities&lt;/strong&gt; and return us the result. If the Worker Pool is disabled, we simply execute the &lt;strong&gt;bcryptHash&lt;/strong&gt; function directly in &lt;strong&gt;Utilities&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At the bottom of our &lt;strong&gt;1-app.js&lt;/strong&gt;, you'll see we have a self calling function. We're doing this to support async/await, which we are using when interacting with the Worker Pool. Here is where we initialize the Worker Pool if it's enabled. The only config we want to override is setting the &lt;strong&gt;minWorkers&lt;/strong&gt; to "max". This will ensure that the Worker Pool will spawn as many threads as there are logical cores on our machine, with the exception of 1 logical core, which is used for our main thread. In my case, I have 6 physical cores with hyperthreading, meaning I have 12 logical cores. So with &lt;strong&gt;minWorkers&lt;/strong&gt; set to "max", the Worker Pool will create and manage 11 threads. Finally, the last piece of code is where we start our server and listen on port 6000.&lt;/p&gt;

&lt;h1&gt;
  
  
  Testing the Worker Pool
&lt;/h1&gt;

&lt;p&gt;Testing the Worker Pool is as simple as starting the application and while it's running, preforming a get request to &lt;code&gt;http://localhost:6000/bcrypt&lt;/code&gt;. If you have a load testing tool like &lt;a href="https://www.npmjs.com/package/autocannon" rel="noopener noreferrer"&gt;AutoCannon&lt;/a&gt;, you can have some fun seeing the difference in performance when the Worker Pool is enabled/disabled. AutoCannon is very easy to use.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I hope this tutorial has provided insight into managing multiple threads in your Node application. The embedded video at the top of this article provides a live demo of testing the Node App.&lt;/p&gt;

&lt;p&gt;Till next time, cheers :)&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Increase Node JS Performance With Libuv Thread Pool</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Mon, 07 Sep 2020 15:50:35 +0000</pubDate>
      <link>https://dev.to/bleedingcode/increase-node-js-performance-with-libuv-thread-pool-5h10</link>
      <guid>https://dev.to/bleedingcode/increase-node-js-performance-with-libuv-thread-pool-5h10</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp0cxb2m09f8cs0x2qm4m.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp0cxb2m09f8cs0x2qm4m.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this 5th instalment of my “&lt;a href="https://www.youtube.com/watch?v=ol56smloW2Q&amp;amp;list=PLISqeoHsXJYAIfu4-mgNY0tloWz2uut1t" rel="noopener noreferrer"&gt;Node JS Performance Optimizations&lt;/a&gt;” series, I show you how to increase &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node JS&lt;/a&gt; performance with thread pool management. We achieve this by understanding how &lt;a href="https://libuv.org/" rel="noopener noreferrer"&gt;Libuv&lt;/a&gt; works, how the thread pool works and how to configure the number of threads based on your machine specs.&lt;/p&gt;

&lt;p&gt;Are you a Node developer who’s not yet familiar with the inner workings of Node JS? If so, you might be deploying production applications with some default configurations that existed since installing Node. In this article, I’m going to touch on a lesser-known configuration that could very well double the performance of some of your application’s operations. This will depend on a number of factors, but chances are good this is going to be a win for many.&lt;/p&gt;

&lt;h1&gt;
  
  
  Watch The Video On YouTube
&lt;/h1&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/LC5FC3FdzAE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  The Node JS Runtime Environment
&lt;/h1&gt;

&lt;p&gt;The Node runtime environment is made up of a few moving parts. We should all be familiar with the &lt;a href="https://v8.dev/" rel="noopener noreferrer"&gt;Google V8 engine&lt;/a&gt;, which is responsible for executing our &lt;a href="https://javascript.info/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt; logic. There is, however, a lesser known library called &lt;a href="https://libuv.org/" rel="noopener noreferrer"&gt;Libuv&lt;/a&gt;, which is responsible for managing asynchronous I/O operations.&lt;/p&gt;

&lt;p&gt;These I/O operations are also well known as “heavy duty tasks” that related to the Operating System. Tasks such as files and folder management, TCP/UDP transactions, compression, encryption, etc. are handled via Libuv.&lt;/p&gt;

&lt;p&gt;Now, while most of these operations are asynchronous by design, there are a few that are synchronous, and if not handled correctly, could cause our applications to be blocked. It is for this reason that Libuv has what is called a “Thread Pool”.&lt;/p&gt;

&lt;h1&gt;
  
  
  Libuv Thread Pool
&lt;/h1&gt;

&lt;p&gt;Libuv initiates a thread pool of 4 threads that it uses to offload synchronous operations to. In doing this, Libuv ensures that our application does not get blocked unnecessarily by synchronous tasks.&lt;/p&gt;

&lt;p&gt;It is here that we will take advantage of a setting to better suit the specs of our machine or the virtual machine that our app will be deployed to. This is because we are allowed to change the default value of 4 threads to anything up to 1024 threads. We achieve this by setting the &lt;a href="https://nodejs.org/api/cli.html#cli_uv_threadpool_size_size" rel="noopener noreferrer"&gt;&lt;strong&gt;UV_THREADPOOL_SIZE&lt;/strong&gt;&lt;/a&gt; Node variable.&lt;/p&gt;

&lt;h1&gt;
  
  
  Physical vs Logical CPU Cores
&lt;/h1&gt;

&lt;p&gt;To better understand what to set the UV_THREADPOOL_SIZE to, we need to first understand how many logical cores our machine is running. If we take my MacBook Pro as an example, it’s running 6 Physical CPU cores (Intel).&lt;/p&gt;

&lt;p&gt;However, these cores have hyperthreading, which means that each core can run 2 operations simultaneously. We therefore regard 1 physical core with hyperthreading as 2 logical cores. In my case, my MacBook Pro is running 12 logical cores.&lt;/p&gt;

&lt;h1&gt;
  
  
  How To Increase Node JS Performance
&lt;/h1&gt;

&lt;p&gt;The recommendation is to set the &lt;strong&gt;UV_THREADPOOL_SIZE&lt;/strong&gt; to the number of logical cores your machine is running. In my case I will set the thread pool size to 12.&lt;/p&gt;

&lt;p&gt;It makes no sense setting the size to anything more than the logical cores your hardware is running and could actually result in poorer performance.&lt;/p&gt;

&lt;h1&gt;
  
  
  How To Check For Logical Cores
&lt;/h1&gt;

&lt;p&gt;When it comes to deployment, the last thing you want to do is manually set the &lt;strong&gt;UV_THREADPOOL_SIZE&lt;/strong&gt;, as your app might run on multiple environments with different machine specifications. As such, we need a way to dynamically set the thread pool size the moment the app is launched on the relevant environment.&lt;/p&gt;

&lt;p&gt;The good news is that this is quite simple, but must be dealt with caution. To achieve this, add the below code to the top of your root JS file of your Node application:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const OS = require('os')
process.env.UV_THREADPOOL_SIZE = OS.cpus().length


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;a href="https://nodejs.org/api/os.html" rel="noopener noreferrer"&gt;&lt;strong&gt;OS&lt;/strong&gt;&lt;/a&gt; module is native to Node JS. It has a function &lt;a href="https://nodejs.org/api/os.html#os_os_cpus" rel="noopener noreferrer"&gt;&lt;strong&gt;cpus()&lt;/strong&gt;&lt;/a&gt;, which returns the total amount of logical cores your machine is running. What’s nice is, should your CPU cores not have hyperthreading, this function will just return the number of physical cpu cores instead, which is perfect.&lt;/p&gt;

&lt;h1&gt;
  
  
  Closing
&lt;/h1&gt;

&lt;p&gt;I trust this article proved valuable. I recommend watching the embedded video as well as checking out my &lt;a href="https://github.com/bleedingcode/nodejs-performance-optimizations" rel="noopener noreferrer"&gt;Source Code repo&lt;/a&gt; on GitHub which has code samples of everything mentioned here.&lt;/p&gt;

&lt;p&gt;Till next time, cheers 😎&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>How To Test The Availability Of Your API Server</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Mon, 31 Aug 2020 19:18:13 +0000</pubDate>
      <link>https://dev.to/bleedingcode/how-to-test-the-availability-of-your-api-server-1mb8</link>
      <guid>https://dev.to/bleedingcode/how-to-test-the-availability-of-your-api-server-1mb8</guid>
      <description>&lt;p&gt;Have you developed or are you in the process of creating an API Server that will be used on a production or cloud environment? In this 4th instalment of my &lt;a href="https://www.youtube.com/playlist?list=PLISqeoHsXJYAIfu4-mgNY0tloWz2uut1t"&gt;Node JS Performance Optimizations&lt;/a&gt; series, I show you how to test the availability of your API Server, so that you can understand how many requests per second it can handle whilst performing heavy duty tasks.&lt;/p&gt;

&lt;p&gt;This is a very important measure, especially for production environments, because the last thing you want is to have incoming requests queued as a result of your API Server peaking and not freeing up resources often enough.&lt;/p&gt;

&lt;h1&gt;
  
  
  A Quick Note
&lt;/h1&gt;

&lt;p&gt;While I’ll be referencing &lt;a href="https://nodejs.org"&gt;NodeJS&lt;/a&gt; in this article, most of the theory and principles mentioned can apply to any platform and environment.&lt;/p&gt;

&lt;h1&gt;
  
  
  Watch The Video On YouTube
&lt;/h1&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/JwFDEJj3CKM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Which Benchmark Testing Tool To Use
&lt;/h1&gt;

&lt;p&gt;The tool I’ll be using for my tests is called &lt;a href="https://github.com/mcollina/autocannon"&gt;AutoCannon&lt;/a&gt;. It’s written entirely in &lt;a href="https://nodejs.org"&gt;NodeJS&lt;/a&gt; and is very similar to &lt;a href="https://httpd.apache.org/docs/2.4/programs/ab.html"&gt;Apache Benchmark&lt;/a&gt;, &lt;a href="https://artillery.io/"&gt;Artillery&lt;/a&gt;, &lt;a href="https://k6.io/"&gt;K6&lt;/a&gt;, &lt;a href="https://github.com/wg/wrk"&gt;Wrk&lt;/a&gt;, etc. This is good news because you are not forced to use AutoCannon to follow along with this article. If your benchmark testing tool can perform load tests against HTTP requests and can determine the average requests per second, you’re good to go.&lt;/p&gt;

&lt;p&gt;That being said, should you wish to make use of AutoCannon, it’s as easy as installing it globally as an NPM Module:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i -g autocannon&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4TV60gf0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/z6ar0fg2m6283aelgnxv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4TV60gf0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/z6ar0fg2m6283aelgnxv.png" alt="Alt Text" width="800" height="758"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How To Test The Availability Of Your API Server
&lt;/h1&gt;

&lt;p&gt;Firstly, there is an online &lt;a href="https://github.com/bleedingcode/nodejs-performance-optimizations"&gt;Source Code Repo&lt;/a&gt; that you can reference should you wish to run these examples on your local environment. All you will need is NodeJS installed.&lt;/p&gt;

&lt;p&gt;The snippet of code below gets you pretty much 99% to where you want to be, with the exception of setting up your package.json, setting the NODE_ENV to Production and PORT to 6000 (reference sample code in provided Source Code Repo and embedded video should you struggle). Add the following to an &lt;strong&gt;app.js&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict'

require('dotenv').config()

const Express = require('express')
const App = Express()
const HTTP = require('http')
const BCrypt = require('bcryptjs')

// Router Setup
App.get('/pulse', (req, res) =&amp;gt; {
  res.send('')
})

App.get('/stress', async (req, res) =&amp;gt; {
  const hash = await BCrypt.hash('this is a long password', 8)
  res.send(hash)
})

// Server Setup
const port = process.env.PORT
const server = HTTP.createServer(App)

server.listen(port, () =&amp;gt; {
  console.log('NodeJS Performance Optimizations listening on: ', port)
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a very simple Express Server that exposes 2 Routes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/pulse&lt;/li&gt;
&lt;li&gt;/stress&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;/pulse&lt;/strong&gt; endpoint represents a very lightweight API that contains no business logic and returns an empty string as a response. There should be no reason for any delays when processing this endpoint.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;/stress&lt;/strong&gt; endpoint, on the other hand, uses BcryptJS to salt and hash a password. This is quite a heavy process and because it’s completely written in JavaScript, it will land up blocking the Event Loop quite badly.&lt;/p&gt;

&lt;p&gt;For our first test, we’re going to use AutoCannon to run a load test against the &lt;strong&gt;/pulse&lt;/strong&gt; endpoint, to see how many requests per second the API Server can handle when it’s running idle. The process is as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start up the Express Server

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;node app&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Run the AutoCannon test

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;autocannon http://127.0.0.1:6000/pulse&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;This is a simple load test that runs 10 concurrent connections for 10 seconds&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After the test run, you should receive a report that includes an average requests per second. Depending on the speed of your machine, it should vary between 15 000 and 25 000 requests:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6dCsJW8g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/2imn5mln7jir9fnisn2i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6dCsJW8g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/2imn5mln7jir9fnisn2i.png" alt="Alt Text" width="627" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our baseline measurement, let’s see what happens when the API Server is performing heavy duty tasks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make sure the Express server is running

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;node app&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Open 2 Terminal windows for the tests to be performed&lt;/li&gt;
&lt;li&gt;In window 1, run AutoCannon against the &lt;strong&gt;/stress&lt;/strong&gt; endpoint for a duration of &lt;strong&gt;30&lt;/strong&gt; seconds

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;autocannon -d 30 http://127.0.0.1:6000/stress&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;In window 2, while the &lt;strong&gt;/stress&lt;/strong&gt; test is running, run AutoCannon against the &lt;strong&gt;/pulse&lt;/strong&gt; endpoint, same as before

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;autocannon http://127.0.0.1:6000/pulse&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Make sure the &lt;strong&gt;/pulse&lt;/strong&gt; test runs to completion whilst the &lt;strong&gt;/stress&lt;/strong&gt; test is running&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After this test run, you should see a significant drop in the requests per second for the &lt;strong&gt;/pulse&lt;/strong&gt; test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0GSJf-wh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/s6eo3gz0hf9hsj1i70n3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0GSJf-wh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/s6eo3gz0hf9hsj1i70n3.png" alt="Alt Text" width="599" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can imagine, this is a frightening result…one that needs to be handled sooner rather than later.&lt;/p&gt;

&lt;h1&gt;
  
  
  What Does This Mean In The Real World
&lt;/h1&gt;

&lt;p&gt;While this example won’t make too much sense in the real world, it forms a template for the kind of tests you should be running on your environment. You need to identify when your API Server is running at peak, and then hit it with load testing against lightweight APIs that belong to your server. You need to determine if they can be processed without much delay, or if they get blocked because your code might not be managing the Event Loop well enough.&lt;/p&gt;

&lt;h1&gt;
  
  
  How do I fix the problem?
&lt;/h1&gt;

&lt;p&gt;Well, I have good news: As mentioned at the start, I am busy with a series on “&lt;a href="https://www.youtube.com/playlist?list=PLISqeoHsXJYAIfu4-mgNY0tloWz2uut1t"&gt;Node JS Performance Optimizations&lt;/a&gt;”. Having already used examples from content I’ve published and content to come, I managed to increase the requests per second for the &lt;strong&gt;/pulse&lt;/strong&gt; test from &lt;strong&gt;117&lt;/strong&gt; to over &lt;strong&gt;4 000&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What you want to do is &lt;a href="https://youtube.com/bleedingcode?sub_confirmation=1"&gt;subscribe&lt;/a&gt; to my &lt;a href="https://youtube.com/bleedingcode"&gt;Bleeding Code&lt;/a&gt; YouTube Channel, as I publish everything there first and almost on a weekly basis. There are already 4 videos for this series, an important one which is “&lt;a href="http://bleedingcode.com/managing-the-event-loop-phases"&gt;Managing The Event Loop Phases&lt;/a&gt;“.&lt;/p&gt;

&lt;p&gt;I hope this article proved valuable. Stay tuned for more to come 😎&lt;br&gt;
Cheers&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>performance</category>
    </item>
    <item>
      <title>MANAGING THE EVENT LOOP PHASES ⭕️ [Node JS Performance Optimizations]</title>
      <dc:creator>💻 Bleeding Code-By John Jardin</dc:creator>
      <pubDate>Mon, 10 Aug 2020 06:58:41 +0000</pubDate>
      <link>https://dev.to/bleedingcode/managing-the-event-loop-phases-node-js-performance-optimizations-2gb8</link>
      <guid>https://dev.to/bleedingcode/managing-the-event-loop-phases-node-js-performance-optimizations-2gb8</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ol56smloW2Q"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this first video of my &lt;a href="https://www.youtube.com/watch?v=ol56smloW2Q&amp;amp;list=PLISqeoHsXJYAIfu4-mgNY0tloWz2uut1t"&gt;Node JS Performance Optimizations&lt;/a&gt; series, I show you how to level up you &lt;a href="https://nodejs.org"&gt;Node JS&lt;/a&gt; skills by managing the Event Loop phases the right way. I provide simple, yet in depth explanations and examples of how the Event Loop works as well as how to best interact with it to write performant Node apps.&lt;/p&gt;

&lt;p&gt;The tutorial is divided into 4 main sections:&lt;/p&gt;

&lt;h1&gt;
  
  
  Quick Points about Node JS
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Video Location - 00:45&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before diving in to the detail of what makes the Event Loop tick (mind the pun 😎), I go over a few basic points that everyone needs to first understand about Node and the Event Loop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FXCVFOdT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/y6es1uhq9wh5y5r8t243.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FXCVFOdT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/y6es1uhq9wh5y5r8t243.png" alt="Alt Text" width="800" height="728"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Async Functions
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Video Location - 02:37&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this section I provide an overview of the the 5 asynchronous functions you can use to interact with the Event Loop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kqmxkgVs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bbdp6w0s9aqpaf7nu6ri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kqmxkgVs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bbdp6w0s9aqpaf7nu6ri.png" alt="Alt Text" width="800" height="728"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Phases of the Event Loop
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Video Location - 03:55&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using a simple diagram of the Event Loop, I explain the 5 main phases that make up a Cycle (Tick) and what each phase is used for.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JfCLb_1O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/sk17zns77b4sivkdo1dc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JfCLb_1O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/sk17zns77b4sivkdo1dc.png" alt="Alt Text" width="631" height="728"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The Event Loop in Action
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Video Location - 09:15&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I demo in realtime how to interact with the Event Loop using the 5 mentioned asynchronous functions.&lt;/p&gt;

&lt;h1&gt;
  
  
  Performance Tips
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Video Location - 17:43&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, I provide a few quick tips on how to write good, performant Node JS applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rmFhwCo4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/a703ite6lr46erix8u4u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rmFhwCo4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/a703ite6lr46erix8u4u.png" alt="Alt Text" width="800" height="728"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Till next time. Cheers 🙂&lt;/p&gt;

</description>
      <category>node</category>
      <category>tutorial</category>
      <category>javascript</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
