<?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>Forem: Domenico Colandrea</title>
    <description>The latest articles on Forem by Domenico Colandrea (@_domenicocolandrea).</description>
    <link>https://forem.com/_domenicocolandrea</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%2F116586%2F06f90e43-4d4a-4972-84ca-6933965fe6bb.jpeg</url>
      <title>Forem: Domenico Colandrea</title>
      <link>https://forem.com/_domenicocolandrea</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/_domenicocolandrea"/>
    <language>en</language>
    <item>
      <title>Turbocharge Your React DX: Ultra-Fast App Development with Vite &amp; TypeScript Made Easy!</title>
      <dc:creator>Domenico Colandrea</dc:creator>
      <pubDate>Mon, 04 Dec 2023 13:42:00 +0000</pubDate>
      <link>https://forem.com/_domenicocolandrea/turbocharge-your-react-developer-experience-ultra-fast-app-development-with-vite-typescript-made-easy-5lb</link>
      <guid>https://forem.com/_domenicocolandrea/turbocharge-your-react-developer-experience-ultra-fast-app-development-with-vite-typescript-made-easy-5lb</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Effortlessly Kickstart Your next React Project with Vite and TypeScript: Rapid Development, Enhanced Scalability, and Seamless Tooling. Learn how to set up a project in under 2 minutes, leveraging Vite's speed, TypeScript's type safety, and a custom boilerplate for optimized build workflows, testing, linting, and Docker integration.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;&lt;a href="https://www.codescool.io/learning/introduction-to-react"&gt;React&lt;/a&gt;, combined with &lt;a href="https://www.codescool.io/learning/introduction-to-typescript"&gt;TypeScript&lt;/a&gt;, offers a powerful way to develop scalable and maintainable web applications. TypeScript brings static typing to the world of JavaScript, making it easier to write error-free code. Meanwhile, &lt;a href="https://vitejs.dev/"&gt;Vite&lt;/a&gt; is a fast and lightweight build tool for modern web development, providing a rapid development experience focused on speed and simplicity.&lt;/p&gt;

&lt;p&gt;Facing the complexities of tooling while striving to deliver code can often be less than enjoyable. The ideal scenario involves tools seamlessly working without becoming an obstacle. In this article, we will delve into the process of initiating your upcoming &lt;strong&gt;React&lt;/strong&gt; project effortlessly using &lt;strong&gt;Vite&lt;/strong&gt; and &lt;strong&gt;TypeScript&lt;/strong&gt;, along with several other technologies, all in under 2 minutes, completely free from any setup concerns.&lt;/p&gt;

&lt;p&gt;Traditionally, you might have considered turning to Create-React-App (CRA) for this purpose. However, imagine having access to a superior alternative that not only assists in establishing the initial structure but also configures your project with essential tools for optimized build and dev workflows, unit testing, integration testing, code formatting, linting, styling, docker configuration and more!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Vite?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://vitejs.dev/"&gt;Vite&lt;/a&gt; is a build tool that aims to provide a faster and leaner development experience for modern web projects including 2 parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A dev server that provides fast Hot module replacement&lt;/li&gt;
&lt;li&gt;A build command that bundles your code, pre-configured to output highly optimized static assets for production&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Vite
&lt;/h2&gt;

&lt;p&gt;For years &lt;strong&gt;Create React App (CRA)&lt;/strong&gt; and &lt;strong&gt;Webpack&lt;/strong&gt; have been the go-to method for starting a React project. Then &lt;strong&gt;Vite&lt;/strong&gt; came along. I started using Vite for building my React projects and I quickly realized that it’s much better in many ways. One of the reasons I really like Vite is because it resolves the unreasonably long wait time to spin up a dev server which affects developers’ productivity and happiness. This is where Vite really shines.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why combine TypeScript and Vite?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.typescriptlang.org/"&gt;TypeScript&lt;/a&gt; and &lt;a href="https://vitejs.dev/"&gt;Vite&lt;/a&gt; are two powerful tools that have gained widespread popularity in the web development community. While TypeScript provides type safety and a strong foundation for building scalable applications, Vite offers a fast and efficient development experience. So, why combine these two technologies? Let’s take a look.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Improved type safety&lt;/strong&gt;: TypeScript provides optional type annotations that can catch type-related errors during development. This helps developers to write more robust and maintainable code and reduces the likelihood of bugs and unexpected behavior. With TypeScript and Vite, developers can ensure the code they write is high quality and free from type-related errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster development experience&lt;/strong&gt;: Vite was designed with speed and simplicity in mind. It offers instant reloading and optimized build times, making developing web applications more accessible and efficient. By combining TypeScript with Vite, developers can take advantage of TypeScript’s robust type system and Vite’s fast development experience for a more enjoyable and efficient development process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalable and maintainable code&lt;/strong&gt;: TypeScript is a statically typed language that supports modern JavaScript features and is widely used in large-scale projects. By combining TypeScript with Vite, developers can write scalable and maintainable code that is easy to understand and modify over time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved performance&lt;/strong&gt;: Vite is optimized for fast build times and minimal overhead, making it an excellent choice for large and complex applications. This results in improved performance and shorter load times for the end user. By combining TypeScript and Vite, developers can build high-performance web applications that deliver a fast and smooth user experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enough talking. Let’s go and set up our &lt;strong&gt;React&lt;/strong&gt; + &lt;strong&gt;Vite&lt;/strong&gt; + &lt;strong&gt;TypeScript&lt;/strong&gt; project!&lt;/p&gt;

&lt;h2&gt;
  
  
  Project setup and quick start
&lt;/h2&gt;

&lt;p&gt;First, ensure that you have &lt;strong&gt;Node.js ≥v18&lt;/strong&gt; installed on your machine.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Pro tip: &lt;a href="https://www.codescool.io/learning/how-to-easily-manage-different-node-versions-with-nvm"&gt;Nvm&lt;/a&gt; (Node.js Version Manager) makes it easier to install and manage multiple versions of Node.js on your local environment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Next, download and install &lt;a href="https://pnpm.io/"&gt;Pnpm&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-g&lt;/span&gt; pnpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://get.pnpm.io/install.sh | sh -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;PNPM is an alternative package manager for Node.js which stands for “Performant NPM”.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, create your project by running the following commands in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx degit DomenicoColandrea86/react-vite-typescript-boilerplate app
&lt;span class="nb"&gt;cd &lt;/span&gt;app
git init
nvm use
pnpm &lt;span class="nb"&gt;install
&lt;/span&gt;pnpm dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will effectively clone the boilerplate repo, navigate into the app directory, initialize a new git repository, install project dependencies, and run the dev server.&lt;/p&gt;

&lt;p&gt;The app will be served with &lt;strong&gt;Hot Reload&lt;/strong&gt; at &lt;a href="http://localhost:5173"&gt;&lt;/a&gt;&lt;a href="http://localhost:5173"&gt;http://localhost:5173&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--omvdIeJV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.codescool.io/images/react-typescript-vite-starter.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--omvdIeJV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.codescool.io/images/react-typescript-vite-starter.jpg" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Other available commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Build
&lt;/h3&gt;

&lt;p&gt;Build the app for production.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Testing the app
&lt;/h3&gt;

&lt;p&gt;This setup also comes with testing baked in using &lt;a href="https://vitest.dev/"&gt;Vitest&lt;/a&gt; and &lt;a href="https://testing-library.com/"&gt;Testing-library&lt;/a&gt;. You can run tests using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code Formatting and Linting
&lt;/h3&gt;

&lt;p&gt;Similarly, linting via &lt;a href="https://eslint.org/"&gt;ESLint&lt;/a&gt; and formatting via &lt;a href="https://prettier.io/"&gt;Prettier&lt;/a&gt; can be triggered by running the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm lint
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Docker and NGINX
&lt;/h3&gt;

&lt;p&gt;If you would like to run the app via &lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt; and &lt;a href="https://nginx.org/"&gt;NGINX&lt;/a&gt;, you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm docker:build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm docker:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more information on how to use this boilerplate, please visit &lt;a href="https://github.com/DomenicoColandrea86/react-vite-typescript-boilerplate"&gt;this&lt;/a&gt; GitHub repo.&lt;/p&gt;

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

&lt;p&gt;In this article, we discussed the many benefits of combining &lt;strong&gt;React&lt;/strong&gt;, &lt;strong&gt;TypeScript&lt;/strong&gt;, and &lt;strong&gt;Vite&lt;/strong&gt;, as well as demonstrated how to quickly scaffold a new project using these technologies following a custom boilerplate, so that you can avoid &lt;em&gt;analysis paralysis&lt;/em&gt; and focus on the important stuff — writing code and creating amazing applications!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on: &lt;a href="https://www.codescool.io/learning/start-your-next-react-project-with-vite-and-typescript-in-under-2-minutes"&gt;https://www.codescool.io/learning/start-your-next-react-project-with-vite-and-typescript-in-under-2-minutes&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>vite</category>
      <category>typescript</category>
      <category>boilerplate</category>
    </item>
    <item>
      <title>How to Effortlessly Manage Different Node.js Versions with NVM</title>
      <dc:creator>Domenico Colandrea</dc:creator>
      <pubDate>Mon, 04 Dec 2023 13:42:00 +0000</pubDate>
      <link>https://forem.com/_domenicocolandrea/how-to-effortlessly-manage-different-nodejs-versions-with-nvm-39co</link>
      <guid>https://forem.com/_domenicocolandrea/how-to-effortlessly-manage-different-nodejs-versions-with-nvm-39co</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Node.js is a popular JavaScript runtime that allows developers to build server-side applications. However, managing different Node.js versions can be challenging, especially when working on projects with different dependencies or when a specific version is required.&lt;/p&gt;

&lt;p&gt;This is where &lt;a href="https://github.com/nvm-sh/nvm"&gt;NVM (Node Version Manager)&lt;/a&gt; comes to the rescue. NVM is a handy tool that allows developers to easily install, switch, and manage multiple Node.js versions on their local machine. In this guide, we'll explore what NVM is, the problems it aims to solve, and how to get started with NVM.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is NVM and Why is it Useful?
&lt;/h2&gt;

&lt;p&gt;NVM, or Node Version Manager, is a command-line tool that allows you to manage multiple versions of Node.js on a single machine. It provides an efficient way to switch between different Node.js versions without the need for manual installation or configuration changes.&lt;/p&gt;

&lt;p&gt;With NVM, developers can easily switch to a specific Node.js version based on project requirements or compatibility with certain dependencies. This ensures that applications can be developed and tested in the desired Node.js environment, providing greater flexibility and compatibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why developers need NVM
&lt;/h2&gt;

&lt;p&gt;Developers can greatly benefit from using NVM (Node Version Manager) for several reasons. Firstly, NVM provides the flexibility to switch between different versions of Node.js on the same machine. This is essential because different projects may require different versions of Node.js due to compatibility or specific feature requirements. NVM allows developers to easily install and manage multiple Node.js versions, ensuring they have the right environment for each project.&lt;/p&gt;

&lt;p&gt;Furthermore, NVM simplifies the process of managing Node.js versions by abstracting away the complexities. Developers can switch between versions with a single command, eliminating the need for manual installations or modifications. This saves time and avoids potential conflicts between projects.&lt;/p&gt;

&lt;p&gt;NVM also offers an added level of stability and consistency. It enables developers to ensure that their applications are compatible with specific Node.js versions and allows them to test their code on different environments without the hassle of manual installations or reconfigurations.&lt;/p&gt;

&lt;p&gt;NVM is a valuable tool for developers because it provides the flexibility to manage multiple Node.js versions, simplifies the process of switching between versions, and ensures compatibility and stability across projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with NVM
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Install NVM
&lt;/h3&gt;

&lt;p&gt;To get started with NVM, the first step is to install it on your machine. The installation process varies depending on your operating system. Here are the general steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visit the NVM repository on GitHub: &lt;a href="https://github.com/nvm-sh/nvm"&gt;&lt;/a&gt;&lt;a href="https://github.com/nvm-sh/nvm"&gt;https://github.com/nvm-sh/nvm&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Follow the installation instructions specific to your operating system. For example, on macOS or Linux, you can install NVM using the curl command:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-o-&lt;/span&gt; https://raw.githubusercontent.com/nvm-sh/nvm/vx.x.x/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;vx.x.x&lt;/code&gt; with the desired NVM version.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Install Node.js Versions
&lt;/h3&gt;

&lt;p&gt;Once NVM is installed, you can use it to install different Node.js versions. Here's an example of how to install Node.js version 18:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your terminal or command prompt.&lt;/li&gt;
&lt;li&gt;Run the following command to install Node.js version 18:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install &lt;/span&gt;18
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will download and install Node.js version 18 on your machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Switch Node.js Versions
&lt;/h3&gt;

&lt;p&gt;After installing multiple Node.js versions, you can easily switch between them using NVM. Here's how to switch to Node.js version 18:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm use 18
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will set Node.js version 18 as the current active version.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other Common NVM Workflows
&lt;/h3&gt;

&lt;p&gt;Besides installing and switching Node.js versions, NVM offers several other useful features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Listing installed versions&lt;/strong&gt;: Use the &lt;code&gt;nvm ls&lt;/code&gt; command to list all installed Node.js versions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Setting a default version&lt;/strong&gt;: Use the &lt;code&gt;nvm alias default &amp;lt;version&amp;gt;&lt;/code&gt; command to set a default Node.js version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatically switching Node.js versions&lt;/strong&gt;: NVM allows you to specify a Node.js version in your project's &lt;code&gt;.nvmrc&lt;/code&gt; file. When you navigate to a directory containing this file, NVM automatically switches to the specified version.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With these additional workflows, NVM provides a seamless experience for managing different Node.js versions, making it a valuable tool for developers working on various projects or maintaining compatibility with different environments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this guide, we explored NVM and how it can help developers switch Node.js versions with ease. We discussed the purpose and benefits of NVM, followed by a detailed step-by-step guide on installing NVM, installing Node.js versions, and switching between them. We also highlighted some additional NVM workflows to enhance your development experience. By utilizing NVM, developers can efficiently manage multiple Node.js versions, ensuring compatibility and flexibility in their projects.&lt;/p&gt;

&lt;p&gt;Now that you have a solid understanding of NVM and its capabilities, you can start leveraging this powerful tool to streamline your Node.js development workflow.&lt;/p&gt;

&lt;p&gt;Originally published on: &lt;a href="https://www.codescool.io/learning/how-to-easily-manage-different-node-versions-with-nvm"&gt;https://www.codescool.io/learning/how-to-easily-manage-different-node-versions-with-nvm&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>nvm</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Master schema validation in TypeScript with Zod</title>
      <dc:creator>Domenico Colandrea</dc:creator>
      <pubDate>Tue, 28 Nov 2023 22:46:30 +0000</pubDate>
      <link>https://forem.com/_domenicocolandrea/master-schema-validation-in-typescript-with-zod-28dc</link>
      <guid>https://forem.com/_domenicocolandrea/master-schema-validation-in-typescript-with-zod-28dc</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;In this article, we'll walk you through the process of implementing schema validation in your project with the help of Zod. Zod is a powerful open-source TypeScript library designed for both declaring schemas and performing validation. We'll delve into the reasons behind choosing Zod for schema validation, offer practical examples to illustrate its usage, and even draw comparisons with alternative libraries.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;As software engineers, we often find ourselves wrestling with data validation and type safety. Ensuring that the data we receive and manipulate adheres to specific structures and constraints is crucial. Fortunately, there's a powerful tool in our TypeScript arsenal called Zod. In this guide, we'll dive deep into Zod and explore how it can revolutionize the way you handle data validation in your TypeScript projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Zod?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://zod.dev/"&gt;Zod&lt;/a&gt; is a TypeScript-first schema validation library with static type inference. It's designed to provide robust runtime validation while fully leveraging TypeScript's type system. This means you get the best of both worlds: type safety at compile-time and data validation at runtime.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Zod?
&lt;/h3&gt;

&lt;p&gt;Before we dive into the world of Zod, let's understand why schema validation is crucial in the first place. Imagine you're developing a web application that relies heavily on user input. Without proper validation, users could submit data in unexpected formats, potentially leading to runtime errors, security vulnerabilities, or data corruption. Schema validation ensures that your application only accepts data that adheres to predefined rules, preventing these issues.&lt;/p&gt;

&lt;p&gt;In one of my previous projects, we struggled with data inconsistencies and runtime errors caused by invalid data entering our system. It was a nightmare to debug and fix these issues. Then, we discovered Zod, and it was a game-changer. The ability to express data schemas as TypeScript types and validate them at runtime saved us countless hours of debugging. Since then, Zod has become an integral part of all my projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Zod
&lt;/h2&gt;

&lt;p&gt;Let's kick things off by setting up Zod in your project. Assuming you have a TypeScript project in place, you can install Zod using npm or yarn or pnpm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;zod
&lt;span class="c"&gt;# or&lt;/span&gt;
yarn add zod
&lt;span class="c"&gt;# or&lt;/span&gt;
pnpm add zod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed, you can start using Zod to define and validate data schemas.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining Schemas with Zod
&lt;/h2&gt;

&lt;p&gt;One of the core concepts in Zod is the &lt;code&gt;z&lt;/code&gt; object, which allows you to define data schemas with ease. Let's look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;email&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;infer&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've not only defined a schema for a &lt;code&gt;user&lt;/code&gt; object but also taken advantage of Zod's powerful type inference capabilities. By using &lt;code&gt;z.infer&amp;lt;typeof userSchema&amp;gt;&lt;/code&gt;, we automatically generate the &lt;code&gt;User&lt;/code&gt; type based on the schema definition. This results in a tight coupling between your schema and TypeScript types, ensuring that your data remains consistent and validated throughout your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Type Safety and Autocompletion
&lt;/h2&gt;

&lt;p&gt;One of the fantastic benefits of using Zod is that it seamlessly integrates with TypeScript. This means you not only get runtime validation but also benefit from enhanced type safety and autocompletion in your code editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;validUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;john_doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;john@example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// You get full type inference and autocompletion here&lt;/span&gt;
&lt;span class="nx"&gt;validUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// TypeScript knows this is a number&lt;/span&gt;
&lt;span class="nx"&gt;validUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// TypeScript knows this is a string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using &lt;code&gt;parse&lt;/code&gt;, we ensure that the object we're working with is not only validated but also fully typed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling Errors
&lt;/h2&gt;

&lt;p&gt;Zod makes it straightforward to handle validation errors gracefully. When data fails to meet the schema requirements, Zod throws an error that contains detailed information about what went wrong.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;invalidUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;do&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Invalid: too short&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bad-email&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Invalid: not a valid email&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Validation error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This error message is invaluable for debugging and can help you pinpoint the exact issues with the data.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Zod Advantage
&lt;/h2&gt;

&lt;p&gt;So, what makes Zod stand out from other validation libraries? Here are a few reasons:&lt;/p&gt;

&lt;h3&gt;
  
  
  TypeScript Integration
&lt;/h3&gt;

&lt;p&gt;Zod's tight integration with TypeScript means you get autocompletion and type checking right out of the box. This not only helps you catch errors early but also improves the developer experience by providing meaningful feedback within your IDE.&lt;/p&gt;

&lt;h3&gt;
  
  
  Concise and Readable Code
&lt;/h3&gt;

&lt;p&gt;Zod's API is designed to be concise and expressive. You can easily define complex schemas with just a few lines of code, leading to more readable and maintainable validation logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Comprehensive Validation
&lt;/h3&gt;

&lt;p&gt;Zod supports a wide range of validation rules, from basic data types like strings and numbers to complex objects, arrays, and more. It also provides convenient methods for common scenarios, like optional fields, defaults, and custom error messages.&lt;/p&gt;

&lt;p&gt;While Zod offers a fantastic TypeScript-first experience, it's essential to consider your project's specific requirements. Other libraries like Joi and Yup have their strengths, particularly if you're working in a JavaScript environment or need validation for other use cases. It's always a good idea to evaluate the options and choose the one that best aligns with your project's needs.&lt;/p&gt;

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

&lt;p&gt;In this blog post, we've scratched the surface of Zod, a powerful TypeScript-first schema validation library. We've explored why schema validation is essential and how Zod can streamline the process by providing type-safe validation in both compile-time and runtime. With its TypeScript integration, concise syntax, and comprehensive validation capabilities, Zod is an excellent choice for any TypeScript project.&lt;/p&gt;

&lt;p&gt;So, if you're ready to supercharge your TypeScript apps and eliminate runtime errors related to data validation, give Zod a try. It might just become your new secret weapon for building robust and error-free applications. Happy coding!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on: &lt;a href="https://www.codescool.io/learning/schema-validation-in-typescript-with-zod"&gt;https://www.codescool.io/learning/schema-validation-in-typescript-with-zod&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>zod</category>
      <category>typescript</category>
      <category>schema</category>
      <category>validation</category>
    </item>
    <item>
      <title>Level Up Your TypeScript Projects: Discover the Power of ESLint and Prettier</title>
      <dc:creator>Domenico Colandrea</dc:creator>
      <pubDate>Tue, 28 Nov 2023 22:24:35 +0000</pubDate>
      <link>https://forem.com/_domenicocolandrea/linting-in-typescript-using-eslint-and-prettier-5f44</link>
      <guid>https://forem.com/_domenicocolandrea/linting-in-typescript-using-eslint-and-prettier-5f44</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;In the dynamic world of full-stack development, incorporating linting and formatting tools such as &lt;a href="https://eslint.org/"&gt;ESLint&lt;/a&gt; and &lt;a href="https://prettier.io/"&gt;Prettier&lt;/a&gt;, along with your &lt;a href="https://www.typescriptlang.org/"&gt;TypeScript&lt;/a&gt; projects, is essential. This integration is particularly important in team settings to ensure code uniformity in syntax and style. Additionally, these tools play a vital role in early detection of errors and bugs. In this article, we'll explore how these tools automate the coding process to produce clean, consistent, and production-ready code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Understanding Linting: More Than Just Error Checking
&lt;/h2&gt;

&lt;p&gt;Linting is a transformative process that not only identifies errors but also fosters a uniform coding style. &lt;a href="https://eslint.org/"&gt;ESLint&lt;/a&gt; and &lt;a href="https://prettier.io/"&gt;Prettier&lt;/a&gt; act like personal coding coaches, ensuring your TypeScript code remains in prime condition.&lt;/p&gt;

&lt;p&gt;Code linting serves as an automated review of your source code, highlighting both programming and stylistic issues. This critical process significantly enhances code quality by minimizing errors, enforcing best coding practices, and ensuring a consistent coding style across projects. Integrating linting into your development workflow is, therefore, not just beneficial but necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  ESLint: Your TypeScript Sentinel 🛡️
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://eslint.org/"&gt;ESLint&lt;/a&gt; stands as the vigilant guardian of your TypeScript codebase.  It enforces best practices and proactively identifies potential bugs, ensuring your code is not only functional but adheres to top programming standards.&lt;/p&gt;

&lt;p&gt;This tool promotes a culture of quality and consistency. Its customizable rulesets make it adaptable for various coding scenarios, whether for individual developers or teams.&lt;/p&gt;

&lt;h3&gt;
  
  
  Initial Setup for TypeScript
&lt;/h3&gt;

&lt;p&gt;Start by integrating TypeScript into your project. If you haven't initialized a &lt;code&gt;package.json&lt;/code&gt;, begin with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init
npm &lt;span class="nb"&gt;install &lt;/span&gt;typescript &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, create a &lt;code&gt;tsconfig.json&lt;/code&gt; in your project root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx tsc &lt;span class="nt"&gt;--init&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Customize &lt;code&gt;tsconfig.json&lt;/code&gt; as needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding ESLint
&lt;/h3&gt;

&lt;p&gt;Next, integrate ESLint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;eslint &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuring ESLint
&lt;/h3&gt;

&lt;p&gt;Configure ESLint for TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx eslint &lt;span class="nt"&gt;--init&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose the options that suit your TypeScript project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example ESLint Configuration
&lt;/h3&gt;

&lt;p&gt;Your &lt;code&gt;.eslintrc.js&lt;/code&gt; might look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@typescript-eslint/parser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Specifies the ESLint parser&lt;/span&gt;
  &lt;span class="na"&gt;extends&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;plugin:@typescript-eslint/recommended&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Uses the recommended rules from @typescript-eslint/eslint-plugin&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Place to specify ESLint rules - can be used to overwrite rules specified from the extended configs&lt;/span&gt;
    &lt;span class="c1"&gt;// e.g., "@typescript-eslint/explicit-function-return-type": "off",&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Prettier: The Stylist of Your Code 🎨
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://prettier.io/"&gt;Prettier&lt;/a&gt; enhances your code's visual appeal and clarity. It automatically formats your code for consistency, which is invaluable in team projects.&lt;/p&gt;

&lt;p&gt;When combined with ESLint, Prettier ensures your code is not only functionally excellent but also aesthetically pleasing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Prettier
&lt;/h3&gt;

&lt;p&gt;Add Prettier to your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Prettier Configuration
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;.prettierrc&lt;/code&gt; file to define your formatting preferences:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"semi"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"trailingComma"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"all"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"singleQuote"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Harmony Between ESLint and Prettier 🤝
&lt;/h2&gt;

&lt;p&gt;Integrating ESLint and Prettier is crucial for enhancing code quality and readability in TypeScript projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Streamlining Their Integration
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;ESLint focuses on code quality, identifying syntax errors and enforcing best practices.&lt;/li&gt;
&lt;li&gt;Prettier takes charge of formatting, ensuring a consistent style across the codebase.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Compatibility and Collaboration
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;eslint-plugin-prettier&lt;/code&gt; and &lt;code&gt;eslint-config-prettier&lt;/code&gt; to align ESLint with Prettier, enhancing both tools' efficiency.&lt;/p&gt;

&lt;p&gt;This integration creates a cohesive development environment, where code not only functions well but also maintains a uniform, professional appearance, making teamwork and project maintenance more efficient and effective.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Compatibility Plugins
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; eslint-config-prettier eslint-plugin-prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Update ESLint Config
&lt;/h3&gt;

&lt;p&gt;Modify &lt;code&gt;.eslintrc.js&lt;/code&gt; to include Prettier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;extends&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;plugin:@typescript-eslint/recommended&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prettier/@typescript-eslint&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;plugin:prettier/recommended&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Putting It All Together 🌟
&lt;/h2&gt;

&lt;p&gt;Add these scripts to your &lt;code&gt;package.json&lt;/code&gt; for simplified linting and formatting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"lint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"eslint --fix --color ."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"format"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"prettier --write ."&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;In conclusion, integrating ESLint and Prettier into our TypeScript projects is crucial for enabling scalable growth. These tools strengthen our codebase, ensuring high-quality standards. By adopting these tools, we establish a foundation for efficient and maintainable project development. Happy coding!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on: &lt;a href="https://www.codescool.io/learning/linting-in-typeScript-using-eslint-and-prettier"&gt;https://www.codescool.io/learning/linting-in-typeScript-using-eslint-and-prettier&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>eslint</category>
      <category>prettier</category>
      <category>typescript</category>
      <category>linting</category>
    </item>
    <item>
      <title>Build and Send Stunning Emails using React and TypeScript</title>
      <dc:creator>Domenico Colandrea</dc:creator>
      <pubDate>Sun, 23 Jul 2023 23:24:00 +0000</pubDate>
      <link>https://forem.com/_domenicocolandrea/build-and-send-stunning-emails-using-react-and-typescript-4bc6</link>
      <guid>https://forem.com/_domenicocolandrea/build-and-send-stunning-emails-using-react-and-typescript-4bc6</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;In this comprehensive blog post, discover how React Email simplifies the process of building and sending emails using React and TypeScript. Explore its benefits in solving common challenges of email development, learn about its versatile use cases, and follow a detailed guide to get started with code examples. Streamline your email creation and deliver visually appealing, responsive emails with ease.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;Email communication is an integral part of modern web applications, enabling businesses to connect with their users and customers. However, historically, creating and sending well-designed, responsive emails has been a complex and time-consuming task. Developers have faced challenges in ensuring cross-client compatibility, managing complex layouts, and dynamically generating personalized content. That's where React Email comes in. React Email is a popular third-party library that simplifies the process of building and sending emails using the power of &lt;a href="https://www.codescool.io/learning/introduction-to-react" rel="noopener noreferrer"&gt;React&lt;/a&gt; and &lt;a href="https://www.codescool.io/learning/introduction-to-typescript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing React Email
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.email/" rel="noopener noreferrer"&gt;React Email&lt;/a&gt; is a versatile library that harnesses the declarative nature of React and the type safety of TypeScript to revolutionize email development. It provides a rich set of components, utilities, and styling options that enable developers to create responsive and visually appealing emails with ease. With React Email, you can focus on the content and design of your emails, while the library takes care of the underlying complexities of email rendering and cross-client compatibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problems React Email Solves
&lt;/h2&gt;

&lt;p&gt;React Email addresses several pain points that developers face when working with email development. Firstly, it simplifies the creation of responsive emails by leveraging the component-based approach of React. This allows for the easy composition and reuse of email components, resulting in more maintainable and scalable email templates.&lt;/p&gt;

&lt;p&gt;Secondly, React Email handles the intricacies of email rendering across different clients, ensuring consistent email display and functionality. It automatically generates client-specific HTML and CSS, taking care of the nuances and quirks of various email clients.&lt;/p&gt;

&lt;p&gt;Lastly, React Email seamlessly integrates with TypeScript, providing type safety and improved developer productivity. The combination of React and TypeScript empowers developers with better code organization, refactoring capabilities, and tooling support, making email development a more efficient and enjoyable experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Cases for React Email
&lt;/h2&gt;

&lt;p&gt;React Email can be utilized in a wide range of use cases. For transactional emails, such as welcome emails, order confirmations, or password reset notifications, React Email enables developers to easily craft dynamic and personalized email content. The library's flexibility allows for the inclusion of user-specific data, making each email feel tailored to the recipient.&lt;/p&gt;

&lt;p&gt;In addition, React Email is well-suited for creating visually stunning newsletters and marketing campaigns. Its component-based approach and robust styling options make it effortless to design eye-catching layouts, incorporate interactive elements, and handle responsive design principles.&lt;/p&gt;

&lt;p&gt;Furthermore, React Email can be integrated into backend systems and server-side rendering (SSR) frameworks, enabling server-generated emails with ease. This makes it an ideal choice for applications that require complex email generation logic or rely on dynamic data for email content.&lt;/p&gt;

&lt;h2&gt;
  
  
  React Email Preview
&lt;/h2&gt;

&lt;p&gt;React Email Preview is a feature of the React Email library that enables developers to visualize and review their email templates during the development process. It provides a real-time preview of how the email will appear in various email clients and devices, allowing developers to ensure consistent rendering across different platforms.&lt;/p&gt;

&lt;p&gt;With React Email Preview, developers can easily test and iterate on their email designs without the need to send test emails or rely on external email clients. The preview feature provides an interactive environment where developers can view and interact with the email template in real-time, making it easier to identify and address any rendering issues or inconsistencies.&lt;/p&gt;

&lt;p&gt;The React Email Preview feature supports different email clients and devices, giving developers the ability to see how the email will look in popular platforms such as Gmail, Outlook, and mobile devices. This helps ensure that the email design is responsive and optimized for different screen sizes and email clients, providing a seamless user experience for recipients.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.codescool.io%2Fimages%2Freact-email-project.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.codescool.io%2Fimages%2Freact-email-project.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Overall, React Email Preview simplifies the process of reviewing and fine-tuning email templates, reducing the time and effort required for manual testing and troubleshooting. By providing an interactive preview environment, developers can confidently create visually appealing and consistent email designs that deliver a great user experience across various email clients and devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with React Email
&lt;/h2&gt;

&lt;p&gt;To start building and sending emails with React Email, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install React Email as a dependency in your project using npm or yarn:&lt;/li&gt;
&lt;/ol&gt;

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

npm &lt;span class="nb"&gt;install &lt;/span&gt;react-email


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

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Import the necessary components and hooks from React Email into your email template file:&lt;/li&gt;
&lt;/ol&gt;

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

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Section&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-email&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Create the email template by utilizing the provided components and customizing them to suit your design:&lt;/li&gt;
&lt;/ol&gt;

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

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyEmailTemplate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Email&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Welcome to React Email"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Section&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, World!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Section&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Email&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Render the email template using a server-side rendering (SSR) framework like Next.js or convert it to HTML using a library like react-dom/server:&lt;/li&gt;
&lt;/ol&gt;

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

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOMServer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom/server&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;emailHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ReactDOMServer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;renderToStaticMarkup&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyEmailTemplate&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Finally, use your preferred email sending mechanism, such as an SMTP library or a third-party email service, to send the generated HTML email to your recipients.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this blog post, we explored how React Email can streamline the process of building and sending emails using React and TypeScript. We discussed the problems it solves, the benefits it offers, and its use cases in various email-related scenarios. We also provided a detailed guide on getting started with React Email, covering installation, template creation, and rendering.&lt;/p&gt;

&lt;p&gt;By leveraging React Email, developers can create visually appealing, responsive, and dynamic emails with ease. Whether you're building transactional emails, newsletters, or marketing campaigns, React Email empowers you to deliver compelling content to your users.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on: &lt;a href="https://www.codescool.io/learning/build-and-send-emails-using-react-and-typescript" rel="noopener noreferrer"&gt;https://www.codescool.io/learning/build-and-send-emails-using-react-and-typescript&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>email</category>
      <category>reactemail</category>
    </item>
    <item>
      <title>Documenting your Node.js APIs with Swagger</title>
      <dc:creator>Domenico Colandrea</dc:creator>
      <pubDate>Sun, 23 Jul 2023 22:13:00 +0000</pubDate>
      <link>https://forem.com/_domenicocolandrea/build-and-send-stunning-emails-using-react-and-typescript-15dj</link>
      <guid>https://forem.com/_domenicocolandrea/build-and-send-stunning-emails-using-react-and-typescript-15dj</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;In the world of API development, documentation plays a crucial role in ensuring seamless integration and collaboration. In this blog post, we explore how Swagger can simplify the process of documenting your Node.js APIs. Discover how Swagger enables you to generate interactive and comprehensive API documentation, streamline testing and debugging, and improve overall developer experience.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Solving API Development Challenges with the OpenAPI Specification
&lt;/h2&gt;

&lt;p&gt;Developers have long faced challenges when building APIs, with one major pain point being the lack of consistent and standardized documentation formats. Without a uniform structure, integrating and understanding different APIs becomes time-consuming and error-prone. Additionally, keeping documentation in sync with code changes can be a manual and tedious process, leading to outdated or incomplete documentation.&lt;/p&gt;

&lt;p&gt;To tackle these challenges, &lt;a href="https://swagger.io/specification/"&gt;the OpenAPI Specification (OAS)&lt;/a&gt; was introduced as an industry-standard specification for API documentation. It provides a structured and standardized approach, allowing developers to describe APIs in a machine-readable format. This includes key details such as endpoints, request/response formats, and authentication methods. By adopting the OAS, developers can achieve consistent and accurate documentation, reducing ambiguity and enhancing the overall development process. Moreover, the machine-readable nature of the OAS enables automated tools to generate interactive documentation, SDKs, and client code, saving valuable time and promoting seamless integration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simplifying API Development and Documentation with Swagger
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://swagger.io/"&gt;Swagger&lt;/a&gt; is an open-source framework widely used for simplifying API development and documentation. It offers a comprehensive set of tools for designing, building, and documenting RESTful APIs. At its core, Swagger empowers developers to describe APIs using the OpenAPI Specification. With Swagger, developers can effortlessly generate interactive and user-friendly API documentation, streamline testing and debugging, and facilitate collaboration between frontend and backend teams.&lt;/p&gt;

&lt;p&gt;A key feature of Swagger is its automatic API documentation generation. By annotating API code with Swagger-specific metadata, developers can easily create detailed documentation encompassing endpoints, request/response payloads, headers, error codes, and authentication mechanisms. This documentation is not only human-readable but also machine-readable, allowing for automatic generation of client SDKs, server stubs, and API testing tools. Swagger ensures consistent and up-to-date documentation, relieving developers from the burden of manual maintenance.&lt;/p&gt;

&lt;p&gt;Beyond documentation, Swagger provides powerful tools for API development and testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://swagger.io/tools/swagger-ui/"&gt;Swagger UI&lt;/a&gt;, a web-based interface, allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your OpenAPI Specification, with the visual documentation making it easy for back end implementation and client side consumption.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xNuQOsMp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.codescool.io/images/swagger_ui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xNuQOsMp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.codescool.io/images/swagger_ui.png" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Addressing Common Challenges with Swagger
&lt;/h2&gt;

&lt;p&gt;Swagger is a powerful solution that addresses common challenges faced by developers when working with APIs. One of its primary aims is to tackle the issue of inconsistent and hard-to-understand API documentation. With complex API structures that encompass numerous endpoints, request/response formats, and parameters, consuming APIs effectively can be a daunting task. Swagger solves this problem by providing the OpenAPI Specification (OAS) framework, which allows developers to define API contracts in a structured and consistent manner. This standardized documentation format simplifies understanding the API's capabilities, endpoints, input/output formats, and authentication requirements.&lt;/p&gt;

&lt;p&gt;Another challenge Swagger addresses is the difficulty of exploring and testing APIs. Traditional static text-based documentation often leaves developers manually constructing requests and interpreting responses. Swagger overcomes this challenge with its interactive and user-friendly interface called Swagger UI. Developers can leverage Swagger UI to explore API endpoints, test requests with different parameters, view sample responses, and even generate client SDKs. This interactive interface streamlines API interaction and ensures that developers have a clear understanding of how to effectively consume the API.&lt;/p&gt;

&lt;p&gt;Furthermore, Swagger tackles the issue of keeping API documentation in sync with the actual implementation. APIs are dynamic and undergo changes over time, including updates, bug fixes, and the introduction of new features. Maintaining accurate and up-to-date documentation can be a time-consuming and error-prone process. Swagger addresses this challenge by providing tools and integrations that generate API documentation directly from the codebase. By automatically synchronizing the documentation with the API implementation, Swagger reduces manual effort and the risk of inconsistencies. Developers can focus on writing code while having comprehensive and accurate API documentation.&lt;/p&gt;

&lt;p&gt;In summary, Swagger offers a comprehensive solution to the challenges of inconsistent and hard-to-understand API documentation, lack of an interactive exploration and testing interface, and the struggle of maintaining up-to-date documentation. With its standardized documentation framework and intuitive UI, Swagger enhances developer productivity, promotes collaboration, and improves the overall quality of APIs.&lt;/p&gt;

&lt;p&gt;Now that we have explored the benefits of Swagger for API development, let's dive into setting it up and configuring it in an Express.js application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Node, Express, and Swagger UI
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;As we discussed in the section above, Swagger UI is a powerful tool for documenting and exploring APIs, providing an interactive interface for developers to interact with their APIs in a user-friendly manner.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will walk through the process of getting started with Node.js, Express, and Swagger UI to document and test your APIs. By the end of this guide, you'll have a solid understanding of how to integrate Swagger UI into your Node.js application and generate comprehensive API documentation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we begin, make sure you have the following prerequisites installed on your system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js and npm (Node Package Manager) - Visit the official Node.js website (&lt;a href="https://nodejs.org"&gt;&lt;/a&gt;&lt;a href="https://nodejs.org"&gt;https://nodejs.org&lt;/a&gt;) and download the latest LTS (Long-Term Support) version for your operating system. Follow the installation instructions provided..&lt;/li&gt;
&lt;li&gt;A text editor or integrated development environment (IDE) of your choice. I prefer to use &lt;a id="what-is-vscode" href="https://code.visualstudio.com/"&gt;Visual Studio Code (VSCode)&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up the Node.js and Express Application
&lt;/h2&gt;

&lt;p&gt;First, let's set up a basic Node.js and Express application. Open your terminal or command prompt and follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new directory for your project:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;swagger-demo
&lt;span class="nb"&gt;cd &lt;/span&gt;swagger-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Initialize a new Node.js project and follow the prompts:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Install Express as a dependency:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a new file named &lt;code&gt;app.js&lt;/code&gt; and open it in your text editor. Add the following code to set up a basic Express server:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Swagger!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Server is running on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Start the server by running the following command in your terminal:
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;/div&gt;



&lt;p&gt;You should see the message "Server is running on port 3000" indicating that your Express server is up and running.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing and Configuring Swagger UI
&lt;/h2&gt;

&lt;p&gt;Now that we have our basic Node.js and Express application set up, let's install and configure Swagger UI.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the required packages by running the following command in your terminal:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;swagger-ui-express swagger-jsdoc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a new directory named &lt;code&gt;docs&lt;/code&gt; and inside that directory, create a file named &lt;code&gt;swagger.json&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the &lt;code&gt;swagger.json&lt;/code&gt; file in your text editor and define your API documentation using the OpenAPI Specification (OAS). Here's an example to get you started:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"openapi"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"3.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"info"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Swagger Demo API"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"API documentation for the Swagger Demo"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"paths"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"get"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"summary"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Get a greeting message"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"responses"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"200"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Successful response"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
              &lt;/span&gt;&lt;span class="nl"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"example"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Hello, Swagger!"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
              &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Open the &lt;code&gt;app.js&lt;/code&gt; file again and add the following code to integrate Swagger UI into your Express application:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;swaggerUi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;swagger-ui-express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;swaggerJsDoc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;swagger-jsdoc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;swaggerDefinition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;openapi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3.0.0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;info&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Swagger Demo API&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1.0.0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;API documentation for the Swagger Demo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;apis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;// Add the path to your main application file&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;specs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;swaggerJsDoc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/docs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;swaggerUi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;swaggerUi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;specs&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code sets up the Swagger UI endpoint at &lt;code&gt;/docs&lt;/code&gt; and serves the API documentation generated from the &lt;code&gt;swagger.json&lt;/code&gt; file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Restart your Node.js server and open your browser. Navigate to &lt;code&gt;http://localhost:3000/docs&lt;/code&gt; to access the Swagger UI interface. You should see the API documentation with the defined endpoint and response example.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Congratulations! You have successfully integrated Swagger UI into your Node.js and Express application, allowing you to generate interactive API documentation. In this tutorial, we covered the steps to set up a basic Express server, install and configure Swagger UI, and generate API documentation using the OpenAPI Specification. By leveraging Swagger UI, you can streamline API development, facilitate collaboration, and improve the overall developer experience.&lt;/p&gt;

&lt;p&gt;Remember to keep your API documentation up to date as your API evolves and make use of the powerful features offered by Swagger UI to explore and test your APIs.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on: &lt;a href="https://www.codescool.io/learning/documenting-your-node-api-with-swagger"&gt;https://www.codescool.io/learning/documenting-your-node-api-with-swagger&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>swagger</category>
      <category>openapi</category>
      <category>express</category>
    </item>
  </channel>
</rss>
