<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by divyagupta on Medium]]></title>
        <description><![CDATA[Stories by divyagupta on Medium]]></description>
        <link>https://medium.com/@divyaguptams?source=rss-b7755eaf7708------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*07x2LTPrwvarH_qmiY_Ajg.jpeg</url>
            <title>Stories by divyagupta on Medium</title>
            <link>https://medium.com/@divyaguptams?source=rss-b7755eaf7708------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 10:15:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@divyaguptams/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a component library with React, Typescript, Tailwind and Storybook — Part 4]]></title>
            <link>https://divyaguptams.medium.com/building-a-component-library-with-react-typescript-tailwind-and-storybook-part-4-f0a0d7a4b46c?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0a0d7a4b46c</guid>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Sun, 19 May 2024 12:37:30 GMT</pubDate>
            <atom:updated>2024-05-19T12:37:30.217Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a component library with React, Typescript, Tailwind and Storybook — Part 4</h3><p>Test configuration using Vitest and React-Testing-Library</p><p><strong>Vitest</strong></p><p>Vitest is the unit testing framework build on top of Vite and is an excellent unit test framework with many modern features.</p><p>To install Vitest, run the following command:</p><pre>pnpm install -D vitest @testing-library/react jsdom @testing-library/jest-dom</pre><p>Now, add the following script to the package.json file.</p><pre>&quot;scripts&quot;: {<br>  ...<br>  &quot;test&quot;: &quot;vitest run&quot;,<br>  &quot;test-watch&quot;: &quot;vitest&quot;,<br>  &quot;test:ui&quot;: &quot;vitest --ui&quot;<br>}</pre><p>Add the following line at the top of the vite.config.ts file:</p><pre>/// &lt;reference types=&quot;vitest&quot; /&gt;</pre><p>Create a file named setupTests.ts in the root directory and add the following code to that file:</p><pre>import { expect } from &quot;vitest&quot;;<br>import * as matchers from &quot;@testing-library/jest-dom/matchers&quot;;<br>import { TestingLibraryMatchers } from &quot;@testing-library/jest-dom/matchers&quot;;<br>declare module &quot;vitest&quot; {<br>  // eslint-disable-next-line @typescript-eslint/no-explicit-any<br>  interface Assertion&lt;T = any&gt;<br>    extends jest.Matchers&lt;void, T&gt;,<br>      TestingLibraryMatchers&lt;T, void&gt; {}<br>}<br>expect.extend(matchers);</pre><p>Now, add the following configuration to vite.config.ts file under defineConfig:</p><pre>test: {<br>    globals: true,//Button/__test__/Button.test.tsx<br>import React from &quot;react&quot;;<br>import { describe, expect, it } from &quot;vitest&quot;;<br>import { render, screen } from &quot;@testing-library/react&quot;;<br>import Button from &quot;../Button&quot;;<br><br>describe(&quot;Button component&quot;, () =&gt; {<br>  it(&quot;Button should render correctly&quot;, () =&gt; {<br>    render(&lt;Button /&gt;);<br>    const button = screen.getByRole(&quot;button&quot;);<br>    expect(button).toBeInTheDocument();<br>  });<br>});<br>    environment: &quot;jsdom&quot;,<br>    setupFiles: &quot;./setupTests.ts&quot;,<br>  },</pre><p>Create __test__ directory in the button folder and add a file named Button.test.tsx to test the button component with the following code:</p><pre>//Button/__test__/Button.test.tsx<br>import React from &quot;react&quot;;<br>import { describe, expect, it } from &quot;vitest&quot;;<br>import { render, screen } from &quot;@testing-library/react&quot;;<br>import Button from &quot;../Button&quot;;<br><br>describe(&quot;Button component&quot;, () =&gt; {<br>  it(&quot;Button should render correctly&quot;, () =&gt; {<br>    render(&lt;Button /&gt;);<br>    const button = screen.getByRole(&quot;button&quot;);<br>    expect(button).toBeInTheDocument();<br>  });<br>});</pre><p>Now, modify the package.json , to add testing in the commit hooks,</p><pre>&quot;lint-staged&quot;: {<br>  &quot;*.{ts,tsx}&quot;: [<br>    &quot;npm run format&quot;,<br>    &quot;npm run lint&quot;<br>  ],<br>  &quot;*.test.tsx&quot;: [<br>    &quot;npm run test&quot;<br>  ]<br>}</pre><p>Now when you try to commit all the above commands will run before a commit happens</p><pre>git commit -a</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0a0d7a4b46c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a component library with React, Typescript, Tailwind and Storybook — Part 3]]></title>
            <link>https://divyaguptams.medium.com/building-a-component-library-with-react-typescript-tailwind-and-storybook-part-3-f223f12988ab?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/f223f12988ab</guid>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Fri, 17 May 2024 10:48:42 GMT</pubDate>
            <atom:updated>2024-05-17T11:39:11.991Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a component library with React, Typescript, Tailwind and Storybook — Part 3</h3><p>Storybook and Husky configuration</p><p>For part 1, go <a href="https://divyaguptams.medium.com/building-a-component-library-with-react-typescript-tailwind-and-storybook-87c29b248a2f">here</a>.<br>For previous part, go <a href="https://divyaguptams.medium.com/building-a-component-library-with-react-typescript-tailwind-and-storybook-part-2-cab8f9978a9d">here</a>.</p><p><strong>Adding Storybook<br></strong><a href="https://storybook.js.org/">Storybook</a> is an open-source development environment for designing, testing, and showcasing UI components in isolation.</p><p>Run the following command to initialise a new storybook project:</p><pre>npx storybook@latest init</pre><p>As we already have Vite, it will be detected as a runner in Storybook, and it will also add the .storybook folder along with the required script in the package.json file.</p><p>It will generate a stories folder in the src folder, but we are going to <strong>delete</strong> it.</p><p>Each components its __docs__ own directory, and to that, we will add our stories. To do that we have to update the stories field in the .storybook/main.ts file.</p><pre>stories: [&quot;../src/**/__docs__/*.stories.tsx&quot;, &quot;../src/**/__docs__/*.mdx&quot;],</pre><p>Create three files in the src/components/button/__docs__ directory:</p><ul><li>Button.stories.tsx</li><li>Button.mdx</li></ul><p>Add the following content to the Button.mdx :</p><pre>import { Meta, Primary, Controls, Story, Title, Subtitle, Description, Stories } from &#39;@storybook/blocks&#39;;<br><br>import * as ButtonStories from &#39;./Button.stories&#39;;<br><br>&lt;Meta of={ButtonStories} /&gt;<br><br>&lt;Title /&gt;<br>&lt;Subtitle /&gt;<br>&lt;Description /&gt;<br>A button is ...<br><br>&lt;Primary /&gt;<br><br>## Props<br><br>&lt;Controls /&gt;<br><br>&lt;Stories /&gt;<br>{/* ... */}</pre><p>In the Button.stories.tsx file, insert the following code:</p><pre>import type { Meta, StoryObj } from &quot;@storybook/react&quot;;<br>import Button from &quot;../Button&quot;;<br><br><br>const meta: Meta&lt;typeof Button&gt; = {<br>    title: &quot;Button&quot;,<br>    component: Button,<br>};<br><br>export default meta;<br>type Story = StoryObj&lt;typeof Button&gt;;<br><br>export const Primary: Story = {<br>    args: {<br>        text: &quot;Button&quot;,<br>        intent: &quot;primary&quot;,<br>        disabled: false,<br>        size: &quot;small&quot;,<br>        onClick: () =&gt; console.log(&quot;Button&quot;),<br>    },<br>};<br>export const Secondary: Story = {<br>    args: {<br>        text: &quot;Button&quot;,<br>        intent: &quot;secondary&quot;,<br>        disabled: false,<br>        size: &quot;small&quot;,<br>        onClick: () =&gt; console.log(&quot;Button&quot;),<br>    },<br>};</pre><p>To view the storybook, run the following command,</p><pre>npm run storybook</pre><p>You should be able to see all the Button UI variations in Storybook.</p><p>Tailwind would not be available for storybook, to make it available for storybook, add the following line to the file .storybook/preview.ts</p><pre>import &#39;tailwindcss/tailwind.css&#39;;</pre><p>In .gitignore file in the root directory, add the directories that you don’t want to be present in the repository.</p><pre>#storybook build directory<br>storybook-static<br>*storybook.log</pre><p><strong>Husky<br></strong><a href="https://typicode.github.io/husky/">Husky</a> is primarily designed to enforce pre-commit hooks in your Git repository, ensuring that certain tasks like running tests, formatting code, and linting are performed before any commits are allowed.</p><p>To configure Husky with pre-commit hooks, run the following commands:</p><pre>pnpm install -D husky lint-staged</pre><p>Initialise git,</p><pre>git init</pre><p>Run the following commands to initialise husky</p><pre>npx husky-init<br>pnpm install<br>npx husky install</pre><p>Now, inside the .husky folder, create a file named pre-commit hook and add the following to it:</p><pre>#!/bin/sh<br>. &quot;$(dirname &quot;$0&quot;)/_/husky.sh&quot;<br><br>npx lint-staged</pre><p>Add the following configuration to the package.json file:</p><pre>&quot;lint-staged&quot;: {<br>  &quot;*.{ts,tsx}&quot;: [<br>    &quot;npm run format&quot;,<br>    &quot;npm run lint&quot;,<br>  ]<br>}</pre><p>Now, when we commit our changes using git command, Husky will automatically run lint-staged , which, in turn, will run our specified formatting and linting scripts on the staged files.</p><p>Try to commit files now, husky will automatically run the lint and format commands, if there are errors, husky will stop you from committing.</p><pre>git add .<br>git commit -a</pre><p>If you are getting warning about storybook files being ignored, when you commit, add !.storybook in ignorePatterns in the file .eslintrc.cjs</p><pre>// .eslintrc.cjs<br>ignorePatterns: [&#39;dist&#39;, &#39;.eslintrc.cjs&#39;, &#39;!.storybook&#39;],</pre><p>This will make sure that the files in storybook is not ignored. Trying to commit your code again, will not throw warnings now.</p><p>Now, husky and storybook set up is done, to continue with the next steps, go <a href="https://medium.com/p/f0a0d7a4b46c/">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f223f12988ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a component library with React, Typescript, Tailwind and Storybook — Part 2]]></title>
            <link>https://divyaguptams.medium.com/building-a-component-library-with-react-typescript-tailwind-and-storybook-part-2-cab8f9978a9d?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/cab8f9978a9d</guid>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Fri, 17 May 2024 10:31:17 GMT</pubDate>
            <atom:updated>2024-05-17T10:31:17.119Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a component library with React, Typescript, Tailwind and Storybook — Part 2</h3><p>Creating components</p><p>For initial set up (part 1), go <a href="https://divyaguptams.medium.com/building-a-component-library-with-react-typescript-tailwind-and-storybook-87c29b248a2f">here</a>,</p><p>Inside the src folder in the root directory, create a folder named components. Create a folder named button for our button components, inside the components folder. Add Button.tsx and index.ts in this folder and paste the following code:</p><pre>// components/button/Button.tsx<br>import React, { MouseEventHandler } from &quot;react&quot;;<br>import { cva } from &quot;class-variance-authority&quot;;<br>import { twMerge } from &#39;tailwind-merge&#39;<br><br><br>export type ButtonProps = {<br>    text?: string;<br>    disabled?: boolean;<br>    size?: &quot;small&quot; | &quot;medium&quot; | &quot;large&quot;;<br>    intent?: &quot;primary&quot; | &quot;secondary&quot; | &quot;default&quot;;<br>    onClick?: MouseEventHandler&lt;HTMLButtonElement&gt;;<br>};<br><br>const ButtonVariants = cva(<br>    /* button base style */<br>    &quot;h-fit text-white uppercase transition-colors duration-150&quot;,<br>    {<br>        variants: {<br>            /* button colors */<br>            intent: {<br>                primary:<br>                    &quot;bg-green-500 hover:bg-green-600&quot;,<br>                secondary:<br>                    &quot;bg-red-500 hover:bg-red-600&quot;,<br>                default:<br>                    &quot;bg-gray-500 hover:bg-gray-600&quot;,<br>            },<br>            /* button sizes */<br>            size: {<br>                small: [&quot;text-sm&quot;, &quot;py-1&quot;, &quot;px-2&quot;],<br>                medium: [&quot;text-base&quot;, &quot;py-2&quot;, &quot;px-4&quot;],<br>                large: [&quot;text-lg&quot;, &quot;py-4&quot;, &quot;px-8&quot;],<br>            },<br>        },<br><br>        // defaults<br>        defaultVariants: {<br>            intent: &quot;default&quot;,<br>            size: &quot;medium&quot;,<br>        },<br>    }<br>);<br><br><br>const Button: React.FC&lt;ButtonProps&gt; = ({<br>    size = &quot;small&quot;,<br>    disabled = false,<br>    text = &quot;Button&quot;,<br>    onClick = () =&gt; {},<br>    intent = &quot;primary&quot;,<br>    ...props<br><br>}) =&gt; {<br>    const defaultButtonStyle = `font-bold rounded-lg inline-block cursor-pointer focus:outline-none`;<br>    return (<br>      &lt;button<br>          type=&quot;button&quot;<br>          onClick={onClick}<br>          disabled={disabled}<br>          className = {twMerge(defaultButtonStyle, ButtonVariants({ intent, size }))}<br>          {...props}<br>      &gt;<br>          {text}<br>      &lt;/button&gt;<br>    );<br>};<br><br>export default Button;</pre><p>Create a file named index.ts</p><pre>// components/button/index.ts<br>export { default as Button } from &#39;./Button&#39;;</pre><p>Add an index.ts file to the components folder, as this file will allow you to export all the components from the components folder.</p><pre>// components/index.ts<br>export * from &#39;./button&#39;; // Add more exports for other components as needed</pre><p>In index.ts in the srcfolder, add the following line,</p><pre>export * from &quot;./components&quot;;</pre><p>After adding a component, run the following command. It generates a dist folder.</p><pre>npm run build</pre><p>In the dist folder, you will find the output code for your library.</p><p>The components are now created and built, to follow the next steps, go to the next page <a href="https://medium.com/p/f223f12988ab">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cab8f9978a9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a component library with React, Typescript, Tailwind and Storybook]]></title>
            <link>https://divyaguptams.medium.com/building-a-component-library-with-react-typescript-tailwind-and-storybook-87c29b248a2f?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/87c29b248a2f</guid>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Fri, 17 May 2024 09:29:48 GMT</pubDate>
            <atom:updated>2024-05-19T13:01:21.384Z</atom:updated>
            <content:encoded><![CDATA[<p>A tutorial on creating a own React component libraries to be used across your projects by sharing it with the team</p><p>The final boilerplate code is available <a href="https://github.com/DivyaGupta261/react-ui-components">here</a>. If you want to understand the steps in creating the boilerplate or do it yourself, follow the below steps.</p><p>This guide consists of following parts</p><ol><li>Project setup with Tailwind, ESLint, Prettier, Typescript and Vite configuration</li><li><a href="https://medium.com/p/cab8f9978a9d">Creating components</a></li><li><a href="https://medium.com/p/f223f12988ab">Storybook and Husky setup</a></li><li>Tests configuration</li><li>Using the component library in locally in nextjs app</li><li>Sharing the code</li><li>Additional ESLint rules</li><li>Adding material UI components</li></ol><p>The final code is in this github repository, if you want to skip creating it on your own,</p><p>We’ll be using pnpm for this project,</p><pre>pnpm create vite react-component-library --template react-ts</pre><p>This will create a project with files for the project. Now let’s navigate to the project in your terminal and run the following command to install the dependencies,</p><pre>cd react-component-library<br>pnpm install<br>pnpm run dev</pre><h3>Setting up Tailwind</h3><p>Now, let’s install Tailwind and initialise it. To install the tailwind, run the following command</p><pre>pnpm install -D tailwindcss postcss autoprefixer</pre><pre>npx tailwind init -p</pre><p>Now tailwind.config.js file would be created. Modify the file with the below content,</p><pre>/** @type {import(&#39;tailwindcss&#39;).Config} */<br>export default {<br>  content: [<br>    &quot;./index.html&quot;,<br>    &quot;./src/**/*.{js,ts,jsx,tsx}&quot;,<br>  ],<br>  theme: {<br>    extend: {},<br>  },<br>  plugins: [],<br>}</pre><p>Replace the contents of src/index.css with the below lines of code</p><pre>@tailwind base;<br>@tailwind components;<br>@tailwind utilities;</pre><p>Create a file named src/index.ts , to import the css file, add the following line,</p><pre>import &quot;./index.css&quot;;</pre><p>Let’s install two more libraries, which will help us in coding better components</p><pre>pnpm install -D tailwind-merge class-variance-authority</pre><h3>Project Setup with Typescript, ESLint and Prettier</h3><p>To add typescript, run the following command,</p><pre>pnpm install -D @types/react typescript</pre><p>Here, we need to move react to peerDependencies because it’s typically used as a peer dependency in library packages. This allows consumers to use one version of React without conflicts. To do this, add following lines to your package.json .</p><pre>&quot;peerDependencies&quot;: {<br>  &quot;react&quot;: &quot;^18.2.0&quot;,<br>  &quot;react-dom&quot;: &quot;^18.2.0&quot;,<br>  &quot;tailwindcss&quot;: &quot;^3.4.3&quot;<br>},</pre><p><a href="https://prettier.io/"><strong>Prettier</strong></a><strong><br></strong>Prettier helps you and your team to make your code look neat and tidy without you needing to do it yourself. It’s like a helpful code formatter, that fixes your messy code so it’s easier to read. It parses your code, and re-prints it by enforcing a consistent style.</p><p>To install Prettier, run the following command:</p><pre>pnpm install -D prettier</pre><p>Create .prettierrc at the root of the project and set the rules as follows:</p><pre>{<br>  &quot;printWidth&quot;: 80,<br>  &quot;tabWidth&quot;: 2<br>}</pre><p>To add more options — check documentation <a href="https://prettier.io/docs/en/options.html">here</a>.</p><p>To format the project, add the following script in package.json :</p><pre>{<br>  ...<br>  &quot;scripts&quot;: {<br>     &quot;format&quot;: &quot;prettier --write --parser typescript &#39;**/*.{ts,tsx}&#39;&quot;<br>  },<br>  ...<br>}</pre><p><a href="https://eslint.org/"><strong>ESLint</strong></a><strong><br></strong>ESLint is a code analysis tool that helps you find and fix common problems in your JavaScript code, like typos, syntax errors, style violations, and potential bugs. It’s like having a code coach that points out mistakes and suggests improvements to make your code better.</p><p>To <strong>install</strong> the ESLint with its plugin, run the following command:</p><pre>pnpm install -D eslint @typescript-eslint/parser eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-storybook @typescript-eslint/eslint-plugin</pre><p>Now, create a config file ESLint named .eslintrc at the root of the project and paste the following configuration:</p><pre>{<br>  // Specify the environments where the code will run<br>  &quot;env&quot;: {<br>    &quot;jest&quot;: true,       // Enable Jest for testing<br>    &quot;browser&quot;: true     // Enable browser environment<br>  },<br><br>  // Stop ESLint from searching for configuration in parent folders<br>  &quot;root&quot;: true,<br><br>  // Specify the parser for TypeScript (using @typescript-eslint/parser)<br>  &quot;parser&quot;: &quot;@typescript-eslint/parser&quot;, // Leverages TS ESTree to lint TypeScript<br><br>  // Add additional rules and configuration options<br>  &quot;plugins&quot;: [&quot;@typescript-eslint&quot;],<br><br>  // Extend various ESLint configurations and plugins<br>  &quot;extends&quot;: [<br>    &quot;eslint:recommended&quot;,                   // ESLint recommended rules<br>    &quot;plugin:react/recommended&quot;,             // React recommended rules<br>    &quot;plugin:@typescript-eslint/recommended&quot;, // TypeScript recommended rules<br>    &quot;plugin:@typescript-eslint/eslint-recommended&quot;, // ESLint overrides for TypeScript<br>    &quot;prettier&quot;,                             // Prettier rules<br>    &quot;plugin:prettier/recommended&quot;,          // Prettier plugin integration<br>    &quot;plugin:react-hooks/recommended&quot;,       // Recommended rules for React hooks<br>    &quot;plugin:storybook/recommended&quot;          // Recommended rules for Storybook<br>  ],<br>  &quot;rules&quot;: {<br>    &quot;react/react-in-jsx-scope&quot;: &quot;off&quot;,<br>  }<br>}</pre><p>For linting the project, add the following script in package.json :</p><pre>{<br>  ...<br>  &quot;scripts&quot;: {<br>    &quot;lint&quot;: &quot;eslint . --ext .ts,.tsx --ignore-path .gitignore --report-unused-disable-directives --max-warnings 0 --fix&quot;<br>  },<br>  ...<br>}</pre><p><strong>Typescript and Vite Configuration<br></strong>Vite is a lightning-fast build tool for web projects, designed to make the development process smoother by offering quick server startup and rapid hot module replacement.</p><p>Rollup is used under the hood to bundle your application’s code for production, optimising it for performance and reducing file size. This bundled code is then served to users when they visit your website, ensuring a faster and more efficient browsing experience.</p><p>Replace the contents of tsconfig.json with the following configuration:</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;target&quot;: &quot;ES5&quot;, // Specifies the JavaScript version to target when transpiling code.<br>    &quot;useDefineForClassFields&quot;: true, // Enables the use of &#39;define&#39; for class fields.<br>    &quot;lib&quot;: [&quot;ES2020&quot;, &quot;DOM&quot;, &quot;DOM.Iterable&quot;], // Specifies the libraries available for the code.<br>    &quot;module&quot;: &quot;ESNext&quot;, // Defines the module system to use for code generation.<br>    &quot;skipLibCheck&quot;: true, // Skips type checking of declaration files.<br><br>    /* Bundler mode */<br>    &quot;moduleResolution&quot;: &quot;bundler&quot;, // Specifies how modules are resolved when bundling.<br>    &quot;allowImportingTsExtensions&quot;: true, // Allows importing TypeScript files with extensions.<br>    &quot;resolveJsonModule&quot;: true, // Enables importing JSON modules.<br>    &quot;isolatedModules&quot;: true, // Ensures each file is treated as a separate module.<br>    &quot;noEmit&quot;: true, // Prevents TypeScript from emitting output files.<br>    &quot;jsx&quot;: &quot;react-jsx&quot;, // Configures JSX support for React.<br>    &quot;typeRoots&quot;: [&quot;./dist/index.d.ts&quot;],<br><br>    /* Linting */<br>    &quot;strict&quot;: true, // Enables strict type checking.<br>    &quot;noUnusedLocals&quot;: true, // Flags unused local variables.<br>    &quot;noUnusedParameters&quot;: true, // Flags unused function parameters.<br>    &quot;noFallthroughCasesInSwitch&quot;: true, // Requires handling all cases in a switch statement.<br>    &quot;declaration&quot;: true, // Generates declaration files for TypeScript.<br>  },<br>  &quot;include&quot;: [&quot;src&quot;], // Specifies the directory to include when searching for TypeScript files.<br>  &quot;references&quot;: [{ &quot;path&quot;: &quot;./tsconfig.node.json&quot; }],  <br>  &quot;exclude&quot;: [<br>    &quot;src/**/__docs__&quot;,&quot;src/**/__test__&quot;<br>  ]<br>}</pre><p>To install Vite with one plugin that generates a declaration file, run the following command:</p><pre>pnpm install -D vite-plugin-dts</pre><p>Modify the file named vite.config.ts in the root directory with the following configuration:</p><pre>import { defineConfig } from &quot;vite&quot;;<br>import dts from &quot;vite-plugin-dts&quot;;<br>import { peerDependencies } from &quot;./package.json&quot;;<br>import tailwindcss from &quot;tailwindcss&quot;;<br><br><br>export default defineConfig({<br>  build: {<br>    lib: {<br>      entry: &quot;./src/index.ts&quot;, // Specifies the entry point for building the library.<br>      name: &quot;vite-react-ts-button&quot;, // Sets the name of the generated library.<br>      fileName: (format) =&gt; `index.${format}.js`, // Generates the output file name based on the format.<br>      formats: [&quot;cjs&quot;, &quot;es&quot;], // Specifies the output formats (CommonJS and ES modules).<br>    },<br>    rollupOptions: {<br>      external: [...Object.keys(peerDependencies)], // Defines external dependencies for Rollup bundling.<br>      output: {<br>        globals: {<br>          react: &quot;React&quot;, // Maps &#39;react&#39; to the &#39;React&#39; global variable.<br>          &quot;react-dom&quot;: &quot;ReactDOM&quot;, // Maps &#39;react-dom&#39; to the &#39;ReactDOM&#39; global variable.<br>          tailwindcss: &quot;tailwindcss&quot;,<br>        },<br>      },<br>    },<br>    sourcemap: true, // Generates source maps for debugging.<br>    emptyOutDir: true, // Clears the output directory before building.<br>  },<br>  plugins: [dts({ rollupTypes: true })], // Uses the &#39;vite-plugin-dts&#39; plugin for generating TypeScript declaration files (d.ts).<br> css: {<br>    postcss: {<br>      plugins: [tailwindcss],<br>    },<br>  },<br>});</pre><p>Add this configuration to package.json as it defines the entry points and types definitions with the build script.</p><pre>{<br>  ...<br>  &quot;type&quot;: &quot;module&quot;,<br>  &quot;main&quot;: &quot;dist/index.cjs.js&quot;,<br>  &quot;module&quot;: &quot;dist/index.es.js&quot;,<br>  &quot;types&quot;: &quot;dist/index.d.ts&quot;,<br>  &quot;files&quot;: [<br>    &quot;/dist&quot;<br>  ],<br>}</pre><p>The initial configurations are done, to follow the next steps, go to the next page <a href="https://medium.com/p/cab8f9978a9d">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87c29b248a2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mother or a child — no in between]]></title>
            <link>https://divyaguptams.medium.com/mother-or-a-child-no-in-between-6e8b533811a7?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e8b533811a7</guid>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Wed, 15 May 2024 10:11:27 GMT</pubDate>
            <atom:updated>2024-05-15T10:11:27.582Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mother or a child — no in between</h3><p>In a world<br>where the norm is <br>to be treated like a child<br>and the expectation is <br>to behave like a mother.</p><p>To be treated as friend<br>and to be expected <br>to behave like an equal,<br>Is truly a privilege<br>a blessing,<br>that the world has offered<br>to a very few.<br>Sometimes a prize given<br>to those who fought<br>to rise up and see the <br>hypocrisy of the standards set.</p><p>The fight<br>Is it fair? No, a battlefield is never fair.<br>Is it needed?<br>Not unless the need arises from within.<br>Until then,<br>You do you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e8b533811a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Pose Detection using tensorflow in NodeJS]]></title>
            <link>https://divyaguptams.medium.com/simple-pose-detection-using-tensorflow-in-nodejs-9e69051007d8?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e69051007d8</guid>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Fri, 10 May 2024 11:22:53 GMT</pubDate>
            <atom:updated>2024-05-10T11:22:53.378Z</atom:updated>
            <content:encoded><![CDATA[<p>Simple pose estimation using tensorflow</p><p>Initialise a nodejs project,</p><pre>mkdir pose-node<br>cd pose-node<br>npm init -y</pre><p>Install the dependencies required for pose estimation</p><pre>pnpm install --save canvas<br>pnpm install --save ffmpeg<br>pnpm install --save @tensorflow/tfjs-node<br>pnpm install --save @tensorflow-models/posenet<br>pnpm install --save fs</pre><p>Create a file index.js. Here are the contents of the file for pose estimation.</p><pre>const fs = require(&#39;fs&#39;);<br>const { createCanvas, loadImage } = require(&#39;canvas&#39;);<br>const ffmpeg = require(&#39;ffmpeg&#39;);<br>const tf = require(&#39;@tensorflow/tfjs-node&#39;);<br>const posenet = require(&#39;@tensorflow-models/posenet&#39;);<br><br>// Path to your video file<br>const videoPath = &#39;video.mp4&#39;;<br><br>// Output directory for frames<br>const outputDir = &#39;frames&#39;;<br><br>// Output directory for poses<br>const posesDir = &#39;poses&#39;;<br><br>// Ensure output directory exists<br>if (!fs.existsSync(outputDir)){<br>    fs.mkdirSync(outputDir);<br>}<br><br>function drawPose(poseData, ctx, canvas) {  <br>    const colors = [&#39;red&#39;, &#39;green&#39;, &#39;blue&#39;, &#39;orange&#39;, &#39;purple&#39;, &#39;pink&#39;, &#39;yellow&#39;, &#39;aqua&#39;, &#39;lime&#39;, &#39;teal&#39;, &#39;coral&#39;, &#39;gold&#39;, &#39;indigo&#39;, &#39;violet&#39;, &#39;magenta&#39;, &#39;salmon&#39;, &#39;olive&#39;, &#39;maroon&#39;, &#39;navy&#39;, &#39;grey&#39;];  <br><br>    poseData.keypoints.forEach((keypoint, index) =&gt; {<br>        ctx.beginPath();<br>        ctx.arc(keypoint.position.x, keypoint.position.y, 5, 0, 2 * Math.PI);<br>        ctx.fillStyle = colors[index];<br>        ctx.fill();<br>        ctx.closePath();<br>    });<br><br>    // Connect keypoints with lines to form the pose<br>    ctx.beginPath();<br>    ctx.moveTo(poseData.keypoints[5].position.x, poseData.keypoints[5].position.y); // leftShoulder<br>    ctx.lineTo(poseData.keypoints[7].position.x, poseData.keypoints[7].position.y); // leftElbow<br>    ctx.lineTo(poseData.keypoints[9].position.x, poseData.keypoints[9].position.y); // leftWrist<br><br>    ctx.moveTo(poseData.keypoints[6].position.x, poseData.keypoints[6].position.y); // rightShoulder<br>    ctx.lineTo(poseData.keypoints[8].position.x, poseData.keypoints[8].position.y); // rightElbow<br>    ctx.lineTo(poseData.keypoints[10].position.x, poseData.keypoints[10].position.y); // rightWrist<br><br>    ctx.moveTo(poseData.keypoints[5].position.x, poseData.keypoints[5].position.y); // leftShoulder<br>    ctx.lineTo(poseData.keypoints[11].position.x, poseData.keypoints[11].position.y); // leftHip<br>    ctx.lineTo(poseData.keypoints[13].position.x, poseData.keypoints[13].position.y); // leftKnee<br>    ctx.lineTo(poseData.keypoints[15].position.x, poseData.keypoints[15].position.y); // leftAnkle<br><br>    ctx.moveTo(poseData.keypoints[6].position.x, poseData.keypoints[6].position.y); // rightShoulder<br>    ctx.lineTo(poseData.keypoints[12].position.x, poseData.keypoints[12].position.y); // rightHip<br>    ctx.lineTo(poseData.keypoints[14].position.x, poseData.keypoints[14].position.y); // rightKnee<br>    ctx.lineTo(poseData.keypoints[16].position.x, poseData.keypoints[16].position.y); // rightAnkle<br><br>    ctx.strokeStyle = &#39;blue&#39;;<br>    ctx.stroke();<br>    ctx.closePath();<br>    return ctx;<br>}<br><br><br>// Process frames and draw onto canvas<br>async function processFrames() {<br>    try {<br>        const net = await posenet.load({<br>            architecture: &#39;MobileNetV1&#39;,<br>            outputStride: 16,<br>            inputResolution: { width: 640, height: 480 },<br>            multiplier: 0.75<br>        });<br><br>        console.log(&#39;Processing frames&#39;, videoPath);<br>        var process = new ffmpeg(videoPath);<br>        process.then(function (video) {<br>            console.log(&#39;The video is ready to be processed&#39;);<br>            video.fnExtractFrameToJPG(outputDir, {<br>                frame_rate: 1,<br>                number: 20,<br>                file_name: &#39;my_frame_%t_%s&#39;<br>            }, function (error, frames) {<br>                if (error) {<br>                    console.log(&#39;Error: &#39; + error);<br>                    return;<br>                }<br><br>                frames.forEach(async (frame, index) =&gt; {<br>                    let img = await loadImage(frame);<br>                    <br>                    const canvas = createCanvas(img.width, img.height/2);<br>                    const ctx = canvas.getContext(&#39;2d&#39;);<br>                    console.log(`Processing frame ${index}`, img.width, img.height);<br>                    const height = img.height;<br>                    const width = img.width;<br>                    ctx.drawImage(img, 0, height/2, width, height/2, 0, 0, width, height/2);<br><br>                    const input = tf.browser.fromPixels(canvas);<br>                    const pose = await net.estimateSinglePose(input, {<br>                        flipHorizontal: false<br>                    });<br>                    drawPose(pose, ctx, canvas);<br>                    const out = fs.createWriteStream(`${posesDir}/frame_${index}.png`);<br>                    const stream = canvas.createPNGStream();<br>                    stream.pipe(out);<br>                    out.on(&#39;finish&#39;, () =&gt; console.log(`Frame ${index} processed successfully`));<br>                });<br>            });<br>        }, function (err) {<br>            console.log(&#39;Error: &#39; + err);<br>        });<br>    } catch (error) {<br>        console.error(`Error processing frames: ${error}`);<br>    }<br>}<br><br>// Start processing frames<br>processFrames();</pre><h4><strong>How to run</strong></h4><p>Run the file using the following command,</p><pre>node index.js</pre><p>The video is processed, frames are stored in frames folder. Each frame in this folder is processed and pose detection runs on it. Then, the pose is drawn on each frame and stored in poses folder as images.</p><h4><strong>Troubleshooting</strong></h4><p><strong>Error</strong>: ffmpeg command not found<br><strong>Solution</strong>: It means that ffmpeg is not installed, install it using brew to make it work,</p><pre>brew install ffmpeg</pre><p>The working is explained in detail below,</p><ol><li>Import the dependencies required for pose estimation.</li></ol><p>The code imports necessary modules such as ‘fs’ for file system operations, ‘canvas’ for creating and manipulating images, ‘ffmpeg’ for handling video files, and ‘posenet’ for pose estimation using a pre-trained model.</p><pre>const fs = require(&#39;fs&#39;);<br>const { createCanvas, loadImage } = require(&#39;canvas&#39;);<br>const ffmpeg = required(&#39;ffmpeg&#39;);<br>const tf = require(&#39;@tensorflow/tfjs-node&#39;);<br>const posenet = require(&#39;@tensorflow-models/posenet&#39;);</pre><p>2. Constants</p><ul><li>videoPath: Path to the input video file.</li><li>outputDir: Directory where extracted frames will be saved.</li><li>posesDir: Directory where images with drawn poses will be saved.</li><li>colors: Array of colors used for drawing keypoints on the canvas.</li></ul><p>3. Helper function</p><ul><li>drawPose: Draws the estimated pose keypoints and connects them with lines to visualize the pose on the canvas.</li></ul><p>4. Main function — processFrames :</p><p>Loads the PoseNet model with specified configuration.</p><pre>const net = await posenet.load({<br>      architecture: &#39;MobileNetV1&#39;,<br>      outputStride: 16,<br>      inputResolution: { width: 640, height: 480 },<br>      multiplier: 0.75<br>  });</pre><p>Initializes ffmpeg to extract frames from the video.</p><pre>var process = new ffmpeg(videoPath);</pre><p>For each extracted frame, loads the frame image using loadImage.</p><pre>process.then(function (video) {<br>    console.log(&#39;The video is ready to be processed&#39;);<br>    video.fnExtractFrameToJPG(outputDir, {<br>        frame_rate: 1,<br>        number: 20,<br>        file_name: &#39;my_frame_%t_%s&#39;<br>    }, function (error, frames) {<br>        if (error) {<br>            console.log(&#39;Error: &#39; + error);<br>            return;<br>        }<br>        frames.forEach(async (frame, index) =&gt; {<br>          ...<br>        })<br>        ...<br>   })<br>})</pre><p>Creates a canvas and context to draw the pose onto.</p><pre>let img = await loadImage(frame);<br>const canvas = createCanvas(img.width, img.height/2);<br>const ctx = canvas.getContext(&#39;2d&#39;);<br>console.log(`Processing frame ${index}`, img.width, img.height);<br>const height = img.height;<br>const width = img.width;<br>ctx.drawImage(img, 0, height/2, width, height/2, 0, 0, width, height/2);</pre><p><strong>Processes the frame:</strong></p><p>Converts the image to a TensorFlow tensor using tf.browser.fromPixels.<br>Estimates the pose using PoseNet’s estimateSinglePose function.</p><pre>const input = tf.browser.fromPixels(canvas);<br>const pose = await net.estimateSinglePose(input, {<br>    flipHorizontal: false<br>});</pre><p>Draws the estimated pose on the canvas using drawPose.</p><pre>drawPose(pose, ctx, canvas);</pre><p>Writes the canvas content to a PNG file.</p><pre>const out = fs.createWriteStream(`images/frame_${index}.png`);<br>const stream = canvas.createPNGStream();<br>stream.pipe(out);<br>out.on(&#39;finish&#39;, () =&gt; console.log(`Frame ${index} processed successfully`));</pre><p>5. Execution</p><p>Calls processFrames to start the processing of frames,</p><pre>processFrames();</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e69051007d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Touch]]></title>
            <link>https://divyaguptams.medium.com/touch-15949b13a4da?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/15949b13a4da</guid>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Thu, 29 Feb 2024 11:08:37 GMT</pubDate>
            <atom:updated>2024-02-29T11:08:37.854Z</atom:updated>
            <content:encoded><![CDATA[<p>Butterflies visit with a happy hello,<br>bewildered by their own glow,<br>every time your limbs rub mine</p><p>Fingers intertwined,<br>locked in love,<br>letting every thing bloom,<br>Never knew I would feel<br>flower beds inside my palm, one day.<br>Trust me, they looked so beautiful,<br>I did not need to see, to know.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BxFX2PnLMez5z6uf" /><figcaption>Photo by <a href="https://unsplash.com/@huuduong?utm_source=medium&amp;utm_medium=referral">Dương Hữu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Every night,<br>the waves of your breath,<br>loud and calming,<br>Like a dreamy night on the beach.<br>Your hands drag mine,<br>I almost feel elevated towards the moon</p><p>The butterflies that tickle me,<br>The flowers that soothe me,<br>The waves that guide me,<br>The moon that shines on me,<br>You created them,<br>for the blissful owner, that I am.</p><p>Your touch, I really love,<br>honestly, those are<br>the moments that I live, and<br>the moments that I live for,<br>I long for.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15949b13a4da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The journey of life]]></title>
            <link>https://divyaguptams.medium.com/life-45fab5bc1b6?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/45fab5bc1b6</guid>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Mon, 05 Feb 2024 04:37:19 GMT</pubDate>
            <atom:updated>2024-05-15T10:56:48.627Z</atom:updated>
            <content:encoded><![CDATA[<p>My eyes were set on the destination,<br>And so, soon I reached.<br>Only to be shocked to see<br>An empty ground.</p><figure><img alt="illustration of the end" src="https://cdn-images-1.medium.com/max/1024/1*u9ZIyJXHtwByn5WjF83ZTw.png" /></figure><p>But where is the reward, I asked<br>It was placed all along the way <br>Came the response</p><p>The realisation hit hard.</p><p>The emptiness was merely<br>An entrance to another journey.</p><p>This next path, I promise myself,<br>To take gulps of joy,<br>Along the way,<br>With heart, mind and soul.</p><p>The thrill of<br>many more joyful journeys<br>And confusing destinations,<br>In the ride,<br>fondly called as Life.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45fab5bc1b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Punk Family Photo Booth]]></title>
            <link>https://divyaguptams.medium.com/punk-family-photo-booth-7ef07bb317cb?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ef07bb317cb</guid>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[cryptopunks]]></category>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Sat, 26 Jun 2021 19:17:56 GMT</pubDate>
            <atom:updated>2021-07-06T11:02:55.848Z</atom:updated>
            <content:encoded><![CDATA[<p>For the NFT family</p><p>NFTs are booming and it is such a blessing for people who are love creating art.</p><blockquote><a href="https://larvalabs.com/">Larva labs</a> had created a collection called <a href="https://www.larvalabs.com/cryptopunks">Crypto Punks</a>, which was an inspiration for <strong>ERC-721 standard for NFTs</strong>. And there has been no looking back for NFT, since then. Many artists have jumped in and minted amazing art works, keeping the NFT and art enthusiasts busy.</blockquote><p>Few months later, another amazing creative project called <a href="https://punks.baby/">Punks baby</a> was released, as <strong>illegitimate offspring of OG Punks</strong>. I found it funny and interesting. It interested a lot of people because of its attention to detail and rarity of some traits.</p><p><a href="https://punks.baby/">Home - PunkBabies</a></p><p>As people started owning crypto punks, we felt it might be interesting/funny for folks who own those babies to get their family portrait. So, as a weekend project, we built this tool, for family polaroids. Check it out, <a href="https://punkfamily.photos/">here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FviGBHcK82oA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DviGBHcK82oA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FviGBHcK82oA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/06dcbe0b8dbc670012536493a9797d34/href">https://medium.com/media/06dcbe0b8dbc670012536493a9797d34/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*-lgs2Oym3HmxCVywVkwe5w.png" /></figure><p><a href="https://punkfamily.photos/">https://punkfamily.photos</a></p><p>People have been loving it. So far, 500+ polaroids have been taken.</p><h3>How it was built</h3><p><a href="https://moralis.io/">Moralis</a> has SDK to build serverless web3 dapps. It can be used to connect to <a href="https://metamask.io/">Metamask</a> and get the list of all NFTs owned by the user. If the user owns the baby, API request is sent to generate the polaroid.</p><p>Opensea has good set of APIs for getting the details of baby punk. This API returns all traits of the baby punk like the ID of father and mother as well. Openseas APIs is again used to get the portrait of Father and Mother.</p><p>Then, javascript canvas is used to generate the polaroid and return it to the frontend app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vEZTGMTaRH7xr_4KO6LShg.png" /></figure><h4>Opensea links:</h4><blockquote><em>CryptoPunk: </em><a href="https://opensea.io/collection/cryptopunks">https://opensea.io/collection/cryptopunks</a></blockquote><blockquote><em>Baby Punks</em>: <a href="https://opensea.io/collection/punkbabies">https://opensea.io/collection/punkbabies</a></blockquote><p>Hope you enjoyed the app and this blog and hope it inspires other developers to execute their ideas.</p><p><a href="https://youtube.com/shorts/fUHBySnTnoM?feature=share">Working together</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ef07bb317cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSH Basics — in comic]]></title>
            <link>https://divyaguptams.medium.com/ssh-basics-in-comic-c5675a73b25a?source=rss-b7755eaf7708------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5675a73b25a</guid>
            <category><![CDATA[sockets]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[secure]]></category>
            <category><![CDATA[shell]]></category>
            <dc:creator><![CDATA[divyagupta]]></dc:creator>
            <pubDate>Mon, 23 Dec 2019 14:56:00 GMT</pubDate>
            <atom:updated>2019-12-23T14:56:00.393Z</atom:updated>
            <content:encoded><![CDATA[<h3>SSH Basics — in comic</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Erb36J5CVznnkQ2Q59PM-g.jpeg" /><figcaption>Notes for SSH</figcaption></figure><p>The SSH protocol (also referred to as Secure Shell) is a method for secure remote login from one computer to another.</p><h4>Creating Keys</h4><p>Creating SSH keys generated two sets of keys — <strong>my_key and my_key.pub. </strong>The key with .pub extension is the public key which can be shared to the outer world. The other file is a private key which should not be shared.</p><pre>$ ssh_keygen -t rsa</pre><p>There are many algorithms that the SSH employs to generate keys, rsa is one those. We can choose any algorithms from a set of available algorithms like rsa, dsa, dh etc.</p><p><strong>Adding your Public Key</strong></p><p>Add your public in your server by logging in your server and typing the following command.</p><pre>$ ssh -i my_key root@$IP_ADDR</pre><p>This IP Address is added to the file called known_hosts.</p><p><strong>Adding hosts</strong></p><p>Now, we need to create users in the server and block root access. Add your local machine as a user to your server, by using the following command,</p><pre>$ adduser $USER_NAME</pre><p>Give the user, sudo access in order to avoid entering the password every time you access your server from the machine</p><pre>$ usermod -aG sudo $USER_NAME</pre><p>Add ssh key to the new user,</p><pre>$ cat my_key.pub | ssh $USER_NAME @IP_ADDR &quot;mkdir -p ~/.ssh &amp;&amp; cat &gt;&gt; ~/.ssh/authorized_key&quot;</pre><p>The above command adds my_key.pub to the user, by adding this public key to the authorised keys of the server. The local machine needs to contain the private key to access the server.</p><p>Now, the root access of the server needs to be blocked, as it is never safe to have the root of the server accessible to the world. In order to do that, use the following commands</p><pre>$ sudo vi/etc/ssh/sshd_config</pre><p>Change the PermitRootLogin to No and restart the server to apply these settings,</p><pre>$ sudo service ssh restart</pre><p>Welcome to your SECURE SERVER!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5675a73b25a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>