<?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: Leslie Sarfo Gyamfi</title>
    <description>The latest articles on DEV Community by Leslie Sarfo Gyamfi (@kwamedev).</description>
    <link>https://dev.to/kwamedev</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%2F781499%2F0c9ce6eb-8bd1-44e8-be1a-622b7bb32393.jpeg</url>
      <title>DEV Community: Leslie Sarfo Gyamfi</title>
      <link>https://dev.to/kwamedev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kwamedev"/>
    <language>en</language>
    <item>
      <title>Unboxing Pieces App for Developers: Your Workflow Copilot 🚀🔥</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Thu, 20 Jun 2024 13:23:50 +0000</pubDate>
      <link>https://dev.to/kwamedev/unboxing-pieces-app-for-developers-your-workflow-copilot-1i6p</link>
      <guid>https://dev.to/kwamedev/unboxing-pieces-app-for-developers-your-workflow-copilot-1i6p</guid>
      <description>&lt;p&gt;As a backend software engineer, developer advocate, and technical writer who has worked with brands that span the fields of insurance, data management, software testing, and healthcare (cancer research) like DbVisualizer, the highly rated database client and SQL editor in the world, LambdaTest Inc., Insurerity  Digital, and Yemaachi Biotech Company, there’s no better person to describe how a day in the life of an engineer feels like.&lt;/p&gt;

&lt;p&gt;In my typical day as an engineer and dev advocate, I’m mostly found writing JavaScript and SQL, and developing on macOS while using a handful of tools that are indispensable in my day-to-day work such as &lt;strong&gt;VSCode&lt;/strong&gt; IDE, &lt;strong&gt;Google Chrome browser&lt;/strong&gt;, &lt;strong&gt;GitHub Desktop&lt;/strong&gt;, &lt;strong&gt;Slack Desktop&lt;/strong&gt;, &lt;strong&gt;Notion&lt;/strong&gt;, &lt;strong&gt;Notion Calendar&lt;/strong&gt;, &lt;strong&gt;Postman&lt;/strong&gt;, &lt;strong&gt;Anaconda&lt;/strong&gt;, &lt;strong&gt;Android Studio&lt;/strong&gt;, etc. &lt;/p&gt;

&lt;p&gt;Before being introduced to the Pieces app for developers I was a heavy user of Google Drive. I would often use Google Drive to save my code snippets, events, and other workstream materials. Other times when I'm working on a project and I have to save some code snippets, infrastructure platform login credentials, keys, links, and other stuff (db urls, errors) somewhere, I’d use the notes app on macOS or notion. One other important part of my work that I had to always save somewhere so I don’t lose track of is tickets that have been assigned to me or reports from a QA engineer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fe19abtc39882b3uflmi6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fe19abtc39882b3uflmi6.jpg" alt="Saved nuggets in my notes app" width="800" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method of saving tiny pieces of important information lacked cohesion and remembering the exact location of data was sometimes a pain in the arse until I chanced on &lt;a href="https://pieces.app/" rel="noopener noreferrer"&gt;Pieces for Developers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When I first heard about the Pieces for Developers, I was intrigued by its promise to streamline and enhance productivity for coding and project management. As a developer, I am always on the lookout for tools that can help optimize my workflow, and Pieces seemed to offer a unique blend of features designed specifically for our needs.&lt;/p&gt;

&lt;p&gt;My initial interest in &lt;a href="https://pieces.app/" rel="noopener noreferrer"&gt;Pieces&lt;/a&gt; stemmed from its focus on helping developers organize and manage code snippets, notes, and other resources intuitively. The idea of having a central repository where I could quickly store and retrieve useful code snippets, docs, and other related information to my projects was appealing. This feature promised to save me from the chaos of scattered notes and endless searching through old projects to find reusable code.&lt;br&gt;
Upon setting up Pieces, I was eager to achieve several productivity benefits including but not limited to collaboration and improved organization. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collaboration Purposes&lt;/strong&gt;&lt;br&gt;
As I often work in a team environment, I was looking for ways to improve collaboration. Pieces’ ability to share resources and insights with team members promised to foster better communication and collective knowledge sharing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Reusability&lt;/strong&gt;&lt;br&gt;
I wanted to efficiently store and categorize my frequently used code snippets, making reusing them across different use cases or projects easier. This would reduce redundant coding efforts and improve the consistency and quality of my work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Improved Organization&lt;/strong&gt;&lt;br&gt;
Through the consolidation of my notes, documentation, and code snippets in one place, I aimed to create a more organized and accessible knowledge base. This organization would allow me to quickly find the information I needed without sifting through disorganized files or online searches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Seamless Platform Integrations&lt;/strong&gt; &lt;br&gt;
Pieces’ potential to integrate with other development tools and platforms I use, such as VSCode, Slack, GitHub, MS Teams, Google Chrome browser, etc, was a significant draw. I hoped this integration would facilitate a smoother workflow and reduce the time spent switching between different applications or tools.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Review a Product like Pieces for Developers?
&lt;/h2&gt;

&lt;p&gt;With my experience working across spanning industries that include insurance, data management, software testing, and healthcare, I understand the challenges developers face daily. This has given me knowledge of the tools and practices that can significantly enhance a developer's productivity and workflow.&lt;/p&gt;

&lt;p&gt;Given this background, I saw a formal review of Pieces as an excellent opportunity to provide invaluable insights to my followers and readers. The name is Pieces for ‘Developers’ - This tells us that the ulterior goal of Pieces is to make the lives of developers easier.&lt;/p&gt;

&lt;p&gt;Below are the reasons I believe it would be beneficial to review Pieces and share my findings with my audience:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collaboration Purposes&lt;/strong&gt;&lt;br&gt;
Many of my readers work in team environments where collaboration and knowledge sharing are indispensable, therefore Pieces’ ability to facilitate resource sharing and improve team communication can be a game-changer. Through this review, I can highlight its collaborative features and demonstrate how it can boost team productivity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Addressing Common Dev Challenges&lt;/strong&gt;&lt;br&gt;
Developers often face challenges like managing code snippets, organizing documentation, and maintaining efficient workflows. Pieces promises to address these issues by providing a centralized repo for code snippets, notes, and other resources. &lt;/p&gt;

&lt;p&gt;My audience, comprising developers who likely encounter similar challenges, could greatly benefit from understanding how Pieces can help ease their way out.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting Up the Pieces App
&lt;/h2&gt;

&lt;p&gt;Navigate to the &lt;a href="https://docs.pieces.app/installation-getting-started/what-am-i-installing" rel="noopener noreferrer"&gt;pieces app documentation&lt;/a&gt;. Select your installer based on the operating system of your computer. Run the installer and you’re good to go. In the navigation menu of the documentation, you will find a list of Pieces App plugins and extensions for VSCode, JetBrains, web, MS Teams, Azure Data Studio, Obsidian, and Jupyter.&lt;/p&gt;

&lt;p&gt;After installing Pieces, the first step in the onboarding process is to set up a personalized pieces experience by specifying your&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Developer Persona and Languages&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Typical Toolchain&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Experience Level&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Project Types (individual, team, both)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F2nerme6jekfcuz0y4mjz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F2nerme6jekfcuz0y4mjz.png" alt="Setting up Pieces" width="800" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, Pieces will help you choose how to effortlessly search, refer, and be able to reuse all your saved materials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F7q3zmab691nsbqvbaz1e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7q3zmab691nsbqvbaz1e.png" alt="Setting Up - 2" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Frt5pip7walnz3yls0bfi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Frt5pip7walnz3yls0bfi.png" alt="Setting up - 3" width="800" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After setting up preferences, you can also do your cloud integrations so everything syncs. You can choose to use GitHub, Google, etc.&lt;/p&gt;
&lt;h2&gt;
  
  
  Pieces for Developers: the Good &amp;amp; the Bad
&lt;/h2&gt;

&lt;p&gt;In this first-impression blog, we’ll get into the good, and the bad and what it means for a Developer Advocate like myself and the productivity of my work-in-progress journeys. Time to get started!&lt;/p&gt;
&lt;h2&gt;
  
  
  The Bad  - The Ugly 🙂
&lt;/h2&gt;

&lt;p&gt;Below are a few scenarios and features where Pieces fell short:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance on Intel Architecture MacBooks&lt;/strong&gt;&lt;br&gt;
Intel MacBooks experience a noticeable lag when trying to exit the screen where Pieces is open. This high resource consumption results in performance barriers on older Intel architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limited Collaboration Features 🫥&lt;/strong&gt;&lt;br&gt;
The collaboration features are somewhat limited. When attempting to share snippets with a team, I found it difficult to manage permissions and there was no support for real-time collaboration on snippets although the features/ fuctions were visible.&lt;/p&gt;

&lt;p&gt;Additionally, providing detailed access controls (super admin, admin, etc) to manage who can &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;view, &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;comment, &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;edit, and &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;delete a snippet would enhance team collaboration on Pieces.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  The Good - The Awesome! 💪
&lt;/h2&gt;

&lt;p&gt;This section will highlight the outstanding features of Pieces:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Live Context 💡&lt;/strong&gt;&lt;br&gt;
The Live Context feature in Pieces provides context-aware and real-time insights into your code. Because of its ability to comprehend and adjust to your work process, Pieces Copilot can offer apt support based on your work style, where you work, and when, giving you the freedom to recall anything and communicate with everything.&lt;/p&gt;

&lt;p&gt;To enabling Live Context in Pieces, do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the Machine Learning section of the &lt;a href="https://docs.pieces.app/installation-getting-started/what-am-i-installing" rel="noopener noreferrer"&gt;Pieces Desktop App settings&lt;/a&gt; and activate the Workstream Pattern Engine.&lt;/li&gt;
&lt;li&gt;Follow the prompts to adjust the necessary permissions if required.&lt;/li&gt;
&lt;li&gt;Navigate to the Copilot Chats, begin your work, then initiate a conversation with the Pieces Copilot, utilizing Live Context for enhanced assistance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How Live Context Works&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Resolution of Errors&lt;/strong&gt;&lt;br&gt;
You can expedite project hand-offs and resolution of errors with Live Context. The copilot can provide accurate recommendations without requiring you to explicitly input the context of your error by gathering relevant workflow data. &lt;/p&gt;

&lt;p&gt;Let’s look at this warning I’m encountering in my backend project in VsCode at the moment. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fxl3vcrc1rck5q8d8c997.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fxl3vcrc1rck5q8d8c997.png" alt="Illustration - 1" width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since Pieces has relevant data of my workflow, I can ask Pieces Copilot+ to help me resolve it - “How would you take care of the warning in my VSCode Terminal?”. It will then utilize its relevant context or workflow ability to resolve the error as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fpjh6d1ywwle9n83kzytg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fpjh6d1ywwle9n83kzytg.png" alt="Illustration. - 3" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, Pieces tells us how to get rid of the MongoDB Driver warning.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fnpjjwskphrfui1ls4j2o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fnpjjwskphrfui1ls4j2o.png" alt="Warning" width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Present Time Workflow Assistance&lt;/strong&gt;&lt;br&gt;
You can manage your tasks across several tools and sessions with the aid of Live Context. Whether you're hopping from browser-based research, google chats or coding in your text editor, Pieces Copilot+ keeps track of your actions and offers helpful, context-aware support quickly.&lt;/p&gt;

&lt;p&gt;For example, before I wrote about this ‘Live Context’ feature, I was doing some research around it. When I asked Pieces what I had been doing for the past hour, it provided me with the exact flow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fpeoz699e2r63heondykp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fpeoz699e2r63heondykp.png" alt="Hourly Work Update" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Improving Interaction with Developers&lt;/strong&gt;&lt;br&gt;
To assist you in more efficiently managing discussions and teamwork, Pieces Copilot+'s Workstream Pattern Engine collects and analyzes interaction data. Making summaries and action items based on your conversations and actions falls under this category.&lt;/p&gt;

&lt;p&gt;For example, I can ask it to generate points for our sync meeting tonight at Pieces.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fgab2mwpsoljbtq148lxa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgab2mwpsoljbtq148lxa.png" alt="sync meeting generation" width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Workstream Pattern Engine collects and analyzes data from various interactions throughout the day, including code reviews, comments, and direct communications within the team (slack, MS Teams, etc). It then uses the collected data to generate a concise response for the sync meeting.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The domain facilitates easy sharing and collaboration with team members or other developers. You can share specific snippets or resources by providing a link to your cloud domain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your personalized cloud domain in Pieces acts as a backup hub for your snippets, notes, and other resources. While it allows you to store and restore your materials, all snippets are saved on-device by default and only uploaded to the cloud when you manually perform a backup. Live sync functionality is not available, meaning that updates made on one device won't automatically sync to others.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your cloud domain acts as a backup for your data. In case of hardware failure or data loss on your local device, you can easily recover your snippets and resources from your cloud domain.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Etc&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sharing Saved Snippets or Materials&lt;/strong&gt;&lt;br&gt;
With Pieces, you can share your saved materials publicly by generating a shareable link and putting it out there by following the illustration shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Frklw0qjus234fdsh4dol.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Frklw0qjus234fdsh4dol.jpg" alt="Shareable Link" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After generating the shareable link, feel free to share this link with your team. They can save it to their pieces and edit it if need be!&lt;/p&gt;

&lt;p&gt;Another interesting thing is that you can also add project-related people to your saved material. &lt;/p&gt;

&lt;p&gt;Related people are more for Pieces to recommend people who have worked on similar things as you save snippets from various places. If a user shares a saved material to another user, they can save it to their personal saved materials on Pieces and edit it (if need be), but the original user will only have the version that they created and had shared originally. &lt;/p&gt;

&lt;p&gt;To add related people, do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on the menu icon shown in the image below&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fe85p10n2zxcqna6159bh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fe85p10n2zxcqna6159bh.jpg" alt="Related People" width="800" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fj9ju5u4cf717grav8e8s.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fj9ju5u4cf717grav8e8s.jpg" alt="Related People - 2" width="800" height="573"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the name and email of the related person and click on ‘Create’ to create.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Auto-enrichment 🧑‍💻&lt;/strong&gt;&lt;br&gt;
Immediately you save a snippet, Pieces App automatically enriches it with related &lt;strong&gt;links&lt;/strong&gt;, &lt;strong&gt;tags&lt;/strong&gt;, &lt;strong&gt;descriptions&lt;/strong&gt;, and other &lt;strong&gt;metadata&lt;/strong&gt;. This is driven by AI and machine learning algorithms that analyze your snippets and the context in which they are used. You can edit these descriptions, tags, related links, etc if you wish to. For example, embedding a different link (video, article) in your related links. &lt;/p&gt;

&lt;p&gt;Note that this feature is on-device - meaning that all the processing and enrichment of the code snippets happen locally on the user's device, rather than on external servers. &lt;/p&gt;

&lt;p&gt;Since all processing happens locally, sensitive code and data never leave the user's device. This ensures that proprietary or confidential information remains secure. Also, users do not need to worry about their code being stored or processed on third-party servers, reducing the risk of data breaches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What does the Auto-Enrichment Feature Come with?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Searchability&lt;/strong&gt;: With tags, descriptions, and related links automatically added, finding the right snippet becomes much easier. You can search using full-text search, blended, natural language, or snippets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Context&lt;/strong&gt;: Having related links and contextual information at your fingertips helps you understand and utilize snippets more effectively. It reduces the need to search for additional resources manually.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time-Saving&lt;/strong&gt;: Automatic enrichment saves time by eliminating the need to annotate and organize snippets manually. This allows you to focus more on coding.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Better Collaboration&lt;/strong&gt;: When sharing snippets with team members, the added metadata provides them with all the necessary context to understand and use the snippets effectively.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Generating GitHub Gist 🚀&lt;/strong&gt;&lt;br&gt;
This function allows developers to quickly and seamlessly share code snippets on GitHub. To create a GitHub Gist, follow the steps below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a snippet on the Pieces App. Click on the menu icon on the right-hand side of the window.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the pop-up window, click on the shareable link’s  ‘manage’  button shown in the image below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fa0in29ij82pygn2e61ce.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fa0in29ij82pygn2e61ce.jpg" alt="Manage" width="800" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, click on the ‘Generate Github Gist’ button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fiaqv2v9sladz3oek12sg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fiaqv2v9sladz3oek12sg.jpg" alt="GitHub Gist" width="800" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Edit the contextual metadata and the description (if you wish to) and click on ‘Create’ to create the gist. Note that you will have to connect your GitHub account before this action can be done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub Gist Use Case&lt;/strong&gt;&lt;br&gt;
Grace, a software developer, is working on a new feature for a web application. She encounters a complex bug in her JavaScript code that she is unable to resolve on her own. Grace decides to seek help from her colleague, Dillon, who has more experience with JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Process Flow&lt;/strong&gt;&lt;br&gt;
-&amp;gt; Grace identifies the specific code snippet that is causing the issue. She saves the problematic code snippet in the Pieces App. The app automatically enriches the snippet with relevant metadata, such as a description of the issue, tags, and any related links.&lt;/p&gt;

&lt;p&gt;-&amp;gt; Using the Pieces App, she uses the 'Generate GitHub Gist' function to create a GitHub Gist from the saved snippet. This function automates the process of creating a Gist by integrating with Grace's GitHub account. The app generates a link to the GitHub Gist, which Alice can easily share. Alice sends this link to Dillon.&lt;/p&gt;

&lt;p&gt;-&amp;gt; He receives the Gist link and opens it in his browser. He reviews the code and uses GitHub's commenting feature to provide feedback and suggest changes. Grace reviews the comments and updates. She then incorporates the suggested changes into her local codebase, resolving the bug.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Saving Snippets 🔥🔥&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Use Cases&lt;/strong&gt; &lt;br&gt;
The code below is a backend code I wrote for an open-source app. What I have here is a code that connects my application to MongoDB. I want this snippet to be saved so that next time I’m writing some backend, this code snippet will be available to me any moment.&lt;/p&gt;

&lt;p&gt;To do this, follow the steps below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open VSCode, and install the Pieces for VSCode extension.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Highlight the code, right-click, and select ‘Pieces’ from the menu.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fttyam1mpmmsa39t7x8ot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fttyam1mpmmsa39t7x8ot.png" alt="Saving Snippets" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;From the pop-up menu, select ‘Save to Pieces’ to save the snippet. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fa34aoq6hlvf5ocwnhs2h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fa34aoq6hlvf5ocwnhs2h.png" alt="Saving Snippets - 2" width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now, go ahead and open Pieces and you should see the snippet saved.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F9ej87nel3bzufsa66wop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9ej87nel3bzufsa66wop.png" alt="Saving Snippets - 3" width="800" height="511"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dragging and Dropping an Image&lt;/strong&gt;&lt;br&gt;
With Pieces, you can drag and drop an image, which will be automatically saved! One crazy thing is that you could also view the image as code rather than an image. Dragging and dropping an image into Pieces to turn it into actual text (code snippets) leverages optical character recognition (OCR) technology.&lt;/p&gt;

&lt;p&gt;This is a simple demo video to illustrate the drag-and-drop method in Pieces. In this video, you’re also going to learn how to view the image (screenshot of a code snippet) as code.&lt;/p&gt;

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

&lt;p&gt;Are you watching a tutorial and want to use a code in the tutorial? Take a screenshot, drag and drop the image into Pieces, and view it as code! Pieces is simply developer-first! &lt;/p&gt;

&lt;p&gt;There’s also &lt;strong&gt;Context Preview&lt;/strong&gt; - a feature in the Pieces App that provides users with relevant information about their saved code snippets and other developer materials at a glance. This feature is designed to enhance productivity by walking developers through the context of their snippets.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ff0lwf5jf9tu32ho2dzrg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ff0lwf5jf9tu32ho2dzrg.png" alt="Context Preview" width="800" height="629"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Saving using the Chrome extension&lt;/strong&gt;&lt;br&gt;
In this section of the blog, we’re going to experiment with this blog on &lt;a href="https://dev.to/kwamedev/unit-testing-with-mocha-chai-4gdh"&gt;Unit testing with mocha and chai&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5x8ie39oplcnicmt1dcy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5x8ie39oplcnicmt1dcy.jpg" alt="Using Chrome Extension" width="800" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s assume we are interested in this code. To copy it for our use, we just have to hover over the code and Pieces’ functions will pop up as shown in the image above. (provided the &lt;a href="https://chromewebstore.google.com/detail/pieces-for-developers-cop/igbgibhbfonhmjlechmeefimncpekepm" rel="noopener noreferrer"&gt;Chrome extension&lt;/a&gt; has been installed). Click on ‘Copy And Save’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ff1jv1qx4yp8e3459h3bi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ff1jv1qx4yp8e3459h3bi.png" alt="Chrome Extension" width="800" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great! Now we can see that our code snippet in our browser has been saved on Pieces! 💪&lt;/p&gt;

&lt;p&gt;If you want to share this code sample with your teammates, just click ‘Share’. This will save the code, and generate a link to the code sample which will then be automatically saved to your clipboard.&lt;/p&gt;

&lt;p&gt;There’s also the ‘Ask Copilot’ function. This function provides real-time assistance and insights about code samples directly within the browser. Particularly, it is useful for developers looking for quick explanations, suggestions, or solutions related to specific code snippets. &lt;/p&gt;

&lt;p&gt;A dialog box or sidebar will appear after clicking it, prompting you to enter your question about the selected code snippet. For example, you might ask for an explanation of the code, potential optimizations, or how to fix a bug.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fap5jxh3v68thhk44gk5p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fap5jxh3v68thhk44gk5p.jpg" alt="Ask Copilot" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Crazy right?! 😀. Remember this feature works the same for Pieces’ VS Code Extension. &lt;strong&gt;Highlight a code -&amp;gt; right click  -&amp;gt;  ask Copilot&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exploring Curated Collections from the Pieces Team&lt;/strong&gt;&lt;br&gt;
The team members at Pieces have come together to curate a collection full of some of the most useful code samples ranging from JS to TS to Node, Dart and Python (snippets for other languages and frameworks are coming soon). Add these snippets to your Pieces for some extreme time-savers.&lt;/p&gt;

&lt;p&gt;To explore these collections, click on ‘Add Materials’ and in the pop-up window, click on ‘Explore Curated Collections’. Bingo! 🚀&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Analysis 🧑‍💻&lt;/strong&gt;&lt;br&gt;
Copilot Chats in Pieces offers numerous advantages for developers preparing for technical assessment interviews such as Data Structures and Algorithms (DSA) interviews, etc. Let’s look at how to leverage Pieces in code analysis and in the preparation for such assessments.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Launch the Pieces app and click on the ‘Go To’ icon at the top right. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fmgicjiwbodnl0e5duiwp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fmgicjiwbodnl0e5duiwp.jpg" alt="Code Analysis" width="800" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the drop-down menu, select ‘Copilot Chats’&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the input field, you can choose to drag and drop a screenshot, paste a code or ask a technical question as shown below.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;br&gt;
Billy, a software developer, is preparing for a technical interview and practicing a Leetcode DSA problem on binary search trees (BST). Billy has chanced on a solution written in JavaScript on Leetcode.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;He takes a screenshot of the code snippet (solution), opens up Copilot Chats on Pieces and drops the image. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pieces then extracts the code from his image.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Billy then continues to ask technical questions: explanation, potential improvements, etc about the code in question as shown below. You could also ask Copilot to convert a code snippet to a different language. Say from JavaScript to Python, etc&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fe2egcpnagzn1srw1yog0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fe2egcpnagzn1srw1yog0.png" alt=" " width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fu3yoqltjx9mb9yc7gpyq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fu3yoqltjx9mb9yc7gpyq.png" alt=" " width="800" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Asking further questions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fhcnohshqxlag9j6rzahr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fhcnohshqxlag9j6rzahr.png" alt=" " width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is crazy, isn’t it?! 😀&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up! 🫡
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;OverAll Impression of Pieces&lt;/strong&gt;&lt;br&gt;
My overall impression of the Pieces App is up the roof! Well-designed with a clear focus on improving productivity and organization for developers, it has a wide range of features, such as snippet management, integration with popular platforms, and context-aware functionalities, making it a powerful addition to any developer's toolkit. What excites me most is the automatic generation of tags, descriptions, and related links adds significant value by simplifying the process of managing and retrieving code snippets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Potential for the Pieces as it Evolves&lt;/strong&gt;&lt;br&gt;
The potential for the Pieces App is substantial. As Pieces continues to progress , it will surely become an indispensable tool for developers by refining its existing features and extending its flair. Enhancing performance, especially on older hardware, and improving collaboration features can make it more appealing to larger development teams and enterprises. Additionally, incorporating more advanced AI-driven functionalities for code suggestion and error detection can further elevate its utility in the development space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continued Use in Engineering &amp;amp; Developer Advocacy Career&lt;/strong&gt;&lt;br&gt;
I see myself continuing to use the Pieces App throughout my engineering and developer advocacy career. Its ability to smoothen the management of code snippets and integrate with tools I already use makes it a valuable asset to me and my team. &lt;/p&gt;

&lt;p&gt;As developers, there’s always so much context to deal with. From handling large code bases to useful snippets (that we sometimes forget to save), to screenshots, etc, Pieces has made it its goal to bring all these together!&lt;br&gt;
The ongoing improvements and the team’s responsiveness to feedback also provide confidence that the product will only get better with time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Number One Feature/Benefit Wished For&lt;/strong&gt;&lt;br&gt;
The number one feature I wish Pieces App had is real-time collaboration capabilities. Being able to work on code snippets simultaneously with other team members, along with detailed access controls, would significantly enhance the app’s utility in a team setting. This feature would bridge the gap between individual productivity and collaborative coding which will make it a more comprehensive tool for development teams.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recommendation to Other Engineers&lt;/strong&gt;&lt;br&gt;
As an intuitive, powerful tool that seamlessly integrates with various development environments, Pieces is perfect for organizing and managing code snippets, and its user-friendly interface makes it easy to adopt. I would characterize Pieces as a game-changer for code management and productivity. Whether you're working alone or in a team, Pieces is an invaluable tool that can greatly enhance your development experience. I would highly recommend Pieces to any other engineer.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>githubcopilot</category>
      <category>developers</category>
      <category>workflow</category>
    </item>
    <item>
      <title>Unit Testing with Mocha &amp; Chai 🚀</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Tue, 21 May 2024 13:37:13 +0000</pubDate>
      <link>https://dev.to/kwamedev/unit-testing-with-mocha-chai-4gdh</link>
      <guid>https://dev.to/kwamedev/unit-testing-with-mocha-chai-4gdh</guid>
      <description>&lt;p&gt;Unit testing, also known as module testing or component testing is a form of software testing and a software development practice where small units or pieces of code (a line of code, a method, or a class) are tested independently. The end goal of unit testing is to ensure that each unit functions as expected and that bugs are caught at the early stages of the development cycle.&lt;/p&gt;

&lt;p&gt;Regardless of the type of application you're creating, testing should always come before release. There are many different testing frameworks available, some of which include Mocha, Jasmine, and Cypress. But in this extensive guide, we’re going to take a look at unit testing with Mocha and Chai.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Mocha and Chai?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.mochajs.org" rel="noopener noreferrer"&gt;Mocha&lt;/a&gt; is a popular fun, simple, and flexible JavaScript test framework for Node.js environments. It offers a clean and readable syntax for defining test suites and cases, making writing and maintaining tests easy. It also has support for asynchronous testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.chaijs.com/" rel="noopener noreferrer"&gt;Chai&lt;/a&gt; is a flexible assertion library used together with Mocha that provides different assertion styles (expect, should, assert) and a rich set of methods for verifying expected outcomes within your tests. It can be used as a BDD/TDD assertion library for NodeJS and with any other JavaScript testing framework. How does Chai do this?&lt;/p&gt;

&lt;p&gt;To begin with, BDD and TDD (Behavior-Driven Development and Test-Driven Development) are software development methodologies that emphasize writing tests before or alongside writing the actual code. &lt;/p&gt;

&lt;p&gt;In TDD, you start by writing a failing test that defines the expected behavior of a code unit. Then, you write the code to make the test pass. This ensures your code is designed to fulfill specific requirements from the beginning.&lt;/p&gt;

&lt;p&gt;BDD focuses on describing the desired behavior of the system from the user's perspective. This is typically done using a Gherkin syntax with "Given-When-Then" statements. While BDD can be used with TDD, it's not strictly required.&lt;/p&gt;

&lt;p&gt;So Chai’s is used as an assertion library for BDD and TDD within your BDD/TDD workflows. While Chai itself isn't inherently tied to BDD or TDD, it provides the tools to write assertions that align with these methodologies.&lt;/p&gt;

&lt;p&gt;Chai also has several interfaces that a developer can choose from and it will look like the tests are being written in English sentences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of using Mocha and Chai for Unit Testing in Node.js
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Readable and expressive assertions&lt;/strong&gt;&lt;br&gt;
Chai offers various assertion styles and expressive syntax choices, smoothly integrating with Mocha. You may select the assertion style that best fits your preferences and readability requirements from various available styles, including the widely used expect, assert, and should.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Support for asynchronous testing&lt;/strong&gt;&lt;br&gt;
Node.js applications frequently use asynchronous processes like database queries and network requests. You may write tests involving asynchronous code with Mocha without the need for extra libraries or complicated configurations since it smoothly manages asynchronous testing.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Running Mocha Tests in Node
&lt;/h2&gt;

&lt;p&gt;First, install Mocha as a dependency by running the command below on the terminal of your computer:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i --save-dev mocha&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open the package.json file and change the scripts block to mocha as seen in the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 "name": "unit-tests-mocha-chai",
 "version": "1.0.0",
 "description": "Unit Test",
 "main": "index.js",
 "directories": {
   "test": "tests"
 },
 "scripts": {
   "test": "mocha"
 },
 "author": "LambdaTest-Leslie",
 "license": "ISC",
 "devDependencies": {
   "mocha": "^10.4.0"
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our script is now configured to run a test using mocha. Next, create a test folder in your project's root directory. With this configuration, you can simply run this command to run tests in your project:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm test&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing Tests with Mocha and Chai
&lt;/h2&gt;

&lt;p&gt;Writing tests with Mocha mostly requires the use of an assertion library which will be used to verify that the result from an operation aligns with the expected result.&lt;/p&gt;

&lt;p&gt;We’ll use Chai as the assertion library in this blog. Run the command below to install Chai as a development dependency: &lt;br&gt;
&lt;code&gt;npm i --save-dev chai&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The package.json file should now look like this after Mocha and Chai have both been installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"name": "unit-tests-mocha-chai",
 "version": "1.0.0",
 "description": "Unit Test",
 "main": "index.js",
 "directories": {
   "test": "tests"
 },
 "scripts": {
   "test": "mocha"
 },
 "author": "LambdaTest-Leslie",
 "license": "ISC",
 "devDependencies": {
   "chai": "^5.1.1",
   "mocha": "^10.4.0"
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Chai provides the following assert, expect, and should styles. To learn more about the assertion styles, visit the official &lt;a href="https://www.chaijs.com/guide/styles/" rel="noopener noreferrer"&gt;Chai documentation.&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var assert = require('chai').assert
  , foo = 'bar'
  , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };

assert.typeOf(foo, 'string'); // without optional message
assert.typeOf(foo, 'string', 'foo is a string'); // with optional message
assert.equal(foo, 'bar', 'foo equal `bar`');
assert.lengthOf(foo, 3, 'foo`s value has a length of 3');
assert.lengthOf(beverages.tea, 3, 'beverages has 3 types of tea');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var expect = require('chai').expect
  , foo = 'bar'
  , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };

expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.lengthOf(3);
expect(beverages).to.have.property('tea').with.lengthOf(3);

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var should = require('chai').should() //actually call the function
  , foo = 'bar'
  , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };

foo.should.be.a('string');
foo.should.equal('bar');
foo.should.have.lengthOf(3);
beverages.should.have.property('tea').with.lengthOf(3);

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

&lt;/div&gt;



&lt;p&gt;Chai provides numerous methods for verifying different aspects of test results. Here are some commonly used ones:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;assert.equal(a, b)&lt;/strong&gt;: Checks if two values are strictly equal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;expect(result).to.be.true&lt;/strong&gt;: Verifies if a value is true.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;assert.typeOf(value, 'string')&lt;/strong&gt;: Asserts the data type of a variable.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to Write Test Suites with Mocha
&lt;/h2&gt;

&lt;p&gt;To start writing test suites with Mocha, specify your test suite with the expected functionalities for the test. In your root project directory, and the test folder, create a test.app.js file. Next, add the following code to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");
const { add } = require("../src/app");

describe("Add the numbers", () =&amp;gt; {
 it("should return the sum of two numbers", () =&amp;gt; {
   const result = add(1, 2);
   assert.equal(result, 3);
 });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, implement the add function's functionality as a module export, and run the tests. In the root directory of your project, create a new app.js file in the src folder, and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const add = (a, b) =&amp;gt; a + b;

module.exports = {
 add,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, run the tests in your terminal using the script defined in the package.json file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is how the output should be:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Foexir74f50erylwzajrt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Foexir74f50erylwzajrt.png" alt=" " width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see in the image above that the test passed and we got a green checkmark because the output from the &lt;strong&gt;add&lt;/strong&gt; function was equal to &lt;strong&gt;3&lt;/strong&gt;. But if we change the assertion and say that we expect the result to be &lt;strong&gt;4&lt;/strong&gt; and run the test, the test is going to fail:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fvn4jft3z82ch35z1mg3t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fvn4jft3z82ch35z1mg3t.png" alt=" " width="800" height="661"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the basis of all unit tests: you run a code and then you get to check that the result you’re expecting actually corresponds with the result that the function produces.&lt;/p&gt;

&lt;p&gt;Remember that the test we just wrote was for synchronously executed codes. But since most JavaScript applications involve a lot of synchronous code, we must look into how to test asynchronous codes too. &lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Asynchronous Code
&lt;/h2&gt;

&lt;p&gt;Testing asynchronous (async) code is important in modern JavaScript (Nodejs) applications and Mocha provides built-in support for testing asynchronous operations using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;callback functions&lt;/li&gt;
&lt;li&gt;promises or &lt;/li&gt;
&lt;li&gt;async/await environments &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s look at each of these built-in support methods in the following section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Async Code Using Callback Functions
&lt;/h2&gt;

&lt;p&gt;In JavaScript, a callback is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. Callbacks are a fundamental part of asynchronous programming in JavaScript. &lt;/p&gt;

&lt;p&gt;For example, consider a fetchData function that simulates fetching data from a database with a delay. Create a new async.js file in the root directory of your project and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// async.js
function fetchData(callback) {
   setTimeout(() =&amp;gt; {
     callback('data');
   }, 1000);
 }
  module.exports = fetchData;

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

&lt;/div&gt;



&lt;p&gt;When testing functions that use callbacks, we need to inform Mocha when the asynchronous operation is complete by using the done callback. This tells Mocha to wait until the done callback is called before considering the test complete.&lt;/p&gt;

&lt;p&gt;The following code contains a test for this asynchronous function using a callback function. Create a new async.test.js  file in the test directory of your project and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Use dynamic import to load chai
import('chai').then(chai =&amp;gt; {
   const expect = chai.expect;
    // Assuming fetchData is a function that fetches data asynchronously using a callback
   const fetchData = require('../async');
    describe('Asynchronous Test with Callback', function() {
     it('should fetch data correctly', function(done) {
       fetchData((data) =&amp;gt; {
         expect(data).to.equal('data');
         done();  // Indicates that the test is complete
       });
     });
   });
 }).catch(error =&amp;gt; {
   console.error('Error importing Chai:', error);
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this test:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We import the &lt;strong&gt;fetchData&lt;/strong&gt; function and the chai assertion library.&lt;/li&gt;
&lt;li&gt;We define a test using &lt;strong&gt;it()&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Inside the test, we call &lt;strong&gt;fetchData&lt;/strong&gt; and pass a callback function.&lt;/li&gt;
&lt;li&gt;In the callback, we use Chai's &lt;strong&gt;expect&lt;/strong&gt; to assert that the fetched data is 'data'.&lt;/li&gt;
&lt;li&gt;We call done to signal Mocha that the test is finished.
Run the tests in your terminal and you should get something like this:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fhlw93werfw2jl2p2kz30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fhlw93werfw2jl2p2kz30.png" alt=" " width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You realize a test coverage table in our output shows all test files that have passed. Test coverage is a metric used to measure the amount of code being tested by your test suite. A higher coverage usually indicates a better-tested code.&lt;/p&gt;

&lt;p&gt;To get the test coverage metric to run through your tests, run the command below to install it:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install nyc --save-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, update the test script in your package.json file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 "name": "unit-tests-mocha-chai",
 "version": "1.0.0",
 "description": "Unit Test",
 "main": "index.js",
 "directories": {
   "test": "tests"
 },
 "scripts": {
   "test": "nyc mocha"
 },
 "author": "LambdaTest-Leslie",
 "license": "ISC",
 "devDependencies": {
   "chai": "^5.1.1",
   "mocha": "^10.4.0"
 },
 "dependencies": {
   "nyc": "^15.1.0"
 }
}

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

&lt;/div&gt;



&lt;p&gt;Now you can run your tests and you will get a summary showing the percentage of statements, branches, functions, and lines covered by your tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Async Code Using Promises
&lt;/h2&gt;

&lt;p&gt;Another method of testing asynchronous code is by using promises. In JavaScript, a promise represents the eventual completion (or failure) of an asynchronous operation and its resulting value. It provides a cleaner and more robust way to handle asynchronous operations compared to callbacks.&lt;/p&gt;

&lt;p&gt;To test asynchronous code that uses promises, we’ll create a file that is based on promises. Create a new &lt;strong&gt;promise.js&lt;/strong&gt; file in the root directory of your project and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// promise.js
function fetchData() {
   return new Promise((resolve) =&amp;gt; {
     setTimeout(() =&amp;gt; {
       resolve('data');
     }, 1000);
   });
 }
  module.exports = fetchData;

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

&lt;/div&gt;



&lt;p&gt;Mocha natively supports promises. If a returned promise is resolved, Mocha will consider the test successful. If it is rejected, Mocha will consider the test failed.&lt;/p&gt;

&lt;p&gt;Now, the following code contains a simple test suite for the promise method. Create a new &lt;strong&gt;promise.test.js&lt;/strong&gt; file in the test directory of your project and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// test/promise.test.js
import("chai").then((chai) =&amp;gt; {
 const expect = chai.expect;

 const fetchData = require("../promise");

 describe("Asynchronous Test with Promise", function () {
   it("should fetch data correctly", function () {
     return fetchData().then((data) =&amp;gt; {
       expect(data).to.equal("data");
     });
   });
 });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this test:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We call &lt;strong&gt;fetchData&lt;/strong&gt;, which returns a promise.&lt;/li&gt;
&lt;li&gt;We use the then method to handle the resolved value.&lt;/li&gt;
&lt;li&gt;Inside the then method, we use Chai's expect to assert that the fetched data is 'data'.&lt;/li&gt;
&lt;li&gt;Now, go ahead and run the test with this command:
&lt;code&gt;npm test&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fg0uli9w1y457709waylp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fg0uli9w1y457709waylp.png" alt=" " width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Async Code Using Async or Await Environments
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Async/await&lt;/strong&gt; is syntactic sugar built on top of promises, making asynchronous code look and behave more like synchronous code. An async function always returns a promise. The &lt;strong&gt;await&lt;/strong&gt; keyword is used to wait for a promise to resolve or reject.&lt;/p&gt;

&lt;p&gt;For environments that support the more recent async/await syntax, Mocha also supports passing async functions as the second argument to &lt;strong&gt;it()&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Let's update our fetchData function to use async/await.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchData() {
  return new Promise((resolve) =&amp;gt; {
    setTimeout(() =&amp;gt; {
      resolve('data');
    }, 1000);
  });
}
module.exports = fetchData;

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

&lt;/div&gt;



&lt;p&gt;Create a new &lt;strong&gt;asyncawait.test.js&lt;/strong&gt; file in the test directory of your project and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// test/asyncawait.test.js
import("chai").then((chai) =&amp;gt; {
 const expect = chai.expect;

 const fetchData = require("../asyncawait");

 describe("Asynchronous Test with Async/Await", function () {
   it("should fetch data correctly", async function () {
     const data = await fetchData();
     expect(data).to.equal("data");
   });
 });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this test:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We define the test function with async.&lt;/li&gt;
&lt;li&gt;Inside the test, we use the &lt;strong&gt;await&lt;/strong&gt; keyword to wait for the promise returned by fetchData to resolve.&lt;/li&gt;
&lt;li&gt;We use Chai's &lt;strong&gt;expect&lt;/strong&gt; to assert that the fetched data is 'data'.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Go ahead and run the test. The output should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Faxamdbwgoftbpq7l613j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Faxamdbwgoftbpq7l613j.png" alt=" " width="800" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Test Hooks with Mocha
&lt;/h2&gt;

&lt;p&gt;Test hooks in Mocha allow you to set up the preconditions for your tests and clean up afterward. These hooks help ensure that each test runs in a controlled environment, making tests more reliable and easier to maintain. Mocha provides several hooks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;before()&lt;/strong&gt;: Runs once before all tests in the suite.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;after()&lt;/strong&gt;: Runs once after all tests in the suite.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;beforeEach()&lt;/strong&gt;: Runs before each test in the suite.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;afterEach()&lt;/strong&gt;: Runs after each test in the suite.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It should be noted that depending on the hooks that apply to a given test suite, the hooks are run together with the tests in the suite in a definite sequence:&lt;br&gt;
&lt;code&gt;before() -&amp;gt; beforeEach() -&amp;gt; test() -&amp;gt; afterEach() -&amp;gt; after()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For example, let's create a simple user management module with functions to add and get users. We'll use Mocha's hooks to set up and tear down test conditions.&lt;/p&gt;

&lt;p&gt;Create a &lt;strong&gt;user.js&lt;/strong&gt; file and add the code that follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// user.js
class UserManager {
  constructor() {
    this.users = [];
  }

  addUser(user) {
    this.users.push(user);
  }

  getUser(id) {
    return this.users.find(user =&amp;gt; user.id === id);
  }

  clearUsers() {
    this.users = [];
  }
}

module.exports = UserManager;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's time to write a test Suite with Mocha hooks. Create a &lt;strong&gt;user.test.js&lt;/strong&gt; file in the test folder with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// test/user.test.js
import("chai").then((chai) =&amp;gt; {
 const expect = chai.expect;

 const UserManager = require("../user");

 describe("UserManager", function () {
   let userManager;

   // Runs once before all tests in the suite
   before(function () {
     userManager = new UserManager();
   });

   // Runs before each test in the suite
   beforeEach(function () {
     userManager.clearUsers();
   });

   // Runs after each test in the suite
   afterEach(function () {
     // You can perform additional cleanup here if needed
   });

   // Runs once after all tests in the suite
   after(function () {
     userManager = null;
   });

   it("should add a user", function () {
     userManager.addUser({ id: 1, name: "Carie Levin" });
     const user = userManager.getUser(1);
     expect(user).to.deep.equal({ id: 1, name: "Carie Levin" });
   });

   it("should get a user by id", function () {
     userManager.addUser({ id: 2, name: "Janelle Coop" });
     const user = userManager.getUser(2);
     expect(user).to.deep.equal({ id: 2, name: "Janelle Coop" });
   });
 });
});

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

&lt;/div&gt;



&lt;p&gt;In our test suite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Before Hook (before)&lt;/strong&gt;:
The before hook runs once before all the tests in the suite.
It initializes the userManager instance, ensuring a fresh instance is available for all tests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Before Each Hook (beforeEach)&lt;/strong&gt;:
The beforeEach hook runs before each test in the suite.
It clears the userManager users array before each test to ensure no leftover state from previous tests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;After Each Hook (afterEach)&lt;/strong&gt;:
The afterEach hook runs after each test in the suite.
You can use this hook for additional cleanup, though it is not strictly necessary in our scenario.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;After Hook (after)&lt;/strong&gt;:
The after hook runs once after all tests in the suite.
It clears the userManager instance, helping to release resources or perform final cleanup.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tests&lt;/strong&gt;:
The it blocks define individual tests.
Each test adds a user to userManager and checks that the user can be retrieved correctly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, run the test. The output should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fi55ue3z1y667o1nmpeg4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fi55ue3z1y667o1nmpeg4.png" alt=" " width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling Slow Tests and Timeouts in Mocha
&lt;/h2&gt;

&lt;p&gt;Handling slow tests and timeouts in Mocha is important to ensure that your test suite runs efficiently and provides useful feedback when tests take longer than expected. Mocha provides several mechanisms to manage these aspects, including setting timeouts, marking tests as slow, and handling asynchronous operations properly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Timeouts
&lt;/h2&gt;

&lt;p&gt;By default, Mocha sets a timeout of 2000 milliseconds (2 seconds) for each test. If a test takes longer than this to complete, it will fail. You can adjust this timeout for individual tests, suites, or globally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Timeout for Individual Tests
&lt;/h2&gt;

&lt;p&gt;You can set a custom timeout for an individual test using the &lt;code&gt;this.timeout()&lt;/code&gt; method within a test function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// test/timeout.test.js
import("chai").then((chai) =&amp;gt; {
 const expect = chai.expect;

describe('Timeout Test', function() {
  it('should complete within 5 seconds', function(done) {
    this.timeout(5000); // Set timeout to 5000 ms (5 seconds)

    setTimeout(() =&amp;gt; {
      expect(true).to.be.true;
      done();
    }, 4000); // Simulate an async operation taking 4 seconds
  });
});
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting Timeout for a Suite
&lt;/h2&gt;

&lt;p&gt;You can set a custom timeout for an entire suite using the &lt;code&gt;this.timeout()&lt;/code&gt; method within a suite function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// test/suiteTimeout.test.js
import("chai").then((chai) =&amp;gt; {
 const expect = chai.expect;

describe('Suite Timeout Test', function() {
  this.timeout(10000); // Set timeout to 10000 ms (10 seconds) for the entire suite

  it('should complete within 5 seconds', function(done) {
    setTimeout(() =&amp;gt; {
      expect(true).to.be.true;
      done();
    }, 4000);
  });

  it('should complete within 8 seconds', function(done) {
    setTimeout(() =&amp;gt; {
      expect(true).to.be.true;
      done();
    }, 7000);
  });
});
});


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

&lt;/div&gt;



&lt;p&gt;You can also set it programmatically in your test setup file (e.g., test/setup.js).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// test/setup.js
mocha.setup({
  timeout: 10000 // Set global timeout to 10000 ms (10 seconds)
});

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Handling Slow Tests
&lt;/h2&gt;

&lt;p&gt;Mocha allows you to mark tests as slow, which can help you identify potentially problematic tests that might need optimization. By default, Mocha considers tests taking longer than 75 milliseconds as slow, but this threshold can be adjusted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting Slow Threshold for Individual Tests&lt;/strong&gt;&lt;br&gt;
You can set a custom slow threshold for an individual test using the &lt;code&gt;this.slow()&lt;/code&gt; method within a test function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// test/slow.test.js
import("chai").then((chai) =&amp;gt; {
 const expect = chai.expect;

describe('Slow Test', function() {
  it('should be marked as slow if it takes more than 2 seconds', function(done) {
    this.slow(2000); // Set slow threshold to 2000 ms (2 seconds)

    setTimeout(() =&amp;gt; {
      expect(true).to.be.true;
      done();
    }, 1500); // Simulate an async operation taking 1.5 seconds
  });
});
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Setting Slow Threshold for a Suite&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can set a custom slow threshold for an entire suite using the this.slow() method within a suite function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// test/suiteSlow.test.js
import("chai").then((chai) =&amp;gt; {
 const expect = chai.expect;

describe('Suite Slow Test', function() {
  this.slow(5000); // Set slow threshold to 5000 ms (5 seconds) for the entire suite

  it('should not be marked as slow', function(done) {
    setTimeout(() =&amp;gt; {
      expect(true).to.be.true;
      done();
    }, 3000); // Simulate an async operation taking 3 seconds
  });

  it('should be marked as slow', function(done) {
    setTimeout(() =&amp;gt; {
      expect(true).to.be.true;
      done();
    }, 6000); // Simulate an async operation taking 6 seconds
  });
});
});


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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Best Practices for Performing Unit Tests with Mocha and Chai
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Each test should cover a single behavior or function to ensure that failures are easily traceable. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test names should clearly describe the behavior being tested for easier understanding and debugging.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use Mocha's hooks (before, after, beforeEach, afterEach) to set up the necessary environment and clean up after tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use variables and configuration files to manage test data, making tests more maintainable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that you cover edge cases and not just the happy paths to make your tests more robust.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Mastering Mocha and Chai for unit testing is an invaluable skill for any JavaScript developer. These tools offer a robust framework for writing, running, and managing tests, ensuring your code is reliable and maintainable.&lt;/p&gt;

&lt;p&gt;You can fine-tune your testing environment to suit your specific needs by understanding how to handle asynchronous tests with callbacks, promises, and async/await, and by utilizing Mocha’s powerful CLI options. &lt;/p&gt;

&lt;p&gt;Implementing best practices such as managing timeouts, identifying slow tests, and setting up proper test hooks will further enhance your testing efficiency. With Mocha and Chai, you can confidently develop high-quality, bug-free JavaScript applications. &lt;/p&gt;

&lt;p&gt;Do let us know me you leverage unit testing with mocha and chai in your applications!&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Advantages of Bun: When to Choose it Over Node.js 🔥</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Mon, 13 May 2024 15:56:53 +0000</pubDate>
      <link>https://dev.to/kwamedev/the-advantages-of-bun-when-to-choose-it-over-nodejs-m4m</link>
      <guid>https://dev.to/kwamedev/the-advantages-of-bun-when-to-choose-it-over-nodejs-m4m</guid>
      <description>&lt;p&gt;&lt;strong&gt;Node&lt;/strong&gt; has long been the dominant force in server-side JavaScript runtime environments. However, a new contender has emerged: &lt;strong&gt;Bun&lt;/strong&gt;. Bun promises significant performance improvements and a streamlined developer experience, making it a compelling choice for certain projects. This article explores Bun's advantages and the situations where it might be a better fit than Node.js.&lt;/p&gt;

&lt;p&gt;In this article, we will learn about &lt;strong&gt;Bun&lt;/strong&gt; and &lt;strong&gt;Node.js&lt;/strong&gt;, their characteristics, and some instances where Bun is a better substitute for Node.js - have a read!&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Nodejs and Bun?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Node.js&lt;/strong&gt; is the most popular JavaScript runtime for server-side development. It’s supported by a vast ecosystem of npm packages and a vast community. It has been around for much longer and has a well-developed ecosystem of libraries, frameworks, and tools. This makes finding solutions for various project tasks easier: APIs, backends, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bun&lt;/strong&gt;, on the other hand, is a new JavaScript runtime environment that offers built-in support for TypeScript without needing extra configuration. It directly integrates a package manager, bundler, and transpiler, streamlining the development process and reducing complexity. One thing about Bun is that it starts up applications significantly faster and executes code efficiently. Thanks to its use of the JavaScriptCore engine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bun vs Nodejs: The Good and the Bad ➰
&lt;/h3&gt;

&lt;p&gt;Here's a breakdown of the individual strengths and weaknesses of Bun and Nodejs to help you decide which one is better for your project. Time to learn!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bun&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;The Good🔥&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blazing Speed&lt;/strong&gt;: Bun shines in performance. It boasts significantly faster startup times thanks to the Zig language and faster execution speeds due to the JavaScriptCore engine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Native TypeScript Support&lt;/strong&gt;: Bun offers built-in support for TypeScript, allowing for type-safe code without extra configuration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Faster Package Management&lt;/strong&gt;: Bun's package manager, &lt;code&gt;bun install&lt;/code&gt;, is much faster than &lt;strong&gt;npm&lt;/strong&gt;, reducing development iteration times.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Bad👎🏽&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stability&lt;/strong&gt;: As a newer technology, Bun might have some stability concerns compared to the battle-tested Node.js. All Node versions except v22.0 have LTS (long-term support) release. This means that these versions of Node have been taken through several tests to ensure their performance and stability. Bun lacks this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Miniature Ecosystem&lt;/strong&gt;: Bun's ecosystem is still growing. You might not find solutions for every niche task compared to Node.js.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Nodejs&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;The Good🔥&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Large Community&lt;/strong&gt;: With a long history, Node.js has a massive user base and a wealth of online resources and support communities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fully-developed Ecosystem&lt;/strong&gt;: Node.js has an established ecosystem of libraries, frameworks, and tools. You'll likely find pre-built solutions for almost any task you can imagine.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Bad👎🏽&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Limited Native TypeScript Support&lt;/strong&gt;: While TypeScript can be used with Node.js, it requires additional configuration and dependencies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Managing dependencies and bundling code often requires additional tools like npm and webpack, which can add complexity.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bun's Performance Edge 🦾
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Bun leverages the Zig programming language for its core, resulting in significantly faster process startup compared to Node.js.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bun utilizes the JavaScriptCore engine from WebKit, known for its efficiency. Benchmarks indicate Bun can outperform Node.js in raw JavaScript execution speed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bun integrates a package manager, bundler, and transpiler, eliminating the need for external dependencies like &lt;strong&gt;Webpack&lt;/strong&gt; or &lt;strong&gt;Babel&lt;/strong&gt;. This reduces complexity and improves build times.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bun demonstrates faster file access and manipulation compared to Node.js. This can be beneficial for applications that handle large amounts of data or perform frequent disk operations.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When and Why to Choose Bun over Nodejs? 🤔
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;When your application demands top-notch performance&lt;/strong&gt;: &lt;br&gt;
Because Zig (the programming language behind Bun) offers fine-grained control over code execution, creators of Bun can optimize the speed at a fundamental level.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You're working with TypeScript and appreciate native support&lt;/strong&gt;:&lt;br&gt;
Bun offers built-in support for TypeScript, a superset of JavaScript that adds type safety. This means you can write type-safe code without needing additional configuration steps compared to Node.js, where TypeScript requires extra tools and configuration. This can lead to fewer errors and a more maintainable codebase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;When You Need a Built-In Database&lt;/strong&gt;:&lt;br&gt;
SQLite is a widely used serverless, zero-configuration, self-contained SQL database engine. This makes it a great option for an internal database because it is embeddable. It eliminates the complexity of conventional databases is eliminated, allowing you to handle organized data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bun is a wonderful choice if you're developing a web application that needs an internal database and you want to minimize the number of external dependencies. Included with it is the &lt;a href="https://bun.sh/docs/api/sqlite" rel="noopener noreferrer"&gt;bun:sqlite&lt;/a&gt; module, which is a high-performance SQLite3 driver implementation. Bun:sqlite promises three to six times greater performance than &lt;a href="https://github.com/JoshuaWise/better-sqlite3" rel="noopener noreferrer"&gt;better-sqlite3&lt;/a&gt;, but its API was influenced by the latter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Outro
&lt;/h2&gt;

&lt;p&gt;Bun's emergence as a JavaScript runtime environment offers exciting possibilities for developers seeking top-notch performance and a smooth development experience. While Node.js remains a powerful choice with its established ecosystem, Bun's strengths in speed and developer experience make it a strong contender for the future of JavaScript development. As Bun continues to mature, it will be interesting to see how it shapes the landscape of JavaScript runtime environments.&lt;/p&gt;

&lt;p&gt;Feel free to add contributions or drop questions in the comment box and until next time! Let's connect on &lt;a href="https://github.com/starboyles" rel="noopener noreferrer"&gt;Github&lt;/a&gt; and on &lt;a href="https://twitter.com/thestarboyles" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>javascript</category>
      <category>backenddevelopment</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Create an HTTP Client with Core HTTP in Nodejs</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Mon, 04 Dec 2023 01:09:20 +0000</pubDate>
      <link>https://dev.to/kwamedev/how-to-create-an-http-client-with-core-http-in-nodejs-g45</link>
      <guid>https://dev.to/kwamedev/how-to-create-an-http-client-with-core-http-in-nodejs-g45</guid>
      <description>&lt;p&gt;This article will guide developers in creating an HTTP client with core HTTP in Nodejs - have a read!&lt;/p&gt;

&lt;p&gt;Node.js comes bundled with an &lt;a href="https://nodejs.org/api/http.html" rel="noopener noreferrer"&gt;http&lt;/a&gt; and an &lt;a href="https://nodejs.org/api/https.html" rel="noopener noreferrer"&gt;https module&lt;/a&gt;. These modules have functions to create an HTTP server so that a Node.js program can respond to HTTP requests. They can also make HTTP requests to other servers. This key functionality equips Node.js programmers to create modern, API-driven web applications with Node.js. As it’s a core module, you do not need to install any libraries to use it.&lt;/p&gt;

&lt;p&gt;In this blog, you will use the https module to make HTTP requests to &lt;a href="https://jsonplaceholder.typicode.com/" rel="noopener noreferrer"&gt;JSON Placeholder&lt;/a&gt;, a fake &lt;a href="https://en.wikipedia.org/wiki/Representational_state_transfer" rel="noopener noreferrer"&gt;REST API&lt;/a&gt; for testing purposes. You will begin by making a &lt;strong&gt;GET&lt;/strong&gt; request, the standard HTTP request to receive data. You will then look at ways to customize your request, such as adding headers. Finally, you will make &lt;strong&gt;POST&lt;/strong&gt;, &lt;strong&gt;PUT&lt;/strong&gt;, and &lt;strong&gt;DELETE&lt;/strong&gt; requests so that you can modify data in an external server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This tutorial requires that you have Node.js installed. Once installed, you will be able to access the https module that’s used throughout the tutorial. This tutorial uses Node.js version 10.19.0. To install Node.js on macOS follow the steps in &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-install-node-js-and-create-a-local-development-environment-on-macos" rel="noopener noreferrer"&gt;How To Install Node.js and Create a Local Development Environment on macOS&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The methods used to send HTTP requests have a Stream-based API. In Node.js, streams are instances of event emitters. How you respond to data coming from a stream is the same as how you respond to data from events. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that you're done setting up Nodejs, let us dive in!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Making a GET Request&lt;/strong&gt;&lt;br&gt;
      When you interact with an API, you typically make &lt;strong&gt;GET&lt;/strong&gt; requests to retrieve data from web servers. In this step, you’ll look at two functions to make GET requests in Node.js. Your code will retrieve a JSON array of user profiles from a publicly accessible API.&lt;br&gt;
      The https module has two functions to make &lt;strong&gt;GET&lt;/strong&gt; requests—the &lt;code&gt;get()&lt;/code&gt; function, which can only make &lt;strong&gt;GET&lt;/strong&gt; requests, and the &lt;code&gt;request()&lt;/code&gt; function, which makes other types of requests. You will begin by making a request with the &lt;code&gt;get()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Making Requests with &lt;code&gt;get()&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
HTTP requests using the get() function have this format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https.get(URL_String, Callback_Function) {
    Action
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first argument is a string with the endpoint you’re making the request to. The second argument is a callback function, which you use to handle the response.&lt;/p&gt;

&lt;p&gt;First, set up your coding environment. In your terminal, create a folder called &lt;strong&gt;requests&lt;/strong&gt; to store all your Node.js modules for this guide:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir requests&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, enter the folder: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd requests&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create and open a new file in a text editor. This tutorial will use nano as it’s available in the terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nano getRequestWithGet.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, to make HTTP requests in Node.js, import the https module by adding the follow line:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithGet.js&lt;/strong&gt; -&amp;gt; &lt;code&gt;const https = require('https');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Node.js has an http and an https module. They have the same functions and behave similarly, but https makes the requests through the Transport Layer Security (TLS/SSL). As the web servers you are using are available via HTTPS, you will use the https module. If you are making requests to and from URLs that only have HTTP, then you would use the http module.&lt;/p&gt;

&lt;p&gt;Now use the http object to make a GET request to the API to retrieve a list of users. You will use JSON Placeholder, a publicly available API for testing. This API does not keep a record of any changes you make in your requests. It simulates a real server, and returns mocked responses as long as you send a valid request.&lt;/p&gt;

&lt;p&gt;Write the following highlighted code in your text editor:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithGet.js&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;-&amp;gt; const https = require('https');

let request = https.get('https://jsonplaceholder.typicode. com/users?_limit=2', (res) =&amp;gt; { });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As mentioned in the function signature, the &lt;code&gt;get()&lt;/code&gt; function takes two parameters. The first is the API URL you are making the request to in string format and the second is a callback to handle the HTTP response. To read the data from your response, you have to add some code in the callback.&lt;/p&gt;

&lt;p&gt;HTTP responses come with a status code. A status code is a number that indicates how successful the response was. Status codes between 200 and 299 are positive responses, while codes between 400 and 599 are errors.&lt;/p&gt;

&lt;p&gt;For this request, a successful response would have a 200 status code. The first thing you’ll do in your callback will be to verify that the status code is what you expect. Add the following code to the callback function:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithGet.js&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;const https = require('https');
let request = https.get('https://jsonplaceholder.typicode.com/
users?_limit=2', (res) =&amp;gt; {
if (res.statusCode !== 200) {
    console.error(`Did not get an OK from the server. Code: ${
res.statusCode}`);
    res.resume();
return; }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response object that’s available in the callback has a statusCode property that stores the status code. If the status code is not 200, you log an error to the console and exit.&lt;/p&gt;

&lt;p&gt;Note the line that has res.resume() . You included that line to improve performance. When making HTTP requests, Node.js will consume all the data that’s sent with the request. The res.resume() method tells Node.js to ignore the stream’s data. In turn, Node.js would typically discard the data more quickly than if it left it for garbage collection—a periodic process that frees an application’s memory.&lt;/p&gt;

&lt;p&gt;Now that you’ve captured error responses, add code to read the data. Node.js responses stream their data in chunks. The strategy for retrieving data will be to listen for when data comes from the response, collate all the chunks, and then parse the JSON so your application can use it.&lt;br&gt;
   Modify the request callback to include this code:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithGet.js&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;const https = require('https');
let request = https.get('https://jsonplaceholder.typicode.com/
users?_limit=2', (res) =&amp;gt; {
if (res.statusCode !== 200) {
    console.error(`Did not get an OK from the server. Code: ${
res.statusCode}`);
    res.resume();
return; }
let data = '';
res.on('data', (chunk) =&amp;gt; { data += chunk;
});
res.on('close', () =&amp;gt; { console.log('Retrieved all data'); console.log(JSON.parse(data));
}); });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You begin by creating a new variable data that’s an empty string. You can store data as an array of numbers representing byte data or a string. This tutorial uses the latter as it’s easier to convert a JSON string to a JavaScript object.&lt;/p&gt;

&lt;p&gt;After creating the data variable, you create an event listener. Node.js streams the data of an HTTP response in chunks. Therefore, when the response object emits a data event, you will take the data it received and add it to your data variable.&lt;/p&gt;

&lt;p&gt;When all the data from the server is received, Node.js emits a close event. At this point, you parse the JSON string stored in data and log the result to the console.&lt;br&gt;
Your Node.js module can now communicate with the JSON API and log the list of users, which will be a JSON array of three users. However, there’s one small improvement you can make first.&lt;br&gt;
  This script will throw an error if you are unable to make a request. You may not be able to make a request if you lose your internet connection, for example. Add the following code to capture errors when you’re unable to send an HTTP request:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithGet.js&lt;/strong&gt; : &lt;code&gt;...&lt;br&gt;
res.on('data', (chunk) =&amp;gt; {&lt;br&gt;
    data += chunk;&lt;br&gt;
  });&lt;br&gt;
res.on('close', () =&amp;gt; { console.log('Retrieved all data'); console.log(JSON.parse(data));&lt;br&gt;
}); });&lt;br&gt;
request.on('error', (err) =&amp;gt; {&lt;br&gt;
console.error(&lt;/code&gt;Encountered an error trying to make a reques&lt;br&gt;
t: ${err.message}&lt;code&gt;);&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When a request is made but cannot be sent, the request object emits an error event. If an error event is emitted but not listened to, the Node.js program crashes. Therefore, to capture errors you add an event listener with the &lt;code&gt;on()&lt;/code&gt; function and listen for error events. When you get an error, you log its message.&lt;/p&gt;

&lt;p&gt;That’s all the code for this file. Save and exit nano by pressing &lt;code&gt;CTRL+X&lt;/code&gt;. Now execute this program with node:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node getRequestWithGet.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your console will display this response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
Retrieved all data
[
{
id: 1,
    name: 'Leanne Graham',
    username: 'Bret',
    email: 'Sincere@april.biz',
    address: {
      street: 'Kulas Light',
      suite: 'Apt. 556',
      city: 'Gwenborough',
      zipcode: '92998-3874',
      geo: [Object]
    },
    phone: '1-770-736-8031 x56442',
    website: 'hildegard.org',
    company: {
      name: 'Romaguera-Crona',
      catchPhrase: 'Multi-layered client-server neural-net',
      bs: 'harness real-time e-markets'
} },
{
id: 2,
    name: 'Ervin Howell',
username: 'Antonette',
    email: 'Shanna@melissa.tv',
    address: {
      street: 'Victor Plains',
      suite: 'Suite 879',
      city: 'Wisokyburgh',
      zipcode: '90566-7771',
      geo: [Object]
    },
    phone: '010-692-6593 x09125',
    website: 'anastasia.net',
    company: {
      name: 'Deckow-Crist',
      catchPhrase: 'Proactive didactic contingency',
      bs: 'synergize scalable supply-chains'
} }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means you’ve successfully made a &lt;code&gt;GET&lt;/code&gt;request with the core Node.js library.&lt;br&gt;
  The &lt;code&gt;get()&lt;/code&gt; method you used is a convenient method Node.js provides because &lt;code&gt;GET&lt;/code&gt; requests are a very common type of request. Node.js provides a &lt;code&gt;request()&lt;/code&gt; method to make a request of any type. Next, this tutorial will examine how to make a &lt;code&gt;GET&lt;/code&gt; request with &lt;code&gt;request()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Making Requests with &lt;code&gt;request()&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;request()&lt;/code&gt; method supports multiple function signatures. You’ll use&lt;br&gt;
this one for the subsequent example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https.request(URL_String, Options_Object, Callback_Function) {
    Action
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first argument is a string with the API endpoint. The second argument is a JavaScript object containing all the options for the request. The last argument is a callback function to handle the response.&lt;/p&gt;

&lt;p&gt;Create a new file for a new module called &lt;strong&gt;getRequestWithRequest.js:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The code you will write is similar to the &lt;code&gt;getRequestWithGet.js&lt;/code&gt; module you wrote earlier. First, import the &lt;code&gt;https&lt;/code&gt; module:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithRequest.js&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;const https = require('https');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a new JavaScript object that contains a &lt;code&gt;method&lt;/code&gt; key:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithRequest.js&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;const https = require('https');
const options = { method: 'GET'
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;method&lt;/code&gt; key in this object will tell the &lt;code&gt;request()&lt;/code&gt; function what HTTP method the request is using.&lt;/p&gt;

&lt;p&gt;Next, make the request in your code. The following codeblock highlights code that was different from the request made with the &lt;code&gt;get()&lt;/code&gt; method. In your editor, enter all of the following lines:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithRequest.js&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;...
let request = https.request('https://jsonplaceholder.typicode.
com/users?_limit=2', options, (res) =&amp;gt; { if (res.statusCode !== 200) {
    console.error(`Did not get an OK from the server. Code: ${
res.statusCode}`);
    res.resume();
return; }
let data = '';
res.on('data', (chunk) =&amp;gt; { data += chunk;
});
res.on('close', () =&amp;gt; { console.log('Retrieved all data'); console.log(JSON.parse(data));
}); });
request.end(); request.on('error', (err) =&amp;gt; {
 console.error(`Encountered an error trying to make a reques
t: ${err.message}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make a request using &lt;code&gt;request()&lt;/code&gt;, you provide the URL in the first argument, an object with the HTTP options in the second argument, and a callback to handle the response in the third argument.&lt;br&gt;
  The &lt;code&gt;options&lt;/code&gt; variable you created earlier is the second argument, telling Node.js that this is a &lt;code&gt;GET&lt;/code&gt; request. The callback is unchanged from when you first wrote it.&lt;/p&gt;

&lt;p&gt;You also call the &lt;code&gt;end()&lt;/code&gt; method of the request variable. This is an important method that must be called when using the &lt;code&gt;request()&lt;/code&gt; function. It completes the request, allowing it to be sent. If you don’t call it, the program will never complete, as Node.js will think you still have data to add to the request.&lt;br&gt;
Save and exit nano with &lt;code&gt;CTRL+X&lt;/code&gt;, or the equivalent with your text editor. Run this program in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;node getRequestWithRequest.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You will receive this output, which is the same as the first module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
Retrieved all data
[
{
id: 1,
    name: 'Leanne Graham',
    username: 'Bret',
    email: 'Sincere@april.biz',
    address: {
      street: 'Kulas Light',
      suite: 'Apt. 556',
      city: 'Gwenborough',
      zipcode: '92998-3874',
      geo: [Object]
    },
    phone: '1-770-736-8031 x56442',
    website: 'hildegard.org',
    company: {
      name: 'Romaguera-Crona',
      catchPhrase: 'Multi-layered client-server neural-net',
      bs: 'harness real-time e-markets'
} },
{
id: 2,
    name: 'Ervin Howell',
username: 'Antonette',
    email: 'Shanna@melissa.tv',
    address: {
      street: 'Victor Plains',
      suite: 'Suite 879',
      city: 'Wisokyburgh',
      zipcode: '90566-7771',
      geo: [Object]
    },
    phone: '010-692-6593 x09125',
    website: 'anastasia.net',
    company: {
      name: 'Deckow-Crist',
      catchPhrase: 'Proactive didactic contingency',
      bs: 'synergize scalable supply-chains'
} }
]

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

&lt;/div&gt;



&lt;p&gt;You have now used the &lt;code&gt;request()&lt;/code&gt; method to make a &lt;code&gt;GET&lt;/code&gt; request. It’s important to know this function as it allows you to customize your request in ways the &lt;code&gt;get()&lt;/code&gt; method cannot, like making requests with other HTTP methods.&lt;br&gt;
  Next, you will configure and customize your requests with the &lt;code&gt;request()&lt;/code&gt; function&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Configuring HTTP &lt;code&gt;request()&lt;/code&gt; Options&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;request()&lt;/code&gt; function allows you to send HTTP requests without specifying the URL in the first argument. In this case, the URL would be contained with the options object, and the &lt;code&gt;request()&lt;/code&gt; would have this function signature:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https.request(Options_Object, Callback_Function) {&lt;br&gt;
    Action&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this step, you will use this functionality to configure your &lt;code&gt;request()&lt;/code&gt; with the &lt;code&gt;options&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;Node.js allows you to enter the URL in the options object you pass to the request. To try this out, reopen the &lt;code&gt;getRequestWithRequest.js&lt;/code&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;nano getRequestWithRequest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove the URL from the request() call so that the only arguments are the options variable and the callback function:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithRequest.js&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;const https = require('https');
const options = { method: 'GET',
};
let request = https.request(options, (res) =&amp;gt; { ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now add the following properties to the options object:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithRequest.js&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;const https = require('https');
const options = {
host: 'jsonplaceholder.typicode.com', path: '/users?_limit=2',
method: 'GET'
};
let request = https.request(options, (res) =&amp;gt; { ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of one string URL, you have two properties— &lt;code&gt;host&lt;/code&gt; and &lt;code&gt;path&lt;/code&gt;. The &lt;code&gt;host&lt;/code&gt; is the domain name or IP address of the server you’re accessing. The path is everything that comes after the domain name, including query parameters (values after the question mark).&lt;br&gt;
   The options object can hold other useful data that goes into a request. For example, you can provide request headers in the options. Headers typically send metadata about the request.&lt;br&gt;
   When developers create APIs, they may choose to support different data formats. One API endpoint may be able to return data in JSON, CSV, or XML. In those APIs, the server may look at the Accept header to determine the correct response type.&lt;/p&gt;

&lt;p&gt;The Accept header specifies the type of data the user can handle. While the API being used in these examples only return JSON, you can add the &lt;code&gt;Accept&lt;/code&gt; header to your request to explicitly state that you want JSON.&lt;/p&gt;

&lt;p&gt;Add the following lines of code to append the &lt;code&gt;Accept&lt;/code&gt; header:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/getRequestWithRequest.js&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;const https = require('https');
const options = {
host: 'jsonplaceholder.typicode.com', path: '/users?_limit=2',
method: 'GET',
headers: {
    'Accept': 'application/json'
  }
};

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

&lt;/div&gt;



&lt;p&gt;By adding headers, you’ve covered the four most popular options that are sent in Node.js HTTP requests: &lt;code&gt;host&lt;/code&gt;, &lt;code&gt;path&lt;/code&gt;, &lt;code&gt;method&lt;/code&gt;, and &lt;code&gt;headers&lt;/code&gt;. Node.js supports many more options; you can read more at the official Node.js docs for more information.&lt;/p&gt;

&lt;p&gt;Enter CTRL+X to save your file and exit .&lt;br&gt;
  Next, run your code once more to make the request by only using the options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node getRequestWithRequest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The results will be the same as your previous runs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
Retrieved all data
[
{
id: 1,
    name: 'Leanne Graham',
    username: 'Bret',
    email: 'Sincere@april.biz',
    address: {
      street: 'Kulas Light',
      suite: 'Apt. 556',
      city: 'Gwenborough',
      zipcode: '92998-3874',
      geo: [Object]
    },
    phone: '1-770-736-8031 x56442',
    website: 'hildegard.org',
    company: {
      name: 'Romaguera-Crona',
      catchPhrase: 'Multi-layered client-server neural-net',
      bs: 'harness real-time e-markets'
} },
{
id: 2,
    name: 'Ervin Howell',
username: 'Antonette',
    email: 'Shanna@melissa.tv',
    address: {
      street: 'Victor Plains',
      suite: 'Suite 879',
      city: 'Wisokyburgh',
      zipcode: '90566-7771',
      geo: [Object]
    },
    phone: '010-692-6593 x09125',
    website: 'anastasia.net',
    company: {
      name: 'Deckow-Crist',
      catchPhrase: 'Proactive didactic contingency',
      bs: 'synergize scalable supply-chains'
} }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As APIs can vary from provider to provider, being comfortable with the &lt;code&gt;options&lt;/code&gt; object is key to adapting to their differing requirements, with the data types and headers being some of the most common variations.&lt;br&gt;
  So far, you have only done GET requests to retrieve data. Next, you will make a &lt;code&gt;POST&lt;/code&gt; request with Node.js so you can upload data to a server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Making a POST Request&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you upload data to a server or want the server to create data for you, you typically send a &lt;code&gt;POST&lt;/code&gt;request. In this section, you’ll create a &lt;code&gt;POST&lt;/code&gt; request in Node.js. You will make a request to create a new user in the &lt;code&gt;users&lt;/code&gt; API.&lt;/p&gt;

&lt;p&gt;Despite being a different method from GET, you will be able to reuse code from the previous requests when writing your &lt;code&gt;POST&lt;/code&gt;request. However, you will have to make the following adjustments:&lt;/p&gt;

&lt;p&gt;-Change the method in the &lt;code&gt;options&lt;/code&gt; object to &lt;code&gt;POST&lt;/code&gt; &lt;br&gt;
-Add a header to state you are uploading JSON&lt;br&gt;
-Check the status code to confirm a user was created &lt;br&gt;
-Upload the new user’s data&lt;/p&gt;

&lt;p&gt;To make these changes, first create a new file called &lt;code&gt;postRequest.js&lt;/code&gt;. &lt;br&gt;
Open this file in nano or an alternative text editor:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nano postRequest.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Begin by importing the &lt;code&gt;https&lt;/code&gt; module and creating an &lt;code&gt;options&lt;/code&gt; object:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/postRequest.js&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;const https = require('https');
const options = {
host: 'jsonplaceholder.typicode.com', path: '/users',
method: 'POST',
headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json; charset=UTF-8'
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You change the path to match what’s required for &lt;code&gt;POST&lt;/code&gt; requests. You also updated the method to &lt;code&gt;POST&lt;/code&gt;. Lastly, you added a new header in your options &lt;code&gt;Content-Type&lt;/code&gt;. This header tells the server what type of data you are uploading. In this case, you’ll be uploading JSON data with UTF-8 encoding.&lt;/p&gt;

&lt;p&gt;Next, make the request with the &lt;code&gt;request()&lt;/code&gt; function. This is similar to how you made &lt;code&gt;GET&lt;/code&gt; requests, but now you look for a different status code than 200. Add the following lines to the end of your code:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/postRequest.js&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;...
const request = https.request(options, (res) =&amp;gt; {
if (res.statusCode !== 201) {
console.error(`Did not get a Created from the server. Cod
e: ${res.statusCode}`);
    res.resume();
return; }
let data = '';
res.on('data', (chunk) =&amp;gt; { data += chunk;
});
res.on('close', () =&amp;gt; { console.log('Added new user'); console.log(JSON.parse(data));
}); });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The highlighted line of code checks if the status code is 201. The 201 status code is used to indicate that the server created a resource.&lt;/p&gt;

&lt;p&gt;This &lt;code&gt;POST&lt;/code&gt; request is meant to create a new user. For this API, you need to upload the user details. Create some user data and send that with your &lt;code&gt;POST&lt;/code&gt; request:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/postRequest.js&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;...
const requestData = {
name: 'New User',
username: 'TechContentMarketers', email: 'user@techcontentarketers.com', address: {
    street: 'North Pole',
    city: 'Murmansk',
    zipcode: '12345-6789',
  },
  phone: '555-1212',
  website: 'techcontentmarketers.com',
  company: {
    name: 'TechContentMarketers',
    catchPhrase: 'Welcome to TCM',
    bs: 'tech content creation agency'
} };
request.write(JSON.stringify(requestData));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You first created the &lt;code&gt;requestData&lt;/code&gt; variable, which is a JavaScript object containing user data. Your request does not include an &lt;code&gt;id&lt;/code&gt; field, as servers typically generate these while saving the new data.&lt;/p&gt;

&lt;p&gt;You next use the &lt;code&gt;request.write()&lt;/code&gt; function, which accepts a string or buffer object to send along with the request. As your &lt;code&gt;requestData&lt;/code&gt; variable is an object, you used the &lt;code&gt;JSON.stringify&lt;/code&gt; function to convert it to a string.&lt;br&gt;
  To complete this module, end the request and check for errors:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/postRequest.js&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;...
request.end();
request.on('error', (err) =&amp;gt; {
console.error(`Encountered an error trying to make a reques
t: ${err.message}`);
});

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

&lt;/div&gt;



&lt;p&gt;You must write data before you use the &lt;code&gt;end()&lt;/code&gt; function. The end() function tells Node.js that there’s no more data to be added to the request and sends it.&lt;/p&gt;

&lt;p&gt;Save and exit nano by pressing &lt;code&gt;CTRL+X&lt;/code&gt;.&lt;br&gt;
Run this program to confirm that a new user has been created:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node postRequest.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The following output will be displayed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
Added new user
{
  name: 'New User',
  username: 'TechContentMarketers',
  email: 'user@techcontentmarketers.com',
  address: { street: 'North Pole', city: 'Murmansk', zipcode:
 '12345-6789' },
  phone: '555-1212',
  website: 'techcontentmarketers.com',
  company: {
    name: 'TechContentMarketers',
    catchPhrase: 'Welcome to TCM',
    bs: 'tech content creation agency'
},
id: 11 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output confirms that the request was successful. The API returned the user data that was uploaded, along with the ID that was assigned to it.&lt;br&gt;
  Now that you have learned how to make &lt;code&gt;POST&lt;/code&gt; requests, you can upload data to servers in Node.js. Next, you will try out &lt;code&gt;PUT&lt;/code&gt; requests, a method used to update data in a server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4 — Making a PUT Request&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Developers make a &lt;code&gt;PUT&lt;/code&gt; request to upload data to a server. While this may be similar to &lt;code&gt;POST&lt;/code&gt; requests, &lt;code&gt;PUT&lt;/code&gt; requests have a different function. &lt;code&gt;PUT&lt;/code&gt; requests are idempotent—you can run a &lt;code&gt;PUT&lt;/code&gt; request multiple times and it will have the same result.&lt;/p&gt;

&lt;p&gt;In practice, the code you write is similar to that of a &lt;code&gt;POST&lt;/code&gt; request. You set up your options, make your request, write the data you want to upload, and verify the response.&lt;/p&gt;

&lt;p&gt;To try this out, you’re going to create a &lt;code&gt;PUT&lt;/code&gt; request that updates the first user’s username.&lt;/p&gt;

&lt;p&gt;As the code is similar to the &lt;code&gt;POST&lt;/code&gt; request, you’ll use that module as a base for this one. Copy the &lt;strong&gt;postRequest.js&lt;/strong&gt;: into a new file, &lt;strong&gt;putRequest.js&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;cd postRequest.js putRequest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now open &lt;strong&gt;putRequest.js&lt;/strong&gt; in a text editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano putRequest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make these highlighted changes so that you send a &lt;code&gt;PUT&lt;/code&gt; request to &lt;code&gt;https://jsonplaceholder.typicode.com/users/1:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/putRequest.js&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;const https = require('https');
const options = {
host: 'jsonplaceholder.typicode.com', path: '/users/1',
method: 'PUT',
headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json; charset=UTF-8'
  }
};
const request = https.request(options, (res) =&amp;gt; {
if (res.statusCode !== 200) {
console.error(`Did not get an OK from the server. Code: ${
res.statusCode}`);
    res.resume();
return; }
let data = '';
res.on('data', (chunk) =&amp;gt; { data += chunk;
});
res.on('close', () =&amp;gt; { console.log('Updated data'); console.log(JSON.parse(data));
}); });
const requestData = { username: 'digitalocean'
};
request.write(JSON.stringify(requestData));
request.end();
request.on('error', (err) =&amp;gt; {
console.error(`Encountered an error trying to make a reques
t: ${err.message}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You first change the &lt;code&gt;path&lt;/code&gt; and &lt;code&gt;method&lt;/code&gt; properties of the &lt;code&gt;options&lt;/code&gt; object. &lt;code&gt;path&lt;/code&gt;in this case identifies the user that you are going to update. When you make the request, you check if the response code is 200, meaning that the request is OK. The data you are uploading now only contains the property&lt;br&gt;
you are updating.&lt;/p&gt;

&lt;p&gt;Save and exit nano with &lt;code&gt;CTRL+X&lt;/code&gt;.&lt;br&gt;
Now execute this Node.js program in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node putRequest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will be your output:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Updated data&lt;br&gt;
{ username: 'TechContentMarketers', id: 1 }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You sent a &lt;code&gt;PUT&lt;/code&gt; request to update a pre-existing user.&lt;/p&gt;

&lt;p&gt;So far you have learned how to retrieve, add, and update data. To give us a full command of managing data via APIs, you’ll next make a &lt;code&gt;DELETE&lt;/code&gt; request to remove data from a server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5 — Making a DELETE Request&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;DELETE&lt;/code&gt; request is used to remove data from a server. It can have a request body, but most APIs tend not to require them. This method is used to delete an entire object from the server. In this section, you are going to delete a user using the API.&lt;/p&gt;

&lt;p&gt;The code you will write is similar to that of a &lt;code&gt;GET&lt;/code&gt; request, so use that module as a base for this one. &lt;/p&gt;

&lt;p&gt;Copy the &lt;strong&gt;getRequestWithRequest.js&lt;/strong&gt; file into a new &lt;strong&gt;deleteRequest.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;cp getRequestWithRequest.js deleteRequest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;code&gt;deleteRequest.js&lt;/code&gt; with nano:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano deleteRequest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now modify the code at the highlighted parts, so you can delete the first user in the API:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requests/putRequest.js&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;const https = require('https');
const options = {
host: 'jsonplaceholder.typicode.com', path: '/users/1',
method: 'DELETE',
headers: {
    'Accept': 'application/json',
  }
};
const request = https.request(options, (res) =&amp;gt; {
if (res.statusCode !== 200) {
console.error(`Did not get an OK from the server. Code: ${
res.statusCode}`);
    res.resume();
return; }
let data = '';
res.on('data', (chunk) =&amp;gt; { data += chunk;
});
res.on('close', () =&amp;gt; {
console.log('Deleted user');
    console.log(JSON.parse(data));
  });
});
request.end();
request.on('error', (err) =&amp;gt; {
console.error(`Encountered an error trying to make a reques
t: ${err.message}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this module, you begin by changing the &lt;code&gt;path&lt;/code&gt; property of the options object to the resource you want to delete—the first user. You then change the method to &lt;code&gt;DELETE&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Save and exit this file by pressing &lt;code&gt;CTRL+X&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Run this module to confirm it works. Enter the following command in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node deleteRequest.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Output&lt;br&gt;
Deleted user&lt;br&gt;
{}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;While the API does not return a response body, you still got a 200 response so the request was OK.&lt;/p&gt;

&lt;p&gt;You’ve now learned how to make &lt;code&gt;DELETE&lt;/code&gt; requests with Node.js core modules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, you made &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, and &lt;code&gt;DELETE&lt;/code&gt; requests in Node.js. &lt;/p&gt;

&lt;p&gt;No libraries were installed; these requests were made using the standard ht tps module. While &lt;code&gt;GET&lt;/code&gt; requests can be made with a &lt;code&gt;get()&lt;/code&gt; function, all other HTTP methods are done via the &lt;code&gt;request()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;The code you wrote was written for a publicly available, test API. However, the way you write requests will work for all types of APIs. &lt;/p&gt;

</description>
      <category>programming</category>
      <category>node</category>
      <category>httpclient</category>
      <category>corehttp</category>
    </item>
    <item>
      <title>Setting up a Node.js WebSocket server</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Thu, 14 Sep 2023 12:07:14 +0000</pubDate>
      <link>https://dev.to/kwamedev/setting-up-a-nodejs-websocket-server-1cnj</link>
      <guid>https://dev.to/kwamedev/setting-up-a-nodejs-websocket-server-1cnj</guid>
      <description>&lt;p&gt;Real-time communication has been of increasing significance in our digital age. Despite being appropriate in some circumstances, conventional HTTP-based communication is not intended for long-lasting, low-latency communications. WebSockets can be used in this instance.&lt;/p&gt;

&lt;p&gt;Using a single TCP connection, WebSockets enable real-time data transfer by establishing a bi-directional communication channel between a client and a server. The setup of a WebSocket server using Node.js will be covered in detail in this post. We can create reliable WebSocket servers that can meet the needs of real-time web applications by utilizing JavaScript's capability on the server side.&lt;/p&gt;

&lt;p&gt;Why should we employ WebSockets in our development processes? There are several reasons, let us look at some of these reasons in the following chapter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usefulness of WebSockets&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Because WebSocket connections are built to support several concurrent clients, they are appropriate for applications that need great scalability. WebSocket servers are capable of handling hundreds or even millions of connections at once by effectively managing connections.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Relatively Lower Latency&lt;/strong&gt;: By removing the need for repeated HTTP queries, WebSockets lower network latency and overhead. Instant data transfer is made possible by the permanent connection that WebSockets provide, resulting in a more responsive and engaging user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cross Domain Support&lt;/strong&gt;: WebSockets make it simple to communicate between many domains, allowing programmers to create applications that integrate a number of servers or services. This adaptability is particularly helpful in situations when data must be transferred across several origins.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we have looked at some of the usefulness or advantages of WebSockets, let us look at how to initialize a WebSocket server in Nodejs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we can set up a WebSocket, we'll first have to install some required dependencies. We'll employ the &lt;a href="https://github.com/websockets/ws" rel="noopener noreferrer"&gt;ws &lt;/a&gt;library for the purpose of this article. This library provides efficient WebSocket establishment for Nodejs.&lt;/p&gt;

&lt;p&gt;To install the ws library,&lt;/p&gt;

&lt;p&gt;Open your terminal, navigate to your project directory, and run the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install ws
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next chain of command is to initialize the WebSocket and we're looking at that in the chapter below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initializing a WebSocket server in Node.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the ws library is installed, let us proceed to initialize the WebSocket server in Node.js. The server will listen for incoming WebSocket connections, handle communication with clients, and facilitate the exchange of real-time data.&lt;/p&gt;

&lt;p&gt;To create a basic WebSocket server, let us create a new JavaScript file, say, &lt;strong&gt;server.js&lt;/strong&gt;, in the project directory.&lt;/p&gt;

&lt;p&gt;Next, let us require the &lt;strong&gt;ws&lt;/strong&gt; module at the beginning of the file with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const WebSocket = require('ws');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us now define a variable to hold the WebSocket server instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const wss = new WebSocket.Server({ port: 3000 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are creating a WebSocket server that will listen on port 3000. Let's add event listeners to handle WebSocket connections and messages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wss.on('connection', (ws) =&amp;gt; {
  // Handling new WebSocket connections
});

wss.on('message', (message) =&amp;gt; {
  // Handling incoming messages
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the first event listener, &lt;strong&gt;connection&lt;/strong&gt;, we can define the logic to handle new WebSocket connections. This code block will be executed each time a client establishes a WebSocket connection with the server.&lt;/p&gt;

&lt;p&gt;Similarly, in the second event listener, &lt;strong&gt;message&lt;/strong&gt;, we can define the logic to handle incoming messages from clients. This code block will be executed whenever the server receives a WebSocket message from a connected client.&lt;/p&gt;

&lt;p&gt;Let us start the WebSocket server by adding the following line of code at the end of the &lt;strong&gt;server.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;console.log('WebSocket server is running...');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will print a message in the console indicating that the WebSocket server is up and running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling WebSocket connections&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once a client establishes a WebSocket connection with the server, it is crucial to handle and manage these connections effectively.&lt;/p&gt;

&lt;p&gt;Inside the connection event listener, we can access the WebSocket connection object (ws) representing the newly connected client. We can perform various operations, such as sending initial data, tracking connected clients, or performing authentication.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wss.on('connection', (ws) =&amp;gt; {
  // Send initial data to the client
  ws.send('Welcome to the WebSocket server!');

  // Track connected clients
  // ...
});
To handle disconnections, you can listen for the WebSocket close event:

ws.on('close', () =&amp;gt; {
  // Code to handle client disconnection
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This event will be triggered when a WebSocket connection is closed by the client or due to some error. You can use this event to clean up resources associated with the client or update the list of connected clients.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling WebSocket messages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;WebSocket communication primarily revolves around exchanging messages between the client and server. Let's explore how to handle incoming messages from clients in Node.js.&lt;/p&gt;

&lt;p&gt;Inside the message event listener, we can access the received message and take appropriate actions based on its contents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wss.on('message', (message) =&amp;gt; {
  // Handle incoming messages
  console.log('Received message:', message);

  // Send a response to the client
  ws.send('Message received successfully!');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can perform custom logic based on the received message, such as updating the application state, broadcasting the message to other connected clients, or triggering specific actions.&lt;/p&gt;

&lt;p&gt;To send a message to a specific client or all connected clients, you can use the send method of the WebSocket connection object (ws).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Send a message to the client that triggered the event
ws.send('Hello client!');

// Broadcast a message to all connected clients
wss.clients.forEach((client) =&amp;gt; {
  client.send('Broadcast message!');
});

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

&lt;/div&gt;



&lt;p&gt;By utilizing the send method, you can establish seamless bidirectional communication with clients, enabling real-time updates and interactive features in your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data serialization and deserialization in WebSocket communication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;WebSocket communication involves the exchange of data between the client and server in a structured format. To ensure compatibility and seamless communication, it is essential to serialize and deserialize data appropriately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Serialization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Serialization is the process of converting data objects into a string representation that can be transmitted over the WebSocket connection. JavaScript Object Notation (JSON) is a widely used data interchange format that provides a simple and human-readable way to represent structured data.&lt;/p&gt;

&lt;p&gt;To serialize data into JSON format, we can use the JSON.stringify() method provided by JavaScript. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const data = { name: 'John', age: 25 };
const serializedData = JSON.stringify(data);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;JSON.stringify()&lt;/code&gt; method converts the data object into a JSON string, which can be sent as a message over the WebSocket connection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Deserialization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deserialization is the reverse process of serialization, where the received string representation of data is converted back into its original object form. In WebSocket communication, you need to deserialize incoming JSON strings to access and process the data. Let's use the JSON.parse() method to deserialize a JSON string into an object. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const receivedMessage = '{"name":"Jane","age":30}';
const deserializedData = JSON.parse(receivedMessage);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;JSON.parse()&lt;/strong&gt; method converts the &lt;code&gt;receivedMessage&lt;/code&gt; string into a JavaScript object, allowing you to access its properties and perform further operations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sending Serialized Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To send serialized data over a WebSocket connection, we can use the &lt;code&gt;send()&lt;/code&gt; method provided by the WebSocket connection object (ws). By converting the data into a JSON string, you can ensure its compatibility and efficient transmission.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const data = { name: 'John', age: 25 };
const serializedData = JSON.stringify(data);

ws.send(serializedData);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;send()&lt;/strong&gt; method sends the serialized data as a WebSocket message to the connected client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Receiving and Deserializing Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When receiving messages from clients, we will need to deserialize the received JSON string to access and process the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wss.on('message', (message) =&amp;gt; {
  const receivedData = JSON.parse(message);
  // Process the received data
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the message parameter represents the received WebSocket message. By deserializing the message using &lt;strong&gt;JSON.parse()&lt;/strong&gt;, we can obtain the original data object for further processing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advanced features in WebSocket server implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;WebSocket servers can incorporate advanced features to enhance functionality, security, and scalability. Next, we will explore two important aspects: handling multiple channels and implementing authentication mechanisms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling multiple channels&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;WebSocket servers often need to handle communication across multiple channels or rooms. Channels allow grouping clients based on their interests, topics, or specific interactions. This enables targeted message broadcasting and efficient data management.&lt;/p&gt;

&lt;p&gt;To implement multiple channels in your WebSocket server, you can utilize data structures like dictionaries or arrays to store and manage clients associated with each channel. When a message is received, you can then broadcast it selectively to the clients subscribed to that particular channel.&lt;/p&gt;

&lt;p&gt;Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const channels = {};

wss.on('connection', (ws) =&amp;gt; {
  // Join a specific channel
  const channel = 'general';
  if (!channels[channel]) {
    channels[channel] = [];
  }
  channels[channel].push(ws);

  // Handle incoming messages
  ws.on('message', (message) =&amp;gt; {
    // Broadcast message to all clients in the channel
    channels[channel].forEach((client) =&amp;gt; {
      client.send(message);
    });
  });

  // Handle disconnections
  ws.on('close', () =&amp;gt; {
    // Remove client from the channel
    channels[channel] = channels[channel].filter((client) =&amp;gt; client !== ws);
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, clients joining the WebSocket server are assigned to the 'general' channel by default. However, we can modify the logic to allow clients to specify their desired channel during connection or through specific messages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementing authentication mechanisms&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In order to provide secure communication and limit access to authorized clients, WebSocket servers frequently need authentication techniques. Before granting clients access to particular resources or channels, authentication allows for client identification and verification. Before accepting a client connection, your WebSocket server must first validate the client's credentials, such as tokens or session data. We can utilize libraries like JSON Web Tokens (JWT) or integrate with existing authentication solutions (e.g., OAuth) to authenticate clients.&lt;/p&gt;

&lt;p&gt;Here's a simplified example demonstrating authentication using JWT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const jwt = require('jsonwebtoken');

wss.on('connection', (ws, req) =&amp;gt; {
  const token = req.headers.authorization.split(' ')[1];

  // Verify and decode JWT token
  jwt.verify(token, 'your_secret_key', (err, decoded) =&amp;gt; {
    if (err) {
      // Handle authentication failure
      ws.close();
      return;
    }

    // Authentication successful
    // Handle further operations or channel assignment
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the client is expected to send a JWT token in the authorization header. The server verifies the token using a secret key and performs appropriate actions based on the authentication result.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we explored initializing WebSocket servers, handling WebSocket connections and messages in Node.js, data serialization and deserialization in WebSocket communication, and the implementation of a WebSocket server in Node.js for a real-world use case: real-time stock market data streaming. WebSocket servers offer several advantages for real-time applications, including real-time data updates, reduced network overhead, scalability, and customization. &lt;/p&gt;

&lt;p&gt;They enable us to build robust and interactive applications that require instant data streaming and real-time collaboration. By harnessing the power of WebSocket technology, we can create dynamic and responsive applications that deliver real-time data updates and enhance user experiences.&lt;/p&gt;

&lt;p&gt;Feel free to contribute or let me know if you have any questions. Let's connect on &lt;a href="https://twitter.com/dev_leslie_" rel="noopener noreferrer"&gt;X&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>node</category>
      <category>websocket</category>
      <category>backend</category>
    </item>
    <item>
      <title>Top Tools for DevOps That Every Engineer Should Know</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Tue, 12 Sep 2023 22:44:33 +0000</pubDate>
      <link>https://dev.to/kwamedev/top-tools-for-devops-that-every-engineer-should-know-2i5o</link>
      <guid>https://dev.to/kwamedev/top-tools-for-devops-that-every-engineer-should-know-2i5o</guid>
      <description>&lt;p&gt;It's become more and more crucial to have an effective, dependable, and scalable software development process in today's fast-paced industry. DevOps can help in this situation. Software development and IT operations are combined through the DevOps technique to produce an efficient and automated development process. DevOps teams employ a variety of technologies to manage infrastructure, automate processes, and keep an eye on apps in order to do this. The top DevOps tools that are extensively utilized in the sector will be covered in this article.&lt;/p&gt;

&lt;p&gt;Let us look at the major categories of Tools in the DevOps discipline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Version Control Systems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Systematic collaboration, code management, and change tracking are made possible via version control. Developers may successfully manage their codebases using the powerful and adaptable framework offered by Git, the most extensively used distributed version control system. Teams can easily cooperate, assuring code harmony and version control, with tools like branching, merging, and pull requests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fisszjjrpqdjv3d9c2zuh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fisszjjrpqdjv3d9c2zuh.png" alt=" " width="348" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continuous Integration/Continuous Deployment (CI/CD) Tools&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The second tool is what is called CI/CD tools. Continuous Integration/Continuous Deployment (CI/CD) tools are essential for automating and streamlining the software development and the entire delivery pipeline. These tools help developers and organizations integrate code changes, test them, and deploy them to production or staging environments in a consistent and automated manner. Here's a list of some popular CI/CD tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;CircleCI&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CircleCI is a cloud-based continuous integration and continuous deployment (CI/CD) platform that automates the software development process, allowing teams to build, test, and deploy their applications more efficiently Discover CircleCI &lt;a href="https://circleci.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Femfrx82o7xvetlptedse.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Femfrx82o7xvetlptedse.png" alt=" " width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;GitLab CI/CD&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://docs.gitlab.com/ee/ci/" rel="noopener noreferrer"&gt;GitLab CI/CD&lt;/a&gt; is an integral part of GitLab, a web-based platform for version control, source code management, and software development collaboration. GitLab CI/CD provides robust automation and continuous integration/continuous deployment capabilities to help streamline the development and delivery of software. Here are some key features and aspects of GitLab CI/CD: Version control integration, docker container support, Parallel Processing, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Focwhbkj8xxdnykqph39s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Focwhbkj8xxdnykqph39s.png" alt=" " width="340" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Jenkins&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.jenkins.io/" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt; is one of the most popular and widely used open-source automation servers for building, deploying, and automating projects, including software development. It provides a flexible and extensible framework for continuous integration (CI) and continuous delivery (CD) processes. It is especially valuable for teams that require a high degree of customization and control over their build and deployment pipelines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fjdm8ethjdw8ftf57y2nv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjdm8ethjdw8ftf57y2nv.png" alt=" " width="796" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Containerization and Orchestration Tools&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Containerization and orchestration tools play a crucial role in modern software development and deployment, particularly in the context of microservices and container-based applications. These tools help automate the management of containers, ensuring that applications run reliably, efficiently, and at scale. Here are some popular containerization and orchestration tools: Docker, Kubernetes, Podman, etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Docker&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Docker is one of the most well-known and leading containerization platforms. It allows developers to package applications and their dependencies into containers in isolation, making it easy to develop, test, and deploy software consistently across vast environments. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fz8prm9e84y3mx334lkhv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fz8prm9e84y3mx334lkhv.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Kubernetes&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://kubernetes.io/" rel="noopener noreferrer"&gt;Kubernetes(k8s)&lt;/a&gt; is the most widely used container orchestration platform. It automates the deployment, scaling, and management of containerized applications across clusters of machines. It provides features like load balancing, automatic scaling, self-healing, and more. It also has seamless scaling for modern microservices architectures.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fexd602kp472e78583ed0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fexd602kp472e78583ed0.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IaC(Infrastructure as Code) Tools&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Infrastructure as Code (IaC) tools are essential for automating and managing the provisioning and configuration of infrastructure resources in a repeatable and consistent manner. These tools enable developers and operations teams to define and manage infrastructure using code, making it easier to scale, version control, and maintain infrastructure resources. Let us explore some popular IaC tools that enable teams streamline infrastructure management in the DevOps discipline.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Terraform&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.terraform.io/" rel="noopener noreferrer"&gt;Terraform&lt;/a&gt; is an open-source Infrastructure as Code (IaC) tool developed by &lt;strong&gt;HashiCorp&lt;/strong&gt;. It enables users to define and provision infrastructure resources in a declarative and consistent manner using a domain-specific configuration language. Terraform is designed to work with various cloud providers, on-premises environments, and third-party integrations, making it a versatile tool for managing infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fdj0twiplhn14j4dm1bjt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fdj0twiplhn14j4dm1bjt.png" alt=" " width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Ansible&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.ansible.com/" rel="noopener noreferrer"&gt;Ansible&lt;/a&gt; is a configuration management and automation tool that can also be used for IaC. It uses YAML-based playbooks to define and provision infrastructure resources on various cloud providers and on-premises environments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fhw10jhza3ow0cml9o8cm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fhw10jhza3ow0cml9o8cm.png" alt=" " width="800" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cloudify&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cloudify is an open-source orchestration and automation platform that can be used for IaC to define and manage infrastructure resources across various cloud providers. Check it out &lt;a href="https://cloudify.co/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fcsn20cx2z8i3ftipjhfp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fcsn20cx2z8i3ftipjhfp.png" alt=" " width="800" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In conclusion, the field of DevOps is rapidly evolving, and DevOps engineers play a critical role in ensuring the seamless integration of development and operations processes. To excel in this dynamic and demanding environment, it's essential for DevOps engineers to be well-versed in a variety of tools and technologies.&lt;/p&gt;

&lt;p&gt;In this guide, we've explored a list of tools that DevOps engineers should be familiar with. From version control and continuous integration to containerization, orchestration, and infrastructure as code.&lt;/p&gt;

&lt;p&gt;It's crucial, however, to remember that the effectiveness of these tools relies heavily on the skill &amp;amp; expertise of the engineers who use them. While the tools can automate tasks and improve efficiency, it's the DevOps engineer's ability to design, implement, and maintain these processes that truly defines success in the field of DevOps!&lt;/p&gt;

&lt;p&gt;Let me know if you have any contributions or questions. Feel free to reach out to me on &lt;a href="https://twitter.com/dev_leslie_" rel="noopener noreferrer"&gt;X&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>engineering</category>
      <category>tools</category>
      <category>programming</category>
    </item>
    <item>
      <title>Technical Writing 101: How to get Jobs, Gigs &amp; Opportunities</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Fri, 28 Apr 2023 22:32:23 +0000</pubDate>
      <link>https://dev.to/kwamedev/technical-writing-101-how-to-get-jobs-gigs-opportunities-5kf</link>
      <guid>https://dev.to/kwamedev/technical-writing-101-how-to-get-jobs-gigs-opportunities-5kf</guid>
      <description>&lt;h2&gt;
  
  
  Table of Content
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Building technical writing skills.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating a portfolio.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Applying for Jobs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sending Cold Emails.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I have had my share of opportunities be it technical writing or software development. Sometimes these opportunities are copped through the usual route of applying for job opportunities, other times, via cold emails or DMs from CEOs or CTOs reaching out to me and asking if I would be interested in writing technical articles for their company blogs.&lt;/p&gt;

&lt;p&gt;Over the years, although technical writers are in high demand, most technical writers find it somewhat stressful securing opportunities and gigs, both freelance or contract/part-time and full-time. Hence, there's a need for clarification in the technical writing space with respect to building portfolios and getting yourself ready for opportunities.&lt;/p&gt;

&lt;p&gt;In this blog, we're going to talk about how to better position yourself for opportunities as a technical writer - have a read!&lt;/p&gt;

&lt;h2&gt;
  
  
  Building Technical Writing Skills
&lt;/h2&gt;

&lt;p&gt;Technical writing is curating instruction manuals, how-to guides, tutorials, and other supporting documents to communicate technical information in an easy-to-understand form.&lt;/p&gt;

&lt;p&gt;You need two essential skills to become a good technical writer and land opportunities that will help you make money online.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Coding Skills
Writing Skills
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;People have been asking me, "&lt;strong&gt;Hi Leslie, do I need coding skills to work as a technical writer&lt;/strong&gt;?" The short answer is Yes and No. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yes&lt;/strong&gt; because you need to know the basics of programming since most topics you will be writing on will involve breaking down complex programming concepts into a more comprehensible form.&lt;/p&gt;

&lt;p&gt;Writing a technical article aims to help the reader solve a problem or learn something new. In most cases, you have to solve these problems using code and then write about the solution by including code snippets and screenshots.&lt;br&gt;
               From my experience so far, coding has always been involved in almost all commercial technical articles I have worked on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No&lt;/strong&gt;, because you can be a designer writing articles about design or design tools. Also, you can be a data analyst writing articles on data analysis and tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Portfolio
&lt;/h2&gt;

&lt;p&gt;A strong background history or portfolio is critical in any job search irrespective of the industry. The technical writing industry is no exception. A technical writing portfolio is a collection of technical article samples that you have written. As a technical writer, having a portfolio is very important because when a client or a recruiter wants to hire you, they want to see your previous work.&lt;/p&gt;

&lt;p&gt;To build a portfolio as a technical writer build coding projects and then write on how you built these projects.&lt;/p&gt;

&lt;p&gt;For example, let's say you have learnt how to build a CRUD app with Express and Supabase, you can document the steps it took you to build the app from start to finish. This can be done by ensuring that it follows the usual &lt;strong&gt;title&lt;/strong&gt;, &lt;strong&gt;heading&lt;/strong&gt; and &lt;strong&gt;conclusion&lt;/strong&gt; format and attaching code snippets, screenshots and/or demo videos. Take a look at my article on &lt;a href="https://dev.to/kwamedev/analysing-visualising-data-with-postgresql-and-arctype-sql-client-1o5e"&gt;data visualization&lt;/a&gt; and look at how it follows the order.&lt;/p&gt;

&lt;p&gt;Do this for two or three projects and publish the articles on free developer blogging platforms like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to"&gt;DevTo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hashnode.com/" rel="noopener noreferrer"&gt;Hashnode&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Articles published on these blogging platforms will serve as your portfolio. Clients or recruiters might come across your articles on these blogging platforms and reach out to you. &lt;/p&gt;

&lt;p&gt;It's the same way a CEO reached out to me and offered me a gig worth $2000. This is proof of my claim:&lt;br&gt;
&lt;a href="https://media2.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%2F7qcxdlmkghdnrfk9oqom.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7qcxdlmkghdnrfk9oqom.jpg" alt="Proof of claim" width="800" height="1004"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Applying for Jobs
&lt;/h2&gt;

&lt;p&gt;Applying for jobs has to be the biggest headache for technical writers. There are lots of writing and guest author programs &lt;a href="//https:whopaystechnicalwriters.com"&gt;here&lt;/a&gt; for technical writers to apply to. There are also &lt;a href="https://github.com/tigthor/PaidCommunityWriterPrograms" rel="noopener noreferrer"&gt;Paid Community Programs&lt;/a&gt; and &lt;a href="https://github.com/malgamves/CommunityWriterPrograms" rel="noopener noreferrer"&gt;Community Writer Programs&lt;/a&gt; carefully curated for writers.&lt;/p&gt;

&lt;p&gt;But hang on, lots of writers fail to understand what these programs really look out for. I find a good number of writers getting their proposed topics rejected when applying for these roles. &lt;/p&gt;

&lt;p&gt;When you go through these programs, you'll realize that each of these programs has its target niche. When you look at the  &lt;a href="https://invertase.io/authors-program?utm_source=referral&amp;amp;utm_medium=aggregator&amp;amp;utm_campaign=whopaystechnicalwriters.com" rel="noopener noreferrer"&gt;Author Program&lt;/a&gt; of &lt;a href="https://invertase.io" rel="noopener noreferrer"&gt;Invertase&lt;/a&gt; what does it say? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F6amdltp2xckv6l2au2hf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F6amdltp2xckv6l2au2hf.png" alt="Invertase" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's obvious that what their author program is interested in is content on Firebase, Dart &amp;amp; Flutter, Web Technologies, etc. This basically tells you that in order for you to secure a role with this author program, you should have knowledge in these areas. How do you show that you have knowledge and expertise in those areas? - By having article samples or a portfolio that revolves around those topics. The same thing applies to any other writing program - Take note!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sending Cold Emails&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are thousands of companies, fully-fledged ones as well as startups beyond those included in the above writing programs that may require the services of technical writers mainly to create content that will revolve around their product or software in order to increase their reach.&lt;/p&gt;

&lt;p&gt;How do you find these startups and fully-fledged companies?&lt;br&gt;
You can look out for companies on &lt;a href="https://linkedin.com" rel="noopener noreferrer"&gt;Linkedin &lt;/a&gt;that have less than 20 or 50 employees by using the keyword '&lt;strong&gt;YC&lt;/strong&gt;' in the search bar and clicking on the &lt;strong&gt;Companies&lt;/strong&gt; tab. &lt;strong&gt;YC&lt;/strong&gt; is a startup accelerator company that invests funds in a lot of early-stage startups and helps them grow by giving them access to an elite network.&lt;/p&gt;

&lt;p&gt;As you can see below, the keyword results in about 1000 startups you can apply to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fm6xffostyeljsfzdz1pl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fm6xffostyeljsfzdz1pl.png" alt="YC" width="800" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you find a target company, regardless of their hiring status, send a connection request to the employees listed above with a certain message or email attached. This message should contain a very convincing message about yourself and your skill set (also add your resume or CV). &lt;/p&gt;

&lt;p&gt;Then you would pitch yourself to the company, explaining to them that if their budget did not allow for a new hire, you'd be willing to work for free as your only goal is to gain real-world experience (this is the hook that grabs their attention). This has landed a good number of tech writers and developers full-time and part-time roles.&lt;/p&gt;

&lt;p&gt;I personally did this and it landed me a huge technical writing contract. Trust me, it'll work for you too once you put it in the work. Look at screenshots of my email transcripts below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Cold Email&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://media2.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%2Fhknm5ie6etxz3mdv7op5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fhknm5ie6etxz3mdv7op5.png" alt="Email" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Response&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fr6n99cp43j96vqgf6nt2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fr6n99cp43j96vqgf6nt2.png" alt="Reponse" width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Technical writing can be a lucrative and rewarding career, but getting started can be challenging. To be successful, you'll need to develop your technical writing skills and create a strong portfolio that shows the world your work.&lt;/p&gt;

&lt;p&gt;Building an audience on social media, applying to community writer programs, and sending cold emails are all effective ways of finding technical writing opportunities.&lt;/p&gt;

&lt;p&gt;Follow me on Twitter @&lt;a href="https://twitter.com/dev_leslie_" rel="noopener noreferrer"&gt;dev_leslie_ &lt;/a&gt;for daily tips on technical writing&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>technicalwriting</category>
      <category>programming</category>
      <category>blogging</category>
    </item>
    <item>
      <title>ANALYSING &amp; VISUALISING DATA With PostgreSQL and Arctype SQL CLIENT</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Tue, 22 Nov 2022 17:55:28 +0000</pubDate>
      <link>https://dev.to/kwamedev/analysing-visualising-data-with-postgresql-and-arctype-sql-client-1o5e</link>
      <guid>https://dev.to/kwamedev/analysing-visualising-data-with-postgresql-and-arctype-sql-client-1o5e</guid>
      <description>&lt;p&gt;In this article, we’ll learn how to analyse data using PostgreSQL and an SQL client known as Arctype.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data analytics&lt;/strong&gt; is significant since it aids in the performance optimisation of business. Companies can assist cut costs by locating more effective ways to do business by incorporating it into their business strategy. Additionally, a corporation can use data analytics to improve business decisions and track consumer preferences and trends to develop fresh, improved goods and services.&lt;/p&gt;

&lt;p&gt;It is necessary for companies and startups that want to be at the top of their game to employ data analytics because it helps businesses understand the problems they are facing and to explore data in several meaningful ways.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Analysis? What is it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data analysis is the process of organizing, analyzing, and displaying data with the aim of gaining insightful knowledge and influencing more informed business decisions.&lt;/p&gt;

&lt;p&gt;Whether you're looking at quantitative or qualitative data will affect the strategies you employ to examine it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is PostgreSQL&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PostgreSQL&lt;/strong&gt; is a free and open source relational database management system used as a primary data storage for many web apps, mobile apps, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arctype&lt;/strong&gt; is a collaborative SQL client for devs and teams. It is a platform where you can collaborate with teams, manage data, and create dashboards using your own queries and logic. Arctype workspaces are straightforward to share, and their granular access control makes it easy to invite users and manage access restrictions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SETTING Up The ARCTYPE SQL CLIENT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is how Arctype homepage looks like&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fcfzqjnb8d7kb24ef9cz0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fcfzqjnb8d7kb24ef9cz0.png" alt=" " width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Arctype application is available for download for macOS, Linux, and Windows operating systems. Download, install and open it up. Follow the prompts by creating an account and get the client ready.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SETTING Up PostgreSQL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To download Postgres, navigate to the &lt;a href="http://www.postgresql.org/download/" rel="noopener noreferrer"&gt;postgres page&lt;/a&gt; . Postgres is available for macOS, Linux and Windows operating systems. After downloading and installing Postgres, run this command to open the Postgres command prompt&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo -u postgres psql postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This opens up the command prompt and demands that you authenticate the command prompt with a password. Enter your password. Next, create a database, say “library”, in PostgreSQL where data from the library CSV file will  be stored by running the command below and hitting ‘enter’ on the keyboard&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE library;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To know if your database has been created successfully, run this command.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;The library database is highlighted in red.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fn89s8r483wr4fibhtef5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fn89s8r483wr4fibhtef5.png" alt=" " width="800" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MERGING Postgres With the Arctype SQL client&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open Arctype SQL client after installation and creating your account, Now select your database (PostgreSQL)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fjom7i5sz3sau2cydp0gi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjom7i5sz3sau2cydp0gi.png" alt=" " width="800" height="822"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After choosing PostgreSQL as the database, key in the credentials. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fkeigvltv2nj0sa1w46be.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fkeigvltv2nj0sa1w46be.png" alt=" " width="800" height="818"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Name should be the name of the database. In this case, ‘library’. Ensure that the port is exactly the same as the port on which the server is running on Postgres. Key in the password of your computer and enter the name of the database just as you named it in the terminal. In this case ‘library’.&lt;/p&gt;

&lt;p&gt;You can know whether or not the credentials entered are correct by clicking on the “Test Connection” button at the bottom of the window. Click “Save” to save the details.&lt;/p&gt;

&lt;p&gt;This is how it looks after saving up the information&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F1ztrfjtcqfvwte3l04p7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F1ztrfjtcqfvwte3l04p7.png" alt=" " width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, the next step is to head to &lt;a href="https://www.kaggle.com/datasets/sharthz23/mts-library" rel="noopener noreferrer"&gt;kaggle&lt;/a&gt; and download the library dataset CSV file. Locate “Tables” at the top left part of the archetype, click on the three dots beside the table search field. Select “import CSV to table”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ffff542rfv70sp1lkm2eu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ffff542rfv70sp1lkm2eu.png" alt=" " width="800" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the downloaded dataset file and click ‘open’. Click “accept” on the pop-up window. This window will take you to a final window where you will be required to select where you want the data to be uploaded to and in what schema (framework) you would want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fti6xn5cid08mv4i530tc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fti6xn5cid08mv4i530tc.png" alt=" " width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click the “import CSV” button to import the CSV file. After importing successfully, click on the ‘refresh’ button at the top right, next to the ‘export’ button. This is how it should look.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fzhyyfn8o2u4xqpdc950i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fzhyyfn8o2u4xqpdc950i.png" alt=" " width="800" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;USING ARCTYPE to EXECUTE SQL Queries&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Arctype can be used to run SQL queries, display databases, or even make changes, etc. Displaying data means data can be presented in forms of graphs, barcharts, to visualize the specific data.&lt;/p&gt;

&lt;p&gt;Suppose you want to know the number of items in the MTS library. MTS Library provides ebooks, etc. An SQL query can be run to know, say, user reading statistics; item ID, book, genre, author, year of publication, etc.&lt;/p&gt;

&lt;p&gt;To run an SQL query, click on the ‘Create query’ button. Name your query. Mine will be titled "analyzed." Now, write the query for the analysis from the MTS library’s data. Write the following SQL query&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT id,year FROM items_1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The query should create a table with two columns named id and year.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PRESENTING VISUALS/CHARTS Using ARCTYPE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On the right side of the screen, you can select the type of chart you want. Here, we select “Scatter Chart.” Then below the “Select Chart Type” option, you have the “Specify Columns For The Chart" option. In this section, drag the year column to the X-axis column and the id column to the Y-axis column. Arctype should help you come up with a chart similar to the one shown here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F1bxmcq7bl6r4s1jqqz6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F1bxmcq7bl6r4s1jqqz6d.png" alt=" " width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have learned how to analyze and visualize data using postgresql and Arctype SQL client. Try different data sets and enjoy the journey!&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>postgres</category>
      <category>sql</category>
      <category>database</category>
    </item>
    <item>
      <title>The Ultimate Guide To People And Company Alternative Data</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Mon, 03 Oct 2022 23:52:24 +0000</pubDate>
      <link>https://dev.to/kwamedev/the-ultimate-guide-to-people-and-company-alternative-data-5fa6</link>
      <guid>https://dev.to/kwamedev/the-ultimate-guide-to-people-and-company-alternative-data-5fa6</guid>
      <description>&lt;p&gt;&lt;strong&gt;TABLE OF CONTENTS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;-What is Data? &lt;br&gt;
-Why People &amp;amp; Company Data? &lt;br&gt;
-Data Collection Technologies &lt;br&gt;
-People &amp;amp; Company Data Analytics &lt;br&gt;
-Understanding Data Privacy Legislation&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Is Data&lt;/strong&gt;? &lt;/p&gt;

&lt;p&gt;Data is collected either by observation or measurements and can be either qualitative or quantitative, which implies data can be in the form of texts, figures/numbers or even multimedia. Data can be video or audio recordings, photos, documents, etc. It is retrieved, reviewed and analysed, shared, and is sold or bought to and from agencies and organisations. Data itself is meaningless until it is passed through phases of intensive analytics with softwares where it is processed and interpreted to be understood and its significant patterns communicated effectively as information.&lt;/p&gt;

&lt;p&gt;The key challenge for many companies, agencies and/or organisations is transforming data into meaningful information. The power of data lies in its transformation or conversion and this tells us why some of the largest companies like Facebook, Amazon and other corporations have so&lt;br&gt;
much interest in data and value it greatly to the extent of regularly fetching consumers’ personal data without consumer authorisation or approval. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why People &amp;amp; Company Data&lt;/strong&gt;? &lt;/p&gt;

&lt;p&gt;People and Company data may be publicly available or privately permitted information about human behaviors and activities online as well as a company’s interests, business information and confidential data which may be of workers, company’s website engagements, etc. When this data is analyzed and processed, it generates statistics which identifies or has the possibility &lt;br&gt;
of identifying trends or patterns within those activities. Someone may ask, what are companies doing with my data? Below are some of the reasons &lt;/p&gt;

&lt;p&gt;● Analytics on Consumer Interactions/Behavior. - Statistical results processed from data obtained as a result of the collection of user behavior and subjected to softwares to &lt;br&gt;
generate algorithms are used by companies to align their sales and redefine their marketing techniques and strategies. In the long run, consumer’s are lured into using services offered by one company over the other. That’s one aptitude of data.&lt;/p&gt;

&lt;p&gt;● Companies use data to predict the market and align it with their future business goals. Analytics software Companies like ‘Simply Get Results’ owned by Simon Haines harnesses the value of data to improve their financial results. In huge corporations, it’s impossible to know what people are doing everyday, let alone what they’re capable of doing. Big businesses are complex and people can be unpredictable: this leaves a huge hole in every business - a productivity gap. Only data can answer the questions on how people drive business performance. &lt;/p&gt;

&lt;p&gt;● Companies use data as means of generating revenue; by converting it into cash. - Personal data are routinely sought after and are bought/sold by companies. Such trades are facilitated by data brokers. Data brokers are data providers. These brokers buy and sell consumer or customer information. Data brokers are not the only data contributors. Insiders and analysts also form part of the data contribution sector. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Collection Technologies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The digital revolutionization of industries continues to make data one of the most valuable resources. Companies set up API in their businesses and this is why: many tasks are made simpler by computers, particularly those that require gathering and processing through large amounts of data. Imagine you were interested in learning how frequently a specific business &lt;br&gt;
partner sent invoices to your organization. If your company's invoice database has an API set up, you could theoretically access the invoice records, scan the "from" data input, and print each invoice separately for your audit. &lt;/p&gt;

&lt;p&gt;Three components make up APIs: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The user&lt;/strong&gt;: is the one who submits a request. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Client&lt;/strong&gt;: the machine that requests something from the server. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Server&lt;/strong&gt;: the computer that replies to requests.&lt;/p&gt;

&lt;p&gt;The server will be constructed initially because it collects and stores data. Once that server is operational, programmers post documentation that includes the endpoints for particular data. This documentation explains the server's data's structure to outside programmers. The data on the server can then be queried (or searched) by an outside user, or you can create a program that searches the database and converts the results into a new, useful format.&lt;/p&gt;

&lt;p&gt;An API may do the following four sorts of actions: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GET&lt;/strong&gt;: asks a server for information, such as a state or specifics (like last name).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;POST&lt;/strong&gt;: This method adds data to the server, much as creating a new entry, by sending modifications from the client to the server. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PUT&lt;/strong&gt;: updates or adds to information already present &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DELETE&lt;/strong&gt;: removes data that already exists. &lt;/p&gt;

&lt;p&gt;You can search or edit any information that is readily available over an API when you combine the endpoints with these actions. Since each of these actions is distinct, you'll need to consult the API documentation to learn how to write them. &lt;br&gt;
These are the various methods you can submit a request to a server: &lt;br&gt;
● By using the JSON (JavaScript Object Notation) and XML (Extensive MarkUp Language) programming languages. And this involves passing fetched data through these sets of codes to be able to conceptualize the feedback from the server. &lt;/p&gt;

&lt;p&gt;● URL method - By putting in the URL of a source in a browser. This stands to be the easiest way of accessing data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;People &amp;amp; Company Data Analytics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Importance Of People In Organizations &lt;/p&gt;

&lt;p&gt;People are fundamental to creating value in organizations. The knowledge, skills and experience of the workforce is what helps many organizations to remain aggressive. This tells how HR professionals are important in helping businesses to flourish. Think about any company, have a look at their values, have a look at what’s actually important and most of them will say people are their most important asset. The more information you have about your people, the better you are going to be able to get the best out of them and make the best use of that resource. &lt;br&gt;
You need basic information on people; what their age profile is, what the gender mix is, what the qualification mix is, how long people are staying employed by you as an employer, why your employers leave, how good your statistics are around health and safety in the workplace, corporate reports, web pages, conference calls etc. It is important to have information about how people feel about themselves in their workplace, and how engaged they are.&lt;/p&gt;

&lt;p&gt;This is where companies have competitive advantages over other companies because of the use of certain softwares, machine learning and artificial intelligence in retrieving such information about people. &lt;br&gt;
What people analytics does is to deliver facts. And with expert advice, these facts are transformed into actionable insights, each helping you to optimize your business strategy and nurture developing talents. When starting a people analytics scheme, a few key points should come to mind. &lt;/p&gt;

&lt;p&gt;● Start with a business in mind. Think about what business questioning you’re trying to solve. &lt;/p&gt;

&lt;p&gt;● Another key point is to ask yourself what is scalable. Is the piece of analysis you’re working on or product you are working on be used by another company/business another time? Some fully-fledged companies are at a point right now when they think about GDPR (General Data Protection Regulation), when they think about data privacy, when they think about people analytics, they are at a unique inflexion point possibly, of bringing those things together and creating a truly unique dialogue with their employees where they can share what they are planning on doing and allow them a voice in that as well. It helps direct their work. This is a very promising opportunity in a promising moment where companies create a different type of relationship with their employees and analytics crew. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Data Privacy Legislation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is Publicly and Privately Available Personal Information? &lt;br&gt;
Publicly Available Personal Data is information about a person that is disclosed to the general public while Private Personal Data is information that is confidential. Personal information is&lt;br&gt;
available to the general public if it is contained in an official document(s) of public interest or it is related to public officials or if the information comprises the source of the data with public disclosure permission. &lt;/p&gt;

</description>
      <category>datascience</category>
      <category>analytics</category>
      <category>bigdata</category>
    </item>
    <item>
      <title>Conceptualizing Synchronous BuildContexts in Flutter</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Sat, 16 Jul 2022 14:46:03 +0000</pubDate>
      <link>https://dev.to/kwamedev/conceptualizing-synchronous-buildcontexts-in-flutter-2fl</link>
      <guid>https://dev.to/kwamedev/conceptualizing-synchronous-buildcontexts-in-flutter-2fl</guid>
      <description>&lt;p&gt;If you use the Flutter lint package, which as of its 2.0 release, added the use of &lt;strong&gt;BuildContexts&lt;/strong&gt; synchronous rule, you may be seeing some new red squigglies in your dart code. But does this mean use &lt;strong&gt;BuildContexts&lt;/strong&gt; synchronously? If you include this rule to your linting setup either by addition of a dependency to your Flutter lint 2.0 or by specifying it yourself, your editor will start complaining about situations like this below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fd21i99ue00e2wk75909l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fd21i99ue00e2wk75909l.png" alt=" " width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Flutter knows that BuildContexts are unreliable after an asynchronous gap and wants the user also to know it. The first priority in better understanding this is to have a grasp of the concept at hand. Remember that the BuildContext parsed to a widget is that widget’s corresponding element in the element tree.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3l6uacjc3kt301l89of0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3l6uacjc3kt301l89of0.png" alt=" " width="735" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, remember that while lots of our application code is asynchronous, Flutter’s build process is fully synchronous. There are no awaits, no futures anywhere in the assembly of your widget tree. And finally, record the unique relationship between elements and their widgets.&lt;/p&gt;

&lt;p&gt;As flutter developers, we mostly write widgets which makes it pretty easy to think that they are the primary object in the relationship. But widgets are ephemeral, living as briefly as one 1/20 of a second if your app is animating something across a high refresh rate screen.&lt;/p&gt;

&lt;p&gt;This is a huge driver of Flutter’s incredible performance, despite how wasteful it can seem to throw all these widgets away after only using them for a few milliseconds. Flutter keeping elements around where possible makes asynchronous use of &lt;em&gt;BuildContexts&lt;/em&gt; very unpredictable. There are many different scenarios that can make Flutter decide that so of your elements need to be refreshed from scrolling to navigation, to dragging and dropping. It’s not worth trying to memorize them all. For our activities today, let’s use the following rule of thumb: the more dramatically your widget tree changes from one frame to the next, the more Flutter is in need to update portions of your element tree. And for every new frame, it’s always possible that a given widget’s element has been removed from the tree.&lt;/p&gt;

&lt;p&gt;Unpredictable events from your user can force Flutter to reassemble the element tree at any moment. So the only safe way to build your widget is to avoid asynchronous usage of a &lt;em&gt;BuildContext&lt;/em&gt;. But this is just a new lint. When this lint arrived, you probably would have found some places in your code where you were breaking this rule and probably your app wasn’t catching fire. What do you think is the deal here? Part of the issue is that after an asynchronous gap, your widget’s &lt;em&gt;BuildContext&lt;/em&gt; could be a ticking time bomb waiting to explode the second you touch it, or it could be totally fine. Let’s look at some code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F25p3j179l9z7fxf37xzn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F25p3j179l9z7fxf37xzn.png" alt=" " width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F0l4240zl4e4kyi0aoqkc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F0l4240zl4e4kyi0aoqkc.png" alt=" " width="800" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consider this situation above, where a button’s callback submits a form and then pops the current page. The new lint rule will say, that line is risky. But why? If you look up the lint online, you’ll see a suggestion to return early if your widget is no longer mounted, and this gets to the core of the problem at hand, because certain events like user scrolling, navigation, and several others may have already removed your widget’s element from the tree. It’s unsafe to call the famous “.of method” as parsing stale &lt;em&gt;BuildContexts&lt;/em&gt; to those methods can crash your application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fa675qpsxt6dbqa1s2jb2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fa675qpsxt6dbqa1s2jb2.png" alt=" " width="800" height="300"&gt;&lt;/a&gt;&lt;br&gt;
                                1&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fdq8eybpnljvlvmsel6ab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fdq8eybpnljvlvmsel6ab.png" alt=" " width="800" height="318"&gt;&lt;/a&gt;&lt;br&gt;
                                 2&lt;/p&gt;

&lt;p&gt;Back to that lint. The recommended fix is to do (2). The reliable way to confirm your &lt;em&gt;BuildContext&lt;/em&gt; is still valid is to check the mounted property on a state class. And the fix works for this scenario too, because if the widget is no longer mounted, something else may have already removed this package. But does this always work?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F463crvpqjs0eow27p6a8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F463crvpqjs0eow27p6a8.png" alt=" " width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine this scenario above, where instead of removing the page, you want to show a restaurant that informs the user of an action’s outcome, does the ‘if not mounted’ return check still serve our purposes? Probably not. Because even if the element has been disposed, we still want the user to seek confirmation of their action. In that case, do not conditionally return early if the widget is unmounted but instead hold on to the resources you need ahead of time and then use them after the asynchronous gap. Like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fgt2ai2deylq3iaeuxzht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgt2ai2deylq3iaeuxzht.png" alt=" " width="700" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First and foremost, we know that if somehow the user has navigated away from this screen or scrolled past it’s widget in a list view that uses the builder constructor, then our ‘MediaQuery.of’ call is doomed.&lt;/p&gt;

&lt;p&gt;Also, if this widget is no longer mounted, then we definitely do not care about updating any measurements for its children. So it’s safe to use the mounted check.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fsbamcb53kwmefgjf4rzo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fsbamcb53kwmefgjf4rzo.png" alt=" " width="700" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But what if it is still mounted? Can an [?age?] BuildContext safely read the media query and give us up-to-date values? What if the user resized the window during the await? Great news, isn’t it? In this case, Flutter will do the right thing and you wouldn’t need to worry.&lt;/p&gt;

&lt;p&gt;It is worth noting that asynchronous use of BuildContexts is one of those things that’s almost well until something happens and it is not, which is probably the reason for the new lint.&lt;/p&gt;

</description>
      <category>asynchronous</category>
      <category>buildcontexts</category>
      <category>newlint</category>
      <category>flutter</category>
    </item>
    <item>
      <title>13 easy things web developers should do to be in the top 10%</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Sat, 19 Feb 2022 16:56:34 +0000</pubDate>
      <link>https://dev.to/kwamedev/13-easy-things-web-developers-should-do-to-be-in-the-top-10-2b0i</link>
      <guid>https://dev.to/kwamedev/13-easy-things-web-developers-should-do-to-be-in-the-top-10-2b0i</guid>
      <description>&lt;p&gt;Everyone wants a $150,000 job.&lt;/p&gt;

&lt;p&gt;But only a few dedicate themselves to their career. &lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;Build a Portfolio of project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's a great way to demonstrate your skills as a developer.&lt;/p&gt;

&lt;p&gt;While you learn new skills, build projects to showcase them.&lt;/p&gt;

&lt;p&gt;Your portfolio can help you to get hired or get new opportunities.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Write Blogs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You are killing two birds with one stone when you write blogs.&lt;/p&gt;

&lt;p&gt;Improve your writing skills and learn more in order to write.&lt;/p&gt;

&lt;p&gt;You get more visibility on the Internet.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Online presence&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is a new trend in marketing.  &lt;/p&gt;

&lt;p&gt;It helps you build trust and a build personal brand.&lt;/p&gt;

&lt;p&gt;It will help you increase opportunities and signal credibility to search engines.&lt;/p&gt;

&lt;p&gt;You will have an unfair advantage doing this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to build an online presence&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Start newsletters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Share valuable content on social media platforms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Be part of engaging communities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Grow your network and connect will like-minded people.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;4.&lt;strong&gt;Have a Personal website&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;It's a great way to project a positive image of oneself into the world.&lt;/p&gt;

&lt;p&gt;It helps to showcase all your work.&lt;/p&gt;

&lt;p&gt;It also helps you in finding a job in a more pleasant way.&lt;/p&gt;

&lt;p&gt;It's your asset for a bright future.&lt;/p&gt;

&lt;p&gt;5.&lt;strong&gt;Do Open source project contribution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It gives you the opportunity to learn, or share your knowledge.&lt;/p&gt;

&lt;p&gt;You get a chance to meet legends in the community and help you to explore various technologies.&lt;/p&gt;

&lt;p&gt;Improve your coding skills by doing this.&lt;/p&gt;

&lt;p&gt;6.&lt;strong&gt;Showcase your projects on GitHub&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While you learn, build projects, and put them on Github, share them with the world. &lt;/p&gt;

&lt;p&gt;You never know when your project might go viral.&lt;/p&gt;

&lt;p&gt;Your Github profile speaks on behalf of you.&lt;/p&gt;

&lt;p&gt;7.&lt;strong&gt;Focus on Soft Skills&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Soft skills will matter the most once you climb up the ladder in your career.&lt;/p&gt;

&lt;p&gt;Writing, Leadership skills matter the most.&lt;/p&gt;

&lt;p&gt;Invest in learning soft skills in your free time.&lt;/p&gt;

&lt;p&gt;Soft skills help no matter what profession you have.&lt;/p&gt;

&lt;p&gt;8.&lt;strong&gt;Social Proof&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Launch info products to show your knowledge. &lt;/p&gt;

&lt;p&gt;Launch your side projects on Product Hunt.&lt;/p&gt;

&lt;p&gt;Have a side hustle that will help you learn new things and open doors for passive income.&lt;/p&gt;

&lt;p&gt;9.&lt;strong&gt;Don't stick to a single technology&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Learn multiple programming languages or frameworks. &lt;/p&gt;

&lt;p&gt;Once you master the fundamentals switching is much easier.&lt;/p&gt;

&lt;p&gt;Having basic knowledge about Frontend, Backend, Git, DevOps is cherry on top of the cake.&lt;/p&gt;

&lt;p&gt;10.&lt;strong&gt;Be a good feedback giver&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Giving feedback to your teammates is an art, not everybody does it well.&lt;/p&gt;

&lt;p&gt;It can do wonders to your team if the right message is conveyed at the right time.&lt;/p&gt;

&lt;p&gt;11.&lt;strong&gt;Be Creative with Problem Solving&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Creativity matters because it is very important that you have a developer that is capable of creating something that has not yet been created. &lt;/p&gt;

&lt;p&gt;Creativity and problem solving are the best skills for web developers to easily stand out.&lt;/p&gt;

&lt;p&gt;12.&lt;strong&gt;Talk at local and global conferences&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This helps you present your knowledge to the world.&lt;/p&gt;

&lt;p&gt;People will remember you if they need help or have opportunities.&lt;/p&gt;

&lt;p&gt;You improve your presentation skills.&lt;/p&gt;

&lt;p&gt;13.&lt;strong&gt;Have more hands-on experience&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By having hands-on experience, you're showing that you're detail-oriented and able to create something valuable.&lt;/p&gt;

&lt;p&gt;Practical &amp;gt; Theoretical&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Know how to code but haven’t found a great job yet ?&lt;/strong&gt; Qvault &lt;a href="https://qvault.io/?via=leslie" rel="noopener noreferrer"&gt;https://qvault.io/?via=leslie&lt;/a&gt; has got you ! &lt;/p&gt;

&lt;p&gt;You’ve probably dabbled in different programming courses and maybe even attended a bootcamp. Unfortunately, there’s still something standing between you and your next software development job. Our courses/projects will fill the knowledge gap that are holding you back! &lt;/p&gt;

&lt;p&gt;Get access to training, workshops and experienced community alongside crafting your resume whiles gaining skills from courses and confidently helping you breeze through tricky interview questions. &lt;/p&gt;

&lt;p&gt;Get yourself a package at a very affordable pricing &lt;a href="https://qvault.io/?via=leslie" rel="noopener noreferrer"&gt;https://qvault.io/?via=leslie&lt;/a&gt;&lt;/p&gt;

</description>
      <category>developers</category>
      <category>webdev</category>
      <category>toppercentile</category>
    </item>
    <item>
      <title>Data Structures every Web Developer should know</title>
      <dc:creator>Leslie Sarfo Gyamfi</dc:creator>
      <pubDate>Sat, 19 Feb 2022 14:59:34 +0000</pubDate>
      <link>https://dev.to/kwamedev/data-structures-every-web-developer-should-know-1ikg</link>
      <guid>https://dev.to/kwamedev/data-structures-every-web-developer-should-know-1ikg</guid>
      <description>&lt;p&gt;&lt;strong&gt;Data structures are&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Array&lt;/li&gt;
&lt;li&gt;Set&lt;/li&gt;
&lt;li&gt;Stack&lt;/li&gt;
&lt;li&gt;Queue&lt;/li&gt;
&lt;li&gt;Hash Table&lt;/li&gt;
&lt;li&gt;Tree&lt;/li&gt;
&lt;li&gt;Graph&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will be discussing about &lt;/p&gt;

&lt;p&gt;❍  Definition of a Data Structure&lt;br&gt;
❍  Use Case(s) for a Data Structure&lt;br&gt;
❍  Operations you should be knowing&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An array is a collection of similar data elements stored at contiguous memory locations.&lt;/p&gt;

&lt;p&gt;Use Case(s)&lt;/p&gt;

&lt;p&gt;-Data values displayed in a Table&lt;br&gt;
 -Items displayed in a List&lt;br&gt;
 -Options in a Select field&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operations you should know&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;-Creating an Array&lt;br&gt;
 -Iterate through Array&lt;br&gt;
 -Find an Element&lt;br&gt;
 -Insert Element(s)&lt;br&gt;
 -Delete Element(s)&lt;br&gt;
 -Filter an Array&lt;br&gt;
 -Fetch a Sub-Array&lt;br&gt;
 -Merging Arrays&lt;/p&gt;

&lt;p&gt;** Set**&lt;/p&gt;

&lt;p&gt;❍  Set is used to contain unique elements.&lt;br&gt;
❍  Set's elements may or, may not be ordered.&lt;/p&gt;

&lt;p&gt;Use Case(s)&lt;/p&gt;

&lt;p&gt;➀  Items added to a Shopping Cart.&lt;br&gt;
      If you add an item which is already in your shopping cart, its quantity gets increased.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operations you should be knowing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;➀  Creating a Set&lt;br&gt;
➁  Iterate through Set&lt;br&gt;
➂  Get an Element&lt;br&gt;
➃  Insert Element(s)&lt;br&gt;
➄  Delete Element(s)&lt;br&gt;
➅  Check Existence of an Element&lt;br&gt;
➆  Merging Sets&lt;/p&gt;

&lt;p&gt;Stack&lt;/p&gt;

&lt;p&gt;Stack is a type of list where an element is entered to and exited from one end only.&lt;/p&gt;

&lt;p&gt;Use Case(s)&lt;/p&gt;

&lt;p&gt;➀  Image Carousel.&lt;br&gt;
      Images in a Carousel are mostly in Stacks.&lt;br&gt;
      The last image is always displayed on top and, on swipe, the last but one comes to the top&lt;/p&gt;

&lt;p&gt;Operations you should be knowing&lt;/p&gt;

&lt;p&gt;➀  Creating a Stack&lt;br&gt;
➁  Push Element to the Stack&lt;br&gt;
➂  Pop an Element from the Stack&lt;br&gt;
➃  Size of the Stack&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Queue&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Queue is a type of list where an element is entered at one side and exited at the other side.&lt;/p&gt;

&lt;p&gt;Use Case(s)&lt;/p&gt;

&lt;p&gt;➀  A dynamically loading news feed.&lt;br&gt;
      New post appears at the bottom where as while scrolling old post at the top gets offloaded.&lt;/p&gt;

&lt;p&gt;Operations you should be knowing&lt;/p&gt;

&lt;p&gt;➀  Creating a Queue&lt;br&gt;
➁  Insert an item to Queue&lt;br&gt;
➂  Remove an item from Queue&lt;br&gt;
➃  Size of the Queue&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hash Table&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❍  It is a container of Key-Value pairs.&lt;br&gt;
❍  It is also known as Map, Dictionary.&lt;/p&gt;

&lt;p&gt;Use Case(s)&lt;/p&gt;

&lt;p&gt;➀  Storing different fields of values for a single Entity.&lt;br&gt;
E.g., Name, Address and other details of a User&lt;/p&gt;

&lt;p&gt;➁  User's preferences.&lt;br&gt;
E.g., Theme, Color, Font etc.&lt;/p&gt;

&lt;p&gt;Operations you should be knowing&lt;/p&gt;

&lt;p&gt;➀  Creating a Hash Table&lt;br&gt;
➁  Inserting an Entry&lt;br&gt;
➂  Deleting an Entry&lt;br&gt;
➃  Getting Value for a Key&lt;br&gt;
➄  Checking if a Key exists&lt;/p&gt;

&lt;p&gt;** Tree**&lt;/p&gt;

&lt;p&gt;Tree is a data structure where elements are stored in a hierarchical structure.&lt;/p&gt;

&lt;p&gt;Use case(s)&lt;/p&gt;

&lt;p&gt;➀  DOM (Document Object Model)&lt;br&gt;
➁  Organizational Structure&lt;/p&gt;

&lt;p&gt;⬕  Operations you should be knowing&lt;/p&gt;

&lt;p&gt;➀  Creating a Tree&lt;br&gt;
➁  Traversing through Tree&lt;br&gt;
➂  Fetch sub tree&lt;br&gt;
➃  Fetch siblings&lt;br&gt;
➄  Add an Element&lt;br&gt;
➅  Remove an Element&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Graph&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Graph consists of a finite set of vertices(or nodes) and set of Edges which connect a pair of nodes.&lt;/p&gt;

&lt;p&gt;Use case(s)&lt;/p&gt;

&lt;p&gt;➀  Connections in a Social Network&lt;br&gt;
➁  Locations and Routes in a Map&lt;/p&gt;

&lt;p&gt;⬕  Operations you should be knowing&lt;/p&gt;

&lt;p&gt;➀  Breadth First Search&lt;br&gt;
➁  Depth First Search&lt;br&gt;
➂  Graph Cycle&lt;br&gt;
➃  Minimum Spanning Tree&lt;br&gt;
➄  Shortest Paths&lt;/p&gt;

&lt;p&gt;⬘  As a web developer, HTML, CSS and JavaScript are must skills.&lt;/p&gt;

&lt;p&gt;⬙  To successfully model real use cases to a UI, a web developer should know about various data structures.&lt;/p&gt;

</description>
      <category>dsa</category>
      <category>web</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
