<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: balankdharan</title>
    <description>The latest articles on DEV Community by balankdharan (@dharan).</description>
    <link>https://dev.to/dharan</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%2F1161782%2F6d66fcdc-d3d3-411b-8877-74e320eb7904.jpeg</url>
      <title>DEV Community: balankdharan</title>
      <link>https://dev.to/dharan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dharan"/>
    <language>en</language>
    <item>
      <title>Adding reCAPTCHA in MERN Application</title>
      <dc:creator>balankdharan</dc:creator>
      <pubDate>Wed, 01 Nov 2023 03:50:00 +0000</pubDate>
      <link>https://dev.to/dharan/adding-recaptcha-in-mern-application-1kon</link>
      <guid>https://dev.to/dharan/adding-recaptcha-in-mern-application-1kon</guid>
      <description>&lt;p&gt;Adding reCAPTCHA to your MERN website involves several steps. reCAPTCHA is a Google service used to protect your website from spam and abuse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get reCAPTCHA API Keys:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the reCAPTCHA website and sign in with your Google account.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9Fl3Pqml--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lf46x3dvvwqg2opswovg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9Fl3Pqml--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lf46x3dvvwqg2opswovg.png" alt="example" width="800" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a new site by clicking on “Admin Console” and then “Create a site”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose the “reCAPTCHA v2” type (I’m assuming you want the checkbox “I’m not a robot” version) and select “I’m not a robot” Checkbox.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Add your domain(s) to the list of allowed domains. This is important for security.&lt;/p&gt;

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

&lt;p&gt;note: you can also add localhost here&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Accept the reCAPTCHA Terms of Service and click “Submit”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After creating the site, you’ll get a Site Key and a Secret Key. You will use the Site Key on the client-side and secret key on the backend.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--COyJYmMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wqbtgxbyanhlwvoodd4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--COyJYmMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wqbtgxbyanhlwvoodd4q.png" alt="example pic" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Integrate reCAPTCHA in your React application:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your HTML &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;, include the reCAPTCHA script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://www.google.com/recaptcha/api.js" async defer&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the &lt;code&gt;react-google-recaptcha&lt;/code&gt; package to use the widget:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;In your React component where you have your form, add the reCAPTCHA widget using the &lt;code&gt;react-google-recaptcha&lt;/code&gt; library or by manually rendering the widget.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ReCAPTCHA from "react-google-recaptcha";

function MyFormComponent() {
  const onRecaptchaChange = (value) =&amp;gt; {
    console.log(value)
    if(value){
       // send to backend for validation
    }
  };

  return (
    &amp;lt;form&amp;gt;
      // Your form fields
      &amp;lt;ReCAPTCHA
        sitekey="YOUR_SITE_KEY"
        onChange={onRecaptchaChange}
      /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When captcha check is correct you will receive the token in the onRecaptchaChange function, Value will be null if the user hasn’t solved the reCAPTCHA, then send the backend for more security.&lt;br&gt;
It is better to add backend validation too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verify reCAPTCHA Token on the Server:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your server, you should verify the reCAPTCHA response sent from the client. You can use the &lt;code&gt;axios&lt;/code&gt; library to send a POST request to Google's reCAPTCHA verification endpoint.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First, install &lt;code&gt;axios&lt;/code&gt;if you haven't already:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Then, in your server route:&lt;br&gt;
&lt;/p&gt;

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

async function verifyRecaptcha(recaptchaResponse) {
  try {
    const response = await axios.post(
      "https://www.google.com/recaptcha/api/siteverify",
      null,
      {
        params: {
          secret: "YOUR_SECRET_KEY",
          response: recaptchaResponse,
        },
      }
    );

    return response.data.success;
  } catch (error) {
    console.error("Error verifying reCAPTCHA:", error);
    return false;
  }
}

app.post('/submit', async (req, res) =&amp;gt; {
  const { recaptchaToken } = req.body; 

  try {
    const isRecaptchaValid = await verifyRecaptcha(recaptchaToken);

  if (!isRecaptchaValid) {
    return res.status(400).json({ error: "reCAPTCHA verification failed" });
  }else{
    //Add your success response here
}
  } catch (error) {
    console.log(error)
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In conclusion, integrating reCAPTCHA into your MERN website is a crucial step to enhance security and protect your forms from spam and abuse. The process involves adding reCAPTCHA to both the client-side (React) and server-side (Node.js/Express) of your application. On the client-side, you obtain reCAPTCHA API keys, integrate the reCAPTCHA widget into your React forms using a library like &lt;code&gt;react-google-recaptcha&lt;/code&gt;, and handle the user's response. On the server-side, you verify the reCAPTCHA token sent from the client by making a POST request to Google's reCAPTCHA verification endpoint using the &lt;code&gt;axios&lt;/code&gt; library, and based on the verification result, you decide whether to process the form data or show an error message. By following these steps, you can significantly enhance the security of your MERN application and protect it from unwanted spam and abuse.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>mern</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Bun- All in one JavaScript runtime</title>
      <dc:creator>balankdharan</dc:creator>
      <pubDate>Fri, 15 Sep 2023 06:05:01 +0000</pubDate>
      <link>https://dev.to/dharan/bun-all-in-one-javascript-runtime-467e</link>
      <guid>https://dev.to/dharan/bun-all-in-one-javascript-runtime-467e</guid>
      <description>&lt;p&gt;Bun is a JavaScript runtime that is designed to be a drop-in replacement for Node.js. It is written in Zig and powered by JavaScript Core, which is the JavaScript engine used by Apple's Safari web browser.&lt;/p&gt;

&lt;p&gt;Bun claims to be faster than Node.js, and it also has a smaller memory footprint. It also has a built-in bundler, test runner, and package manager, which makes it a more complete development toolkit than Node.js.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are some of the key features of Bun:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fast:&lt;/strong&gt; Bun is designed to be fast and efficient. It uses a variety of techniques to improve performance, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using a lightweight runtime&lt;/li&gt;
&lt;li&gt;Compiling JavaScript to native code&lt;/li&gt;
&lt;li&gt;Using a minimal set of APIs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lightweight:&lt;/strong&gt; Bun has a small memory footprint. This makes it ideal for running on devices with limited resources, such as IoT devices and mobile phones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complete toolkit:&lt;/strong&gt; Bun includes a built-in bundler, test runner, and package manager. This makes it a complete development toolkit for JavaScript applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extensible:&lt;/strong&gt; Bun is extensible. You can write your own plugins and extensions to add new features or improve performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are some of the use cases of Bun:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building web applications&lt;/li&gt;
&lt;li&gt;Building serverless applications&lt;/li&gt;
&lt;li&gt;Running microservices&lt;/li&gt;
&lt;li&gt;Developing IoT applications&lt;/li&gt;
&lt;li&gt;Developing mobile applications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Installing Bun :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is supported for &lt;code&gt;macOS, Linux, and WSL&lt;/code&gt;&lt;br&gt;
Bun provides a limited, experimental native build for Windows. At the moment, only the Bun runtime is supported.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To install it on Windows You need some requirements:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to install WSL (Windows Subsystem for Linux) and ubuntu from windows store.(You can use any other method to install)&lt;/p&gt;

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

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

&lt;p&gt;After that you need to go to the windows feature,&lt;/p&gt;

&lt;p&gt;Simply enter Turn windows feature on or off in your search bar and check the box Windows Subsystem for Linux if not checked, And restart you computer&lt;/p&gt;

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

&lt;p&gt;After that go to your visual studio code and install the WSL extension&lt;/p&gt;

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

&lt;p&gt;So the last step is to use the launch the ubuntu terminal in VSC&lt;br&gt;
(you can use any directory )&lt;/p&gt;

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

&lt;p&gt;Enter the following commands to install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install unzip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -fsSL https://bun.sh/install | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right now you should have installed the bun in your windows, To access the bun you need to set the source path ,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source /root/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;To install it on Linux or macOS :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Linux users - The &lt;code&gt;unzip&lt;/code&gt; package is required to install Bun. Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install unzip // linux-users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -fsSL https://bun.sh/install | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Some code examples:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const server = Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Bun!");
  },
});

console.log(`Listening on http://localhost:${server.port} ...`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bun index.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can write your script to start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "example",
  "module": "index.ts",
  "type": "module",
  "scripts": {
    "start": "bun run index.ts"
  },
  "devDependencies": {
    "bun-types": "^0.7.0"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bun run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bun is a new runtime, so it is not yet as widely used as Node.js. However, it is gaining popularity due to its performance and features. If you are looking for a fast and lightweight JavaScript runtime, Bun is a good option to consider.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are some of the advantages of using Bun:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Faster performance:&lt;/strong&gt; Bun is designed to be faster than Node.js. This is because it uses a lightweight runtime and compiles JavaScript to native code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smaller memory footprint:&lt;/strong&gt; Bun has a smaller memory footprint than Node.js. This makes it ideal for running on devices with limited resources, such as IoT devices and mobile phones.
-** Complete toolkit:** Bun includes a built-in bundler, test runner, and package manager. This makes it a complete development toolkit for JavaScript applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extensible:&lt;/strong&gt; Bun is extensible. You can write your own plugins and extensions to add new features or improve performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Here are some of the disadvantages of using Bun:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Not as widely used as Node.js&lt;/strong&gt;: Bun is a new runtime, so it is not yet as widely used as Node.js. This means that there may be fewer resources available for learning and using Bun.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Less mature:&lt;/strong&gt; Bun is still under development, so it may not be as mature as Node.js. This means that there may be bugs or missing features.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, Bun is a promising new JavaScript runtime that offers a number of advantages over Node.js. However, it is important to weigh the advantages and disadvantages before deciding whether to use Bun for your project.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>bunjs</category>
      <category>javascript</category>
      <category>code</category>
    </item>
  </channel>
</rss>
