<?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: Benjamin Nwokolo</title>
    <description>The latest articles on DEV Community by Benjamin Nwokolo (@benjaminnwokolo).</description>
    <link>https://dev.to/benjaminnwokolo</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%2F920994%2F007d2563-82e1-41a3-b476-281d9442d0b9.png</url>
      <title>DEV Community: Benjamin Nwokolo</title>
      <link>https://dev.to/benjaminnwokolo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/benjaminnwokolo"/>
    <language>en</language>
    <item>
      <title>Environment Variables in Node.js</title>
      <dc:creator>Benjamin Nwokolo</dc:creator>
      <pubDate>Thu, 03 Nov 2022 07:31:10 +0000</pubDate>
      <link>https://dev.to/benjaminnwokolo/environment-variables-in-nodejs-40a5</link>
      <guid>https://dev.to/benjaminnwokolo/environment-variables-in-nodejs-40a5</guid>
      <description>&lt;p&gt;Environment Variables are very useful and helpful in the configuration of applications , in This Article We are going to discussing about Environment Variables and How to work with Environment Variables in  Node.js Applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Introduction to Environment Variables / What are Environment Variables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Importance and Use cases of environment variables &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Getting started with Environment Variables in Node.js&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uses of Environment Variables in Node.js&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Working With Environment Variables in Node.js&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security Practices in an .env file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How To Access environment variables stored in a .env file within a Node.js Application.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Introduction to Environment Variables / What are Environment Variables.
&lt;/h3&gt;

&lt;p&gt;Environment Variables helps in the configuration of applications in different environment in which an application is running on,  be it a Production , Development or a Testing environment.&lt;br&gt;
  Environment Variables are Variables set by the operating system which helps to create the environment that a computer program runs on , one of the commonly used environment variable is the PATH Environment Variable . As A Developer when building applications you should never store and write sensitive information such as API Keys ,HOSTS, Database Credentials , Database  id and Passwords in Your Code which would be pushed to public, with the help of environment variables such sensitive information can be hidden and be protected to avoid any security breach .&lt;/p&gt;
&lt;h3&gt;
  
  
  Importance and Use cases of environment variables
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Environment Variables are useful when separating Programming and configuration settings of an application ,which makes it easier in Deploying an application to different environments. for instance the Database configuration settings of an Application in Development would be different from the settings in Production , and this configuration settings can be stored as environment variables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Environment Variables Helps in the protection and security of configuration  settings  for example API Keys and Passwords should not be hardcoded in an application in production instead it should added as an environment Variable .&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Getting started with Environment Variables in Node.js
&lt;/h3&gt;

&lt;p&gt;Environment Variables can be used in the configuration of Node.js Applications , We can store sensitive information such as passwords and Credentials as environment variables in Node.js .&lt;/p&gt;
&lt;h3&gt;
  
  
  Uses of Environment Variables in Node.js
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Environment Variables are used in Hiding and Protecting API Keys and Passwords.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Environment Variables are used in setting the PORT of Node applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Environment Variables are used in configuring Database Settings.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Working With Environment Variables in Node.js
&lt;/h3&gt;

&lt;p&gt;Environment Variables in Node are accessed using the &lt;code&gt;process&lt;/code&gt; object , which is a Global object that is injected during runtime which represents a node process , one of the major property is the &lt;code&gt;env&lt;/code&gt; propety ,an &lt;code&gt;env&lt;/code&gt; property provides access to all existing environment variables in a Node.js application&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
//process object
process.env

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;process.env&lt;/code&gt; is a global object in Node.js from which we can access all the environment variables in the environment in which an application is running on , this object returns properties which contains the user environment and form the object we have access to the &lt;code&gt;PATH&lt;/code&gt;and &lt;code&gt;PORT&lt;/code&gt;amongst other properties .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(process.env);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When it is been logged to the console we  would have access to the various properties of the &lt;code&gt;process.env&lt;/code&gt; object. the Most Efficient Way to provide environment variables in Node.js is through an &lt;code&gt;.env&lt;/code&gt;file&lt;/p&gt;

&lt;h3&gt;
  
  
  Using the .env file
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;.env&lt;/code&gt; file is a text file which contains a set of key value pairs of environment variables , we can place the value of an application passwords , API Keys and Database Credentials which we want to keep private in an .env file. .env file generally lets us store values in it , values in which we do not want to embedded / placed inside code which can be accessed or seen by the public.&lt;/p&gt;

&lt;p&gt;So lets create a &lt;code&gt;.env&lt;/code&gt; file  in our application 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%2Fqcfhtko58108ihqi9t7p.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%2Fqcfhtko58108ihqi9t7p.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;now lets store an example of  configuration settings, API keys Database Passwords and Credentials inside this .env file  we created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_USERNAME = Benjamin
DB_PASSWORD = Ben102722
API_KEY = DHDJHWRR66
API_PASSWORD = SHD2YWO21093J2Q92Q03
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We Have now stored environment variables (in the form of key value pairs )inside the .env file which we can access later on  in our application .&lt;/p&gt;

&lt;h3&gt;
  
  
  Security Practices in an .env file
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;.env&lt;/code&gt; files should be made private and should not be shared with anyone and also should not be made accessible to the public  because it contains sensitive informations such as Database Credentials ,API Keys e.t.c  &lt;code&gt;. env&lt;/code&gt; files should not be visible in the source code when uploading codes to version control services such as Github.&lt;br&gt;
    To Be able to prevent and exclude .env files From being pushed to Github and been made accessible to the public&lt;br&gt;
, we create a &lt;code&gt;.gitignore&lt;/code&gt; file in the application codebase and exclude the &lt;code&gt;.env&lt;/code&gt;file from being pushed to github , and it is done by typing .env inside the &lt;code&gt;.gitignore&lt;/code&gt; file , so that git would ignore the file when it is been pushed&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%2F3epaih96tv8b8fvexvkw.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%2F3epaih96tv8b8fvexvkw.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  How To Access environment variables stored in a .env file within a Node.js Application.
&lt;/h3&gt;

&lt;p&gt;To make use of the environment variables stored in the .env file , we make use of 3rd Party NPM Package to access the variables and the package is called &lt;code&gt;dotenv&lt;/code&gt; .&lt;br&gt;
     &lt;a href="https://www.npmjs.com/package/dotenv" rel="noopener noreferrer"&gt;Dotenv&lt;/a&gt; is a zero-dependency module that loads environment variables from a .env file into process.env.&lt;br&gt;
dotenv is a npm package that loads environment variables and helps read .env files.&lt;br&gt;
       To install  dotenv , Head over to the command line terminal and execute this command in the directory which contains the application to be able to install it :&lt;br&gt;
&lt;code&gt;npm install dotenv --save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After successfully installing it , to be able to access the environment variables stored in the .env file, head over to file in the which you will making use of the variable in and require dotenv &lt;code&gt;require('dotenv').config();&lt;/code&gt; with this, we can now proceed to access all the  environment variables in which we stored in the .env file above. So lets access the &lt;code&gt;DB_PASSWORD&lt;/code&gt; stored in the .env file as an a example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express')
const path = require ('path');
require('dotenv').config();

//accessing the DB_PASSWORD from the .env File
console.log(process.env.DB_PASSWORD);

const app = express();
app.listen(process.env.PORT || 3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when the code is executed we get the exact value of the &lt;code&gt;DB_PASSWORD&lt;/code&gt; as it was stored in the .env file .&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%2F7uwm8cxbpv6bptzjuwrq.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%2F7uwm8cxbpv6bptzjuwrq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;This Article has explained and shown the Basics and the use cases of environment variables  and the .env file in a Node.js Application . I Hope You Found this article Helpful ! &lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>security</category>
    </item>
    <item>
      <title>Sending an Email With React Without a Backend Server</title>
      <dc:creator>Benjamin Nwokolo</dc:creator>
      <pubDate>Sun, 02 Oct 2022 01:34:52 +0000</pubDate>
      <link>https://dev.to/benjaminnwokolo/sending-an-email-with-react-without-a-backend-server-32gc</link>
      <guid>https://dev.to/benjaminnwokolo/sending-an-email-with-react-without-a-backend-server-32gc</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;In This  Tutorial we are going to learn how to send an email in a  React Application  Without making use of a backend Language Like PHP , Python , Golang and The Rest of Backend Languages.&lt;br&gt;
For us to be able to send an email in react without a Backend we will be making use of Third party Service Called &lt;a href="https://www.emailjs.com/" rel="noopener noreferrer"&gt;EmailJS&lt;/a&gt; . EmailJS is a service from which we can send Emails Directly From Javascript Without a server Code. &lt;a href="https://www.emailjs.com/" rel="noopener noreferrer"&gt;EmailJS&lt;/a&gt;  makes  it easily to send an email with javascript and its  frameworks&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisities
&lt;/h2&gt;

&lt;p&gt;-Basic Knowledge Of React &lt;/p&gt;

&lt;p&gt;-An Email JS  Account&lt;/p&gt;

&lt;p&gt;-An Email Account &lt;/p&gt;
&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;p&gt;So, To be able to make use of EmailJS in our React App we create a free account on emailjs.com &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%2Fdp2n8lrr4dvd91oi5dmj.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%2Fdp2n8lrr4dvd91oi5dmj.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After Signing up , Verify your Email and Then Proceed to Login into your emailjs account .&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;p&gt;We have to also add an email service  provider on EmailJS from which emails will be sent  from , To create a new service  ,  Click On Email services on Your EmailJS Dashboard ,Click on &lt;br&gt;
&lt;code&gt;Add New Service&lt;/code&gt; and choose an email service provider of your choice &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%2F1hlbu81t5jb5k9vlsdnc.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%2F1hlbu81t5jb5k9vlsdnc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the sake of  this tutorial , we’ll  be making use of Gmail as a service provider , So after Selecting the email service of your choice , You Proceed to Connect it with your Gmail Account , To Do That click on &lt;code&gt;"Connect Account"&lt;/code&gt; as displayed on the screen .&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%2Fuxchdvumhej5qjdx2pif.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%2Fuxchdvumhej5qjdx2pif.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After Connecting Your Account Click on  &lt;code&gt;"Create Service"&lt;/code&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%2F51y26vc66wci0pjv0ov1.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%2F51y26vc66wci0pjv0ov1.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;Template Creation , to be  able to send emails we are to create a Template for our emails ,  and to do that we ,Click on &lt;code&gt;"Email Templates"&lt;/code&gt;in  Other to Create an Email template &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%2Fqqykc7pzy9dq8r1wb4vx.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%2Fqqykc7pzy9dq8r1wb4vx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then , Click on &lt;code&gt;“Create New Template”&lt;/code&gt;  and You are Directed to this page which is the default template :&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%2Fa40ikoine1p2g1nx91pj.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%2Fa40ikoine1p2g1nx91pj.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Variables on The Template&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;from_name&lt;/strong&gt; : it Refers to Sender of the email.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;to_name&lt;/strong&gt; : This Refers to the Receiver of the email. in this case it means the person to whom you are sending the mail to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;message&lt;/strong&gt; : it is the main content of your email.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;to_email&lt;/strong&gt; : Refers to email address which the email message is been sent to that is the receivers email  address &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an Edited template :&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%2Fim1emo5khgor7q4xydip.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%2Fim1emo5khgor7q4xydip.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So After editing your template click on &lt;code&gt;“save”&lt;/code&gt; in other to save your Template. So we are ready to use this template in our React app.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;p&gt;We are Going to Create a Contact Form in React to enable us send an email using template in EmailJS. So Head Over to Your Code Editor and Create a form in react , Here is my code for a  Basic contact form :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useRef } from "react";

const Email = () =&amp;gt; {

    const form = useRef();

return (
    &amp;lt;div class="form"&amp;gt;
          &amp;lt;div class="title"&amp;gt;Contact Us&amp;lt;/div&amp;gt;
     &amp;lt;form  ref={form} &amp;gt;

        &amp;lt;div class="input-container ic1"&amp;gt;
          &amp;lt;input id="firstname" className="input" type="text" placeholder="Username "  name="to_name"/&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="input-container ic2"&amp;gt;
          &amp;lt;input id="email" className="input" type="text" placeholder="Email Address  "  name="from_name"/&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="input-container ic2"&amp;gt;
         &amp;lt;textarea  required placeholder="Message"  name="message"&amp;gt;&amp;lt;/textarea&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;button type="text" className="submit"&amp;gt;Submit Message&amp;lt;/button&amp;gt;
     &amp;lt;/form&amp;gt;
 &amp;lt;/div&amp;gt;
   );
}

export default Email;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And Here is The CSS Style For This Particular Contact Form , But You can Create your own unique CSS style When Creating Yours .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*{
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  align-items: center;

  display: flex;
  justify-content: center;
  height: 100vh;
}

.form {
  background-color: black;
  border-radius: 20px;
  box-sizing: border-box;
  height: 600px;
  padding: 20px;
  width: 400px;
}

.title {
  color: #eee;
 margin-left: 60px;
  font-size: 40px;
  font-weight: 600;
  margin-top: 30px;
}


.input-container {
  height: 50px;
  position: relative;
  width: 100%;
}

.ic1 {
  margin-top: 40px;
}

.ic2 {
  margin-top: 30px;
}

.input {
  background-color:white;
  border-radius: 12px;
  border: 0;
  box-sizing: border-box;
  color: black;
  font-size: 18px;
  height: 100%;
  outline: 0;
  padding: 4px 20px 0;
  width: 100%;
}
textarea{
  background-color:white;
  border-radius: 12px;
  border: 0;
  box-sizing: border-box;
  color: black;
  font-size: 18px;
  height: 120px;
  outline: 0;

  width: 100%;
  padding-bottom: 30px;
}

 form label{
     color: white;
     background-color: white;
}

.submit {
  background-color: #08d;
  border-radius: 12px;
  border: 0;
  box-sizing: border-box;
  color: #eee;
  cursor: pointer;
  font-size: 18px;
  height: 50px;
  margin-top: 100px;
 outline: 0;
  text-align: center;
  width: 100%;
}

.submit:active {
  background-color: #06b;
}
textarea::placeholder{
  padding: 30px;
  font-size: 20px;

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

&lt;/div&gt;



&lt;p&gt;Here is the  Form Displayed in The Browser:&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%2F7avrng8cow5k8h2uq6z4.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%2F7avrng8cow5k8h2uq6z4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So now, We are to add functionality to this form to enable us send emails using react .&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5
&lt;/h3&gt;

&lt;p&gt;Now , Head  over to &lt;a href="https://www.emailjs.com/docs/examples/reactjs/" rel="noopener noreferrer"&gt;EmailJS Documentation&lt;/a&gt; to see how to make use of  EmailJs in a React Application by making use of an already made React Code snippets. From the Documentation this is How to make use of EmailJS in A React Application using this function :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useRef } from 'react';
import emailjs from '@emailjs/browser';

export const ContactUs = () =&amp;gt; {
  const form = useRef();

  const sendEmail = (e) =&amp;gt; {
    e.preventDefault();

    emailjs.sendForm('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', form.current, 'YOUR_PUBLIC_KEY')
      .then((result) =&amp;gt; {
          console.log(result.text);
      }, (error) =&amp;gt; {
          console.log(error.text);
      });
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make use Of EmailJS in a React App you are to &lt;code&gt;install and import&lt;/code&gt; emailjs  into your app.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;To be able to install emailjs Headover to new terminal window , check directory into the root directory of your project and  code:
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&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%2F2nxu9oxpv8wbfcqiv3gg.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%2F2nxu9oxpv8wbfcqiv3gg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After installing EmailJS , Go to The Component  which contains your form and Import EmailJS :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import emailjs from '@emailjs/browser';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6
&lt;/h3&gt;

&lt;p&gt;We make use of  The function From &lt;a href="https://www.emailjs.com/docs/examples/reactjs/" rel="noopener noreferrer"&gt;EmailJS Docs&lt;/a&gt; in the component Containing the contact Form&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useRef } from "react";
import emailjs from '@emailjs/browser';

const Email = () =&amp;gt; {

  const form = useRef();
  const sendEmail = (e) =&amp;gt; {
    e.preventDefault();

    emailjs.sendForm('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', form.current, 'YOUR_PUBLIC_KEY')
      .then((result) =&amp;gt; {
          console.log(result.text);
      }, (error) =&amp;gt; {
          console.log(error.text);
      });
    };

return (
    &amp;lt;div class="form"&amp;gt;
          &amp;lt;div class="title"&amp;gt;Contact Us&amp;lt;/div&amp;gt;
     &amp;lt;form  ref={form} onSubmit ={sendEmail}&amp;gt;

        &amp;lt;div class="input-container ic1"&amp;gt;
          &amp;lt;input id="firstname" className="input" type="text" placeholder="Username "  name="to_name"/&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="input-container ic2"&amp;gt;
          &amp;lt;input id="email" className="input" type="text" placeholder="Email Address  "  name="from_name"/&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="input-container ic2"&amp;gt;
         &amp;lt;textarea  required placeholder="Message"  name="message"&amp;gt;&amp;lt;/textarea&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;button type="text" className="submit"&amp;gt;Submit Message&amp;lt;/button&amp;gt;
     &amp;lt;/form&amp;gt;
 &amp;lt;/div&amp;gt;
   );
}

export default Email;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are calling the &lt;code&gt;sendEmail function&lt;/code&gt; when the form is been &lt;code&gt;Submitted(onSubmit)&lt;/code&gt;.  From This Function,  The &lt;code&gt;sendForm&lt;/code&gt;Method&lt;br&gt;
 in the function  has Some parameters which are in our EmailJs Account  which is Required To Enable us Send an Email Successfully&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;emailjs.sendForm('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', form.current, 'YOUR_PUBLIC_KEY')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;YOUR_SERVICE_ID :&lt;/strong&gt; To Get Your Service ID Head Over To Email Services on Your EmailJS Account Dashboard&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%2Fygty53cj07ncfwznzjno.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%2Fygty53cj07ncfwznzjno.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Copy the Service ID and Replace it with the YOUR_SERVICE_ID parameter in the function&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;YOUR_TEMPLATE_ID :&lt;/strong&gt; To Get Your Template ID  Head Over To Email Templates  on Your EmailJs Account Dashboard&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%2F7q73dimbcmkm50sm76dk.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%2F7q73dimbcmkm50sm76dk.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Copy the Template ID and Replace it with the YOUR_TEMPLATE_ID parameter in the function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;YOUR_PUBLIC_KEY :&lt;/strong&gt; To Get Your Public Key  Head Over To Account on  Your EmailJs Account Dashboard.&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%2F0sb3pl9cv8epxu0c19e7.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%2F0sb3pl9cv8epxu0c19e7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the Public Key and Replace it With YOUR_PUBLIC_KEY Parameter in the function.&lt;/p&gt;

&lt;p&gt;After Replacing  the values with all the necessary parameters from Your Personal EmailJs Account , Here is how the function should  be :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useRef } from "react"
import emailjs from '@emailjs/browser';

const Email = () =&amp;gt; {

const form = useRef();

const sendEmail = (e) =&amp;gt; {
  e.preventDefault();

  emailjs.sendForm('service_yta11dh', 'template_2c9a1n9', form.current, 'vnX3YDUTUw7Cj3l_q')
    .then((result) =&amp;gt; {
        console.log(result.text);
    }, (error) =&amp;gt; {
        console.log(error.text);
    });
    e.target.reset();
};

    return ( 
        &amp;lt;div class="form"&amp;gt;
        &amp;lt;div class="title"&amp;gt;Contact Us&amp;lt;/div&amp;gt;

         &amp;lt;form  ref={form}
         onSubmit ={sendEmail}&amp;gt;

        &amp;lt;div class="input-container ic1"&amp;gt;
          &amp;lt;input id="firstname" className="input" type="text" placeholder="Username "  name="to_name"/&amp;gt;

        &amp;lt;/div&amp;gt;

        &amp;lt;div class="input-container ic2"&amp;gt;
          &amp;lt;input id="email" className="input" type="text" placeholder="Email Address  "  name="from_name"/&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="input-container ic2"&amp;gt;
        &amp;lt;textarea  required placeholder="Message"  name="message"&amp;gt;&amp;lt;/textarea&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;button type="text" className="submit"&amp;gt;Submit Message&amp;lt;/button&amp;gt;

        &amp;lt;/form&amp;gt;
      &amp;lt;/div&amp;gt;

     );
}

export default Email;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;e.target.reset()&lt;/code&gt; in  The function is to Clear the Form after it is been submitted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;name Attribute&lt;/code&gt; in the &lt;code&gt;input&lt;/code&gt; element&lt;br&gt;
of the form Must Be The Same With  &lt;code&gt;name of The Variable&lt;/code&gt; in Your EmailJS  Template.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 7
&lt;/h3&gt;

&lt;p&gt;Now , We can Now Proceed to Send an email from the Browser Using the Form.&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%2Fsfrf71j7gy35kz9wbse6.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%2Fsfrf71j7gy35kz9wbse6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After submitting the form , The Email is sent immediately, Here is my  mail sent successfully :&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%2Fgkwu31ycjjlaa6kpr9q6.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%2Fgkwu31ycjjlaa6kpr9q6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;And there you have it , the email has been sent successfully to my Gmail account, So that is how to send an email in ReactJS without a backend Server using EmailJS.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Ways To Make HTTP Request in Javascript</title>
      <dc:creator>Benjamin Nwokolo</dc:creator>
      <pubDate>Mon, 12 Sep 2022 05:26:20 +0000</pubDate>
      <link>https://dev.to/benjaminnwokolo/ways-to-make-http-request-in-javascript-5djp</link>
      <guid>https://dev.to/benjaminnwokolo/ways-to-make-http-request-in-javascript-5djp</guid>
      <description>&lt;p&gt;Ways To Make HTTP Request in Javascript&lt;/p&gt;

&lt;p&gt;It is Very Crucial  To Know How to make HTTP Request to an Endpoint and Being Able to Send or Retrieve or  Get Data. Javascript Has Various Ways  and methods of Making HTTP Request To Various Server Endpoints and Database.&lt;br&gt;
In This Article, we are  Going To Be Discussing the Various Ways to Make HTTP Request In The Javascript Language&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) XMLHttpRequest&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;XMLHttpRequest is A  Built-In Object in Javascript for Making HTTP request From A Web Server. This Was the Only Way and Method Of Making HTTP Request  in The Javascript Language Before ES6.  We Can Receive and Obtain Data Using HTTP GET Method and We Can Send Data Using HTTP POST Method&lt;/p&gt;

&lt;p&gt;In This Example We are Going To Be Making Use of JSON Placeholder API which a free api made for developers for testing&lt;br&gt;
&lt;strong&gt;Step 1&lt;/strong&gt;&lt;br&gt;
We Create a new instance of  &lt;code&gt;XMLHttpRequest()&lt;/code&gt; Object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Creating a new instance of XMLHttpRequestObject

const request = new XMLHttpRequest();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;&lt;br&gt;
We  Proceed to create a new HTTP Request From a Server Endpoint&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
//Creating a new instance an XMLHttpRequest Object
const request = new XMLHttpRequest();
//open the request
request.open('GET', 'https://jsonplaceholder.typicode.com/todos/1');
//sending the request 
request.send();

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

&lt;/div&gt;



&lt;p&gt;We then Open The Request Using  &lt;code&gt;open()&lt;/code&gt;method which  has Two Parameters which  the first Paremeter is the  HTTP type / method of  request , for this case it  is a GET request we are performing.&lt;/p&gt;

&lt;p&gt;While the second parameter is the server endpoint from which we want to get data from. We then Send the request using the &lt;code&gt;send()&lt;/code&gt;Method&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have to track the progress of  request to know if the request  is successful or not so we add an eventlistener to the request to listen to the &lt;code&gt;readystatechange&lt;/code&gt; Event which  is been executed when the readyState property of XMLHttpRequest Changes&lt;br&gt;
readyState with the value of 4 Means The request is complete and status of 200 means the request is successful&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Creating a new instance an XMLHttpRequest Object
const request = new XMLHttpRequest();
//open the request
request.open('GET', 'https://jsonplaceholder.typicode.com/todos/1');
//sending the request 
request.send();

request.addEventListener('readystatechange', ()=&amp;gt;{
    if(request.readyState == 4 &amp;amp;&amp;amp; request.status == 200){
        console.log(request.responseText);
    } else{
        console.log('error in  getting data');
    }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, We performed and &lt;code&gt;if()&lt;/code&gt; statement to check if the readyState is equals to 4 and also if the status is 200 which  means our request was successful so we console.log() request.responsetext which is the text(data) received from the server endpoint in which we made our request and also an else to log error message in the console if the request was nit successful. In This Example our endpoint is the JSON Placeholder API .&lt;br&gt;
In Our Console You Would See something like this .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false
  }

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

&lt;/div&gt;



&lt;p&gt;We have finally and successfully Gotten a Fake id from JSON Placeholder API using XMLHttpRequest&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Using The Fetch API&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Fetch API helps us make to make HTTP Request in a similar manner with XMLHttpRequest but Fetch Makes use of the Promise API .When We make a request using fetch API it returns a promise which is asynchronous in nature .&lt;br&gt;
Fetch API Has one mandatory parameter which is the server-side URL&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Fetch Api
fetch('https://jsonplaceholder.typicode.com/todos/1')
&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;//Fetch Api
fetch('https://jsonplaceholder.typicode.com/todos/1').then((response) =&amp;gt;{
   // it returns a promise
  return response.json();
}).then((response) =&amp;gt;{
    console.log(response);
}).catch((err)=&amp;gt;{
     console.log(err);
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We tack on the &lt;code&gt;then()&lt;/code&gt; method to fetch API which returns our request response and we then log our response to the console. &lt;code&gt;.catch()&lt;/code&gt; method helps us catch error in our request if there is a error in our HTTP request.&lt;br&gt;
In Our Browser Console we get an output which is an object :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{userId: 1, id: 1, title: 'delectus aut autem', completed: false}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3) Axois&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Axois is a library for making HTTP Requests to various endpoints .Axios is a promise based method of making HTTP Request. A Unique feature of axios is that it returns JSON Data already parsed .Axios makes use of XMLHttpRequest Method  under the hood.&lt;br&gt;
Installing Axios&lt;br&gt;
We can make use of axios by installing it ,there are other methods of installing axios but we are going to make use of a CDN in this article&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  //Using CDN
 &amp;lt;script src="https://unpkg.com/axios/dist/axios.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We place this Script tag in the Head  Section of the HTML file&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;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Ways To Make HTTP Request with javascript &amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
    &amp;lt;script src="https://unpkg.com/axios/dist/axios.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can now proceed to make HTTP Requests using axios&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//axios
axios.get('https://jsonplaceholder.typicode.com/todos/1').then((data)=&amp;gt;{
   console.log(data);
}).catch((err)=&amp;gt;{
  console.log(err);
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We make a GET Request by calling get Method on axios with URL we want to send a request to  get data From. It returns a promise&lt;br&gt;
In the browser console we have an object  which contains our data :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{data: {…}, status: 200, statusText: '', headers: {…}, config: {…}, …}

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

&lt;/div&gt;



&lt;p&gt;4) &lt;strong&gt;Using JQuery&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;jQuery has several methods to make HTTP Requests But for the sake of this tutorial we would be using &lt;code&gt;$.ajax()&lt;/code&gt; method .&lt;br&gt;
&lt;code&gt;$.ajax()&lt;/code&gt;  method is used to make  asynchronous HTTP Requests to a specific URL  or Endpoint .&lt;br&gt;
To be able to make use of &lt;code&gt;$.ajax()&lt;/code&gt; you include its library  source file in the head section of your html page&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://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;

&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;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Ways To Make HTTP Request with javascript &amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
    &amp;lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Below is the syntax of $.ajax()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$.ajax({
  url: url,
  type: type,
  success: success,
  error : error
});

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;url:&lt;/strong&gt; it is the  URL / endpoint with which we     want make a request to using ajax.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;type:&lt;/strong&gt;  it defines the type of HTTP Method in the request&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;success:&lt;/strong&gt; it is a  callback function fired based on response of the request if it is successful&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;error:&lt;/strong&gt; it is a  callback function fired based on response of the request if there is an error in the request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$.ajax({
  url: 'https://jsonplaceholder.typicode.com/todos/1',
  type: 'GET',
  success: (res) =&amp;gt;{
     console.log(res);
  },
  error : (err) =&amp;gt;{
    console.log(err);
  },
});

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

&lt;/div&gt;



&lt;p&gt;In the browser console you get response of the request which is shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{userId: 1, id: 1, title: 'delectus aut autem', completed: false}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;We have learnt various ways to make HTTP Request in javascript . You can use any of the various methods to make request in your projects.Happy Coding !!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>api</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
