<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Deepanshu Arora </title>
    <description>The latest articles on Forem by Deepanshu Arora  (@deepansharora27).</description>
    <link>https://forem.com/deepansharora27</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%2F295675%2F20cc4a00-7100-482b-91bb-580de0201648.jpeg</url>
      <title>Forem: Deepanshu Arora </title>
      <link>https://forem.com/deepansharora27</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/deepansharora27"/>
    <language>en</language>
    <item>
      <title>Redefining The Way You Style Components Using Styled-Wind</title>
      <dc:creator>Deepanshu Arora </dc:creator>
      <pubDate>Thu, 26 Nov 2020 12:18:54 +0000</pubDate>
      <link>https://forem.com/deepansharora27/redefining-the-way-you-style-components-using-styled-wind-1g11</link>
      <guid>https://forem.com/deepansharora27/redefining-the-way-you-style-components-using-styled-wind-1g11</guid>
      <description>&lt;p&gt;Hey Everyone , &lt;/p&gt;

&lt;p&gt;In this Blog Post , we will see a better way by which we can style our UI Components. If you develop UI Components , chances that you  might be using &lt;strong&gt;styled-components&lt;/strong&gt; or  to style them , since it is the de-facto &lt;strong&gt;CSS in JavaScript Frameworks&lt;/strong&gt; which is used now a days.&lt;/p&gt;

&lt;p&gt;But Ladies and Gentlemen ,what If I told you  that something better than this exists which inherits features from &lt;strong&gt;styled-components&lt;/strong&gt; and &lt;strong&gt;TailWind CSS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WA15361s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a8i2ro90nifs6kibr2jq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WA15361s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a8i2ro90nifs6kibr2jq.jpg" alt="Fasten Your Seatbelts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Name of that Big Player  is &lt;strong&gt;styled-wind&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DH3LzUOC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p69498z2fwhd79lnkr77.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DH3LzUOC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p69498z2fwhd79lnkr77.png" alt="styled-wind"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;styled-wind&lt;/strong&gt;, you can make use of Tailwind CSS classnames into your &lt;strong&gt;styled-components&lt;/strong&gt; project,&lt;/p&gt;

&lt;p&gt;Now, you might be wondering why migrate to &lt;strong&gt;styled-wind&lt;/strong&gt; when I am okay with &lt;strong&gt;styled-components&lt;/strong&gt; in the first place.&lt;/p&gt;

&lt;p&gt;Let me give you few reasons to justify why you should migrate to &lt;strong&gt;styled-wind&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;1). &lt;strong&gt;The Ability to write Responsive Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Since , &lt;strong&gt;styled-wind&lt;/strong&gt; is a subset of &lt;strong&gt;TailWind CSS&lt;/strong&gt; i.e.&lt;br&gt;
you can make the use of TailWind CSS classnames into your Project , it becomes very easy to make your project responsive.&lt;/p&gt;

&lt;p&gt;Since every class in TailWind can be applied for different breakpoints , it becomes very easy to bring responsiveness into your project , and the fact of the matter is you do not have to use those classic &lt;strong&gt;Media Queries into your HTML&lt;/strong&gt; to make your web project responsive. Let &lt;strong&gt;styled-wind&lt;/strong&gt; do all the heavy lifting for you. &lt;/p&gt;

&lt;p&gt;2).&lt;strong&gt;By Using styled-wind , you do not have to memorize CSS Properties&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When using styled-wind , you get away with this headache of recalling those classic CSS properties and then applying them to style your CSS components. Instead , you can just refer Class Names from &lt;strong&gt;TailWind CSS&lt;/strong&gt; and then you are good to go. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CJzBjasw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r4f5fgduip5rgh578dlt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CJzBjasw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r4f5fgduip5rgh578dlt.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you clearly observe this above Code Snippet Example , you can clearly observe that instead of using any of the classic CSS properties , you can refer the required class name which you want to use from &lt;strong&gt;TailWind CSS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;3).&lt;strong&gt;Flexibility of using TailWind CSS in styled-components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now , since styled-wind is the hybrid form of TailWindCSS+styled-components , it becomes a lot easier to integrate TailWind CSS in a styled-components project.&lt;/p&gt;

&lt;p&gt;As , we discussed in the first point , you can just refer to the required classname in the TailWind CSS Documentation , and then appropriately use it in your Project.&lt;/p&gt;

&lt;p&gt;For Instance , Suppose you want to add vertical padding of 4 rem to an element. Now had you made use of &lt;strong&gt;Traditional CSS&lt;/strong&gt; into your project , you would have to explicitly specify to your CSS file :&lt;br&gt;
&lt;code&gt;padding-top : 4 rem ; &lt;br&gt;
padding-bottom : 4rem ; &lt;br&gt;
&lt;/code&gt;&lt;br&gt;
but with styled-wind , you get away this mess , you can simply write &lt;code&gt;py-4&lt;/code&gt; and you are done. &lt;/p&gt;

&lt;p&gt;I hope , by now you must be fan of TailWind CSS :D &lt;/p&gt;

&lt;p&gt;Well , there are other reasons also as to why using &lt;strong&gt;styled-wind&lt;/strong&gt; is more advantageous. But , in my Opinion as a Developer , these two reasons are strong enough to propel you towards using &lt;strong&gt;styled-wind&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now , there is nothing wrong in using &lt;strong&gt;styled-components&lt;/strong&gt;, but the main factor which I found as a limiting factor was that , everytime I want to style a component , I have to refer those traditional CSS properties. &lt;/p&gt;

&lt;p&gt;So , that's it for this blog post&lt;/p&gt;

&lt;p&gt;You can deep dive into &lt;strong&gt;styled-wind&lt;/strong&gt; by referring to its User Friendly Documentation here : &lt;br&gt;
&lt;a href="https://styled-wind.netlify.app/#/"&gt;https://styled-wind.netlify.app/#/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope , I was able to provide some value through this Blog&lt;/p&gt;

&lt;p&gt;You can connect with me through these following platforms :&lt;/p&gt;

&lt;p&gt;Linkedin : &lt;a href="https://www.linkedin.com/in/deepansharora27/"&gt;https://www.linkedin.com/in/deepansharora27/&lt;/a&gt;&lt;br&gt;
Twitter :  &lt;a href="https://twitter.com/deepansharora27"&gt;https://twitter.com/deepansharora27&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Working on Social Authentication through PassportJS and integrating it with our Backend ExpressJS App (Part - 1 )</title>
      <dc:creator>Deepanshu Arora </dc:creator>
      <pubDate>Tue, 10 Nov 2020 07:22:23 +0000</pubDate>
      <link>https://forem.com/deepansharora27/working-on-social-authentication-through-passportjs-and-integrating-it-with-our-backend-expressjs-app-part-1-3djj</link>
      <guid>https://forem.com/deepansharora27/working-on-social-authentication-through-passportjs-and-integrating-it-with-our-backend-expressjs-app-part-1-3djj</guid>
      <description>&lt;p&gt;Recently , While Working on My Side Project , I thought why not authenticate the end user who is going to access my application with the help of various Social Network platforms such as Facebook and Twitter.&lt;/p&gt;

&lt;p&gt;Many People who are reading this blog , will resonate with the fact that , it is so much easier to signup/login via social network platforms such as Facebook and Twitter , instead of manually going through this traditional process of filling in your E-mail Address , Your Name , then setting up a password. This traditional process takes up a lot of time. &lt;/p&gt;

&lt;p&gt;That's why we have this savior for Developers , who want to provide their users with the comfort of , signing in/signing up  to their web app with the Social Authentication Mechanism and that Savior is &lt;strong&gt;PassportJS&lt;/strong&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1604932334926%2FH2dA0lMCB.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1604932334926%2FH2dA0lMCB.png" alt="Screenshot 2020-11-09 at 8.01.33 PM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PassportJS is basically a authentication middleware for &lt;strong&gt;NodeJS&lt;/strong&gt;. The interesting fact about PassportJS is that , it can be integrated with any Express Based Web Application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's dive into it and explore more about it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the root , we have our &lt;strong&gt;server.js&lt;/strong&gt; file , and main role of this file is instantiating our server , and instantiating the middleware for PassportJS. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I am assuming that you are already familiar with the fundamentals of Express and NodeJS , therefore I will  not go into the deep nitty gritties of every line of code , and I will focus mostly on explaining the concepts related to PassportJS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

app.set("port" , process.env.PORT || 3000);

app.use(passport.initialize());
app.use(passport.session());

app.listen(app.get("port"), () =&amp;gt; {
  console.log("The Server is Up and Running");

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

&lt;/div&gt;



&lt;p&gt;The Main thing to notice here is these two statements&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use(passport.initialize());
app.use(passport.session());

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

&lt;/div&gt;



&lt;p&gt;Let's understand what we're doing in each of the above statements :&lt;/p&gt;

&lt;p&gt;The First Statement basically imports the Passport Middleware Function which is essentially designed for &lt;strong&gt;integration with Express&lt;/strong&gt;. It basically gives Passport the access to the request and response streams(or we can say &lt;strong&gt;request and response objects&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;The Second Statement basically integrates Express Session Middleware with PassportJS.&lt;/p&gt;

&lt;p&gt;Now , comes the main deal where we will now purely deal with &lt;strong&gt;PassportJS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now , we have another file named &lt;strong&gt;auth.js&lt;/strong&gt; , where we will now deal with the &lt;br&gt;
&lt;strong&gt;Social Authentication Logic Using PassportJS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const passport = require('passport');
const FacebookStrategy = require("passport-facebook").Strategy ; 

/*
Importing this User Route because , here I have defined several helper functions and since I am using Mongoose as an Interface to communicate with my MongoDB Database , I have performed all of the queries on the database in this File(Will attach the screenshot of this route file below so that you can know how I have performed query on database using the helper functions.
*/
const user = require("../routes/users");

module.exports = ()=&amp;gt; {

 passport.serializeUser((user, done) =&amp;gt; {
    done(null, user.id);
  });

  passport.deserializeUser((id, done) =&amp;gt; {
    //Find the User Using the _id Property inside of our MongoDB Collection :
    user
      .findById(id)
      .then((user) =&amp;gt; done(null, user))
      .catch((error) =&amp;gt; console.log("Error While Deserializing the User"));
  });

let authProcessor = async (accessToken, refreshToken, profile, done) =&amp;gt; {

    const result = await user.findOne(profile.id);

    if (result) {
      done(null, result);
    } else {
      const newUserSaved = await user.createNewUser(profile);

      if (newUserSaved) {
        done(null, newChatUser);
      } else {
        console.log("Error While Creating a New User");
      }
    }
  };

  passport.use(new FacebookStrategy(config.fb, authProcessor));

}

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

&lt;/div&gt;



&lt;p&gt;Let's start from*&lt;em&gt;top-down&lt;/em&gt;* and see what we are trying to accomplish here:&lt;/p&gt;

&lt;p&gt;Firstly , we have imported this package named as &lt;strong&gt;passport-facebook&lt;/strong&gt; and while importing this package , we are invoking this &lt;strong&gt;Strategy Constructor Function&lt;/strong&gt;. This statement basically goes into the passport-facebook module and imports the constructor function , which internally uses the &lt;strong&gt;OAuth 2.0 Module&lt;/strong&gt; to provide authentication and login functionality to your Application. &lt;/p&gt;

&lt;p&gt;Now , if we have a look at the end of the file , we have this code :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; passport.use(new FacebookStrategy(config.fb, authProcessor));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is basically the passport middleware function , here inside this middleware function , we are passing in a new instance of the FacebookStrategy Module. &lt;br&gt;
(&lt;strong&gt;SideNote : If you are Familiar with Object Oriented Programming, you might be already familiar that in order to invoke constructor of a class automatically , we just create a new instance of that class. The Same thing we are doing here as well.&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;Inside this new instance Of FacebookStrategy , we will pass two things as parameters , &lt;strong&gt;A Configuration Block which basically is providing access to the ApplicationID , SecretKey and a  A Callback URL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the Configuration block that I am talking about :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"fb": {
    "clientID": "3417694501659554",
    "clientSecret": "e9b2089b3c04886396983be6d01cbb7f",
    "callbackURL": "//localhost:3000/auth/facebook/callback",
    "profileFields": ["id", "displayName", "photos"]
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is basically an object with these &lt;strong&gt;key-value pairs&lt;/strong&gt; . The ClientID and ClientSecret is provided by Facebook only and it will be provided by Facebook when you register your application on Facebook . &lt;/p&gt;

&lt;p&gt;You can do so by visiting *&lt;em&gt;&lt;a href="http://www.developers.facebook.com" rel="noopener noreferrer"&gt;www.developers.facebook.com&lt;/a&gt; *&lt;/em&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1604943778909%2FgY7Ra37L_.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1604943778909%2FgY7Ra37L_.png" alt="Screenshot 2020-11-09 at 11.12.28 PM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next Login with your Account , then you will see an option in the top-right corner named as &lt;strong&gt;MyApps&lt;/strong&gt; , click on that. After Clicking on MyApps Option , you will see an option named as &lt;strong&gt;Create New App&lt;/strong&gt; , click on that . &lt;/p&gt;

&lt;p&gt;Next , it will show you a set of options asking you what purpose does your app serve &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1604944037763%2FhN2wTBok_.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1604944037763%2FhN2wTBok_.png" alt="Screenshot 2020-11-09 at 11.16.07 PM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since we are working on creating a Web App , Click on the Last Option and then proceed forward . Fill all the required details about your Web Application .&lt;/p&gt;

&lt;p&gt;At last when everything gets completed , Go to Settings and then click on Basic.&lt;/p&gt;

&lt;p&gt;You will see something like this :&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1604944235562%2FNAvhEyp_q.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1604944235562%2FNAvhEyp_q.png" alt="Screenshot 2020-11-09 at 11.20.05 PM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the AppID and the App Secret Key that is provided by Facebook , so that you can use it's API , to proceed with the Social Authentication.(&lt;strong&gt;SideNote : It is advised that you should not share your SecretKey with anyone&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;CallBack URL&lt;/strong&gt; Key is used such that when you are successfully authenticated by facebook , using your credentials , then facebook needs a way to get back to your Application , this purpose is served by the CallBack URL Property. We Type in the URL , where we want Facebook to redirect to , after we are successfully authenticated. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;profileFields&lt;/strong&gt; property is basically an array of strings , and those strings represent what do we want to request back from the Facebook Server for our Application. &lt;/p&gt;

&lt;p&gt;The Next Parameter inside this Passport Middleware is an Callback Function which has four Parameters :&lt;br&gt;
&lt;strong&gt;AccessToken , RefreshToken , profile(A Profile Object) and done(A Method)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This Callback Function is technically known as the &lt;strong&gt;VerifyCallback&lt;/strong&gt;because its job is to find a User Profile in the local MongoDB Instance using the profile.id which refers to the UserID as sent by Facebook or any other Social Authentication Provider.&lt;/p&gt;

&lt;p&gt;The AccessToken and RefreshToken are Provided by Facebook as a part of OAuth 2.0 Process. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;done()&lt;/strong&gt; method gets the data out of the Authentication Pipeline and provides it to the requesting application. &lt;/p&gt;

&lt;p&gt;As we can see in the code snippet for the callback function , we are querying our Database for finding if the user is present in our Local MongoDB instance or not . If the user is present , we directly return it to the app using the done() method &lt;br&gt;
else we create the new user in the database and then return it to requesting application using done() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let authProcessor = async (accessToken, refreshToken, profile, done) =&amp;gt; {

    const result = await user.findOne(profile.id);

    if (result) {
      done(null, result);
    } else {
      const newUserSaved = await user.createNewUser(profile);

      if (newUserSaved) {
        done(null, newChatUser);
      } else {
        console.log("Error While Creating a New User");
      }
    }
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the code  of the helper function users route , as i mentioned earlier :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const router = require("express").Router();
const UserModel = require("../models/User");

let findOne = (profileID) =&amp;gt; {

  return UserModel.findOne({
    profileId: profileID,
  });
};


let createNewUser = async (profile) =&amp;gt; {
  return new Promise((resolve, reject) =&amp;gt; {

    let newChatUser = new UserModel({
      profileId: profile.id,
      fullName: profile.displayName,
      profilePic: profile.photos[0].value || "",
    });

    newChatUser.save((error) =&amp;gt; {
      if (error) {
        console.log("Error in Creating New User");
        reject(error);
      } else {
        resolve(newChatUser);
      }
    });
  });
};

let findById = (id) =&amp;gt; {
  return new Promise((resolve, reject) =&amp;gt; {
    UserModel.findById(id, (error, user) =&amp;gt; {
      if (error) {
        reject(error);
      } else {
        resolve(user);
      }
    });
  });
};

module.exports = {
  findOne,
  createNewUser,
  findById,
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;That's all for this Part 1 of the Blog . In the Part 2 , I will continue the discussion further and there we will talk about Serializing and De serializing user data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I hope , I was able to provide some value with my content. &lt;br&gt;
If you liked it , please share it with your Network .&lt;/p&gt;

&lt;p&gt;You can connect with me through following platforms :&lt;/p&gt;

&lt;p&gt;LinkedIn : &lt;a href="https://www.linkedin.com/in/deepansharora27/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/deepansharora27/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twitter UserHandle : Deepansharora27&lt;/p&gt;

&lt;p&gt;Instagram : deepanshu.codes&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>express</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Everything about JWT(JSON Web Tokens) and why it is more powerful than the traditional Session Management ? </title>
      <dc:creator>Deepanshu Arora </dc:creator>
      <pubDate>Sun, 11 Oct 2020 07:06:58 +0000</pubDate>
      <link>https://forem.com/deepansharora27/everything-about-jwt-json-web-tokens-and-why-it-is-more-powerful-than-the-traditional-session-management-2j1</link>
      <guid>https://forem.com/deepansharora27/everything-about-jwt-json-web-tokens-and-why-it-is-more-powerful-than-the-traditional-session-management-2j1</guid>
      <description>&lt;p&gt;While Working with any backend framework , I am sure you must have heard of this recurring term , &lt;strong&gt;JWT(JSON Web Tokens)&lt;/strong&gt; , &lt;br&gt;
and I tried to gain more insight into this concept since past few days while working on my &lt;strong&gt;Full Stack MERN Project&lt;/strong&gt; and thought why not share some insights , which can help other Developers in the Community as well. &lt;/p&gt;

&lt;p&gt;So , Let's get started and get to the meat of the things : &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JWT or JSON Web Token&lt;/strong&gt; is basically a token which is used for authorisation of a &lt;strong&gt;Client/or Host/or User&lt;/strong&gt; , and mind my words , it is used for &lt;strong&gt;Authorisation&lt;/strong&gt; , not &lt;strong&gt;Authentication&lt;/strong&gt; . There is a fine line difference between both of these two terms.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Lets take a minute to understand both of these two terms as well *&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Let's take example of Facebook, which we all use in our day to day lives : &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%2Fi%2Fmhxmhmlwejwaqcrnvnql.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%2Fi%2Fmhxmhmlwejwaqcrnvnql.png" alt="Facebook Login Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, is the Facebook Login Page , You Enter your Credentials(User Name and Password Here), and Click on Log In. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When you are successfully logged in , and redirected to the home page of your News Feed, that is when you can say that you are successfully Authenticated by the Backend Server.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Now , since we are clear with Authentication , let's get to Authorisation . &lt;/p&gt;

&lt;p&gt;Now , let's suppose you want to update your Profile Picture on Facebook . Now, you are well aware that you are authenticated user, that's why Facebook Server has redirected to your Homepage. But, in order to update your Profile Picture on Facebook , you must be an Authorised User . &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;By Authorised in this context , I mean that you must have the access right and privileges, to make sure that Facebook's Server accepts your request, to update your Profile Picture on Facebook&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Now , the question which arises here is that , How will Facebook get to know , that I am an &lt;strong&gt;Authorised&lt;/strong&gt; User , and can successfully update my profile picture on Facebook.&lt;/p&gt;

&lt;p&gt;It gets to know it through the help of JWT(JSON Web Token Only). Let's see how : &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%2Fi%2F9fh0l5y8341r3fo1u9rp.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%2Fi%2F9fh0l5y8341r3fo1u9rp.png" alt="Session Management and JSON Web Tokens"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this above diagram, you can see two pictures. The First picture describes how things in &lt;strong&gt;Traditional Session Management&lt;/strong&gt; Work , and the second picture describes how the process of Authorisation and Authentication works in Case of &lt;strong&gt;JSON Web Token&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's have a look at the Second Process as of now:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt; : In the Initial Step Number 1 , the client tries to login using their credentials. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt; : After getting logged in , in Step Number 1 , and getting authenticated successfully, the backend generates a JWT Token and embeds it along with a secret key(&lt;strong&gt;which is generated at the backend server side only&lt;/strong&gt;) and then that token is sent back to the Client/Browser.&lt;/p&gt;

&lt;p&gt;Let's also analyse the structure of JWT also for a minute :&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%2Fi%2F36f6gzij0xp90w3bdkms.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%2Fi%2F36f6gzij0xp90w3bdkms.png" alt="Structure of JSON Web Token"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you take a look on the left side, the token is encoded and if you observe carefully , &lt;strong&gt;there are 3 parts to this token&lt;/strong&gt;. These three parts are as follows : &lt;/p&gt;

&lt;p&gt;1). &lt;strong&gt;Header&lt;/strong&gt;&lt;br&gt;
2). &lt;strong&gt;Payload&lt;/strong&gt;&lt;br&gt;
3). &lt;strong&gt;Signature&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HEADER PART:&lt;/strong&gt;&lt;br&gt;
The Header as you can see in the Screencast as well , contains information about the &lt;strong&gt;Type Of Algorithm&lt;/strong&gt; with which the Token is encoded(&lt;strong&gt;which is generally HS256&lt;/strong&gt;) and the type of token it is . &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PAYLOAD PART:&lt;/strong&gt;&lt;br&gt;
The Payload part is the main part, where the details of the client who is making a request to the server , so that the server knows that client is actually an authorised user and he is having the access privileges to access what is technically known as a &lt;strong&gt;Protected Route&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Payload is a &lt;strong&gt;JavaScript Object&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SIGNATURE PART&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Signature Part is I believe where the real magic happens. It is where the Server in the Backend actually gets to know, that &lt;br&gt;
the User is who is trying to gain access to the &lt;strong&gt;Protected Route&lt;/strong&gt; , should be given the access or not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now,How does the Server Identify that ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the Client to access a protected route , we know that along with the request , token is also sent and it contains details about the User , which are encoded in the Token Itself.&lt;/p&gt;

&lt;p&gt;Now , in order to identify whether the User is authorised or not, the server checks that the token which is received along with request should not be &lt;strong&gt;tampered/modified&lt;/strong&gt; by the client. In case , it is found to be tampered/modified , the request is immediately rejected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, this is how the process of Authorisation with Tokens Work.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, Coming to the Second Part of the Question i.e. &lt;strong&gt;Why this Approach of Authorisation with Tokens is more powerful than traditional Session Management&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Let's say , you have your Application and 2 server(&lt;strong&gt;First is the Primary Server and Second is Secondary Server&lt;/strong&gt;). In Case the traffic load on one server reaches its threshold , all the requests are redirected to the Second Server. Now , Had we used the traditional session management , the Users who had been redirected to the second server , would not have been able to access the Protected Routes.&lt;/p&gt;

&lt;p&gt;Reason being , in case of traditional session management, the data related to the User would have been stored as &lt;strong&gt;Session ID in the Cookies of the Browser&lt;/strong&gt; , and since second server is not the primary server , all the requests of authorising themselves would have been rejected. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, this was all about Process of Authorisation with Tokens and with the Help of Traditional Session Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I hope , I was able to provide some value with the help of this article. If you liked it , please share it so that other developers in the Community can benefit from it. &lt;strong&gt;Thank You&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>webdev</category>
      <category>career</category>
    </item>
    <item>
      <title>Working with State in ReactJS </title>
      <dc:creator>Deepanshu Arora </dc:creator>
      <pubDate>Wed, 01 Apr 2020 12:18:26 +0000</pubDate>
      <link>https://forem.com/deepansharora27/working-with-state-in-reactjs-5g65</link>
      <guid>https://forem.com/deepansharora27/working-with-state-in-reactjs-5g65</guid>
      <description>&lt;p&gt;As we all know that , React is a Component Based Library. We divide the Complex UI into Basic Components and then again we add up all of these Basic Components to create a Complex UI which is also known as a &lt;br&gt;
&lt;strong&gt;Complex Component&lt;/strong&gt; . React Controls the Data Flow in the Components with the help of &lt;strong&gt;State&lt;/strong&gt; and &lt;strong&gt;Props&lt;/strong&gt; . &lt;/p&gt;

&lt;p&gt;Here , by Data Flow I mean that , how a Component can communicate with Another Component , and the components are able to communicate with each other with the help of State and Props .&lt;/p&gt;

&lt;p&gt;In this Article , we will explore about the Concept Of &lt;strong&gt;State&lt;/strong&gt; . &lt;/p&gt;

&lt;p&gt;State can be thought of as a Data-Store to the ReactJS Component.&lt;br&gt;
It allows us to save , modify and delete the properties which are stored in our Component.  &lt;/p&gt;

&lt;p&gt;Now , the question which we should ponder over is that &lt;strong&gt;Why in the First Place Should we use State?What Should be Our Motivation Behind Using It&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well , the core of every React Component is in it's State . The State Determines what the Component looks like, and we can update that as we go. &lt;br&gt;
Let's Suppose , if we have made a change in our Component, then the entire page won't be reloaded if a Component's State is Updated - only the component will be re-rendered , and hence it allows us to create web pages that are &lt;strong&gt;Dynamic and Interactive&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;State is mostly used to update the Component when the User Performs some action like , &lt;strong&gt;Clicking a Button , Typing Some Text , Pressing a Key etc&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now , let's understand the Concept Of State Practically by Coding it :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;**First Of all, we will Create a Class Based Component Named as "App" :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vbz5vcKP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zwxxbj356p8jmiblfrh8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vbz5vcKP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zwxxbj356p8jmiblfrh8.png" alt="Class Based Component App"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, let's Continue by Adding State to Our Component:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2thZaC3I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6r6uywsoxtwap8w99i59.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2thZaC3I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6r6uywsoxtwap8w99i59.png" alt="Alt-text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let's analyse what we have done in the above Code Snippet ,&lt;/p&gt;

&lt;p&gt;Inside Our Class Based Component &lt;strong&gt;App&lt;/strong&gt; , we have defined a Constructor &lt;br&gt;
Now the constructor is making call to the Super Class which in this case is &lt;strong&gt;ReactComponent&lt;/strong&gt; . Now , the reason due to which we make the call to the Super Class is we can think of it as , that our Component inherits some of the Goodies from the Super Class , which in Our Case is &lt;strong&gt;ReactComponent&lt;/strong&gt; , and then we can use it . &lt;/p&gt;

&lt;p&gt;The Goodies which I am talking about here is some &lt;strong&gt;Methods&lt;/strong&gt; which our Component can use . &lt;br&gt;
Now , next to calling super what we have done is set the &lt;strong&gt;State&lt;/strong&gt; . &lt;br&gt;
As we have discussed earlier that State is an Object and we can access this State anywhere in Our Component , by using keyword &lt;strong&gt;this.state&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Now , I have added a property to my state which is &lt;strong&gt;SubscriberCount&lt;/strong&gt; and I have initially set it to &lt;strong&gt;0&lt;/strong&gt; . Now what I want to implement is that , &lt;br&gt;
every time I click on a Button named &lt;strong&gt;Subscribe Me&lt;/strong&gt; , the property of my State should be incremented by &lt;strong&gt;1&lt;/strong&gt; every time I click on the Button. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's write the code to implement the above logic&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dAhYXKpf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o63aj4kcxdtl2vxn7qre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dAhYXKpf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o63aj4kcxdtl2vxn7qre.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Above Code Snippet , we have declared a method named &lt;br&gt;
&lt;strong&gt;handleChange()&lt;/strong&gt; . The Main Motive for which we have declared this&lt;br&gt;
method is &lt;strong&gt;to change the state&lt;/strong&gt; . By Changing the state, here I mean &lt;br&gt;
that whenever we click on the button, it should change the initial state&lt;br&gt;
of the property &lt;strong&gt;SubscriberCount&lt;/strong&gt; and increment it by 1 .&lt;/p&gt;

&lt;p&gt;Inside our handleChange() method, we have changed the state using the &lt;br&gt;
&lt;strong&gt;setState()&lt;/strong&gt; method , which is provided to us by Our Super Class&lt;br&gt;
&lt;strong&gt;React.Component&lt;/strong&gt; . A common question , which you all must be having&lt;br&gt;
in your mind is that , why use this &lt;strong&gt;setState()&lt;/strong&gt; method , why can't we &lt;br&gt;
directly change the state using &lt;strong&gt;this.PropertyName&lt;/strong&gt;  directly . &lt;/p&gt;

&lt;p&gt;Note that you cannot mutate the state directly otherwise it can lead to &lt;br&gt;
some odd bugs in your component . &lt;strong&gt;For More Information , you can refer&lt;br&gt;
to the React Documentation&lt;/strong&gt;  . &lt;/p&gt;

&lt;p&gt;Using the &lt;strong&gt;setState()&lt;/strong&gt; method provided by our super class &lt;strong&gt;React.Component&lt;/strong&gt;, at each click of the button our state property is &lt;br&gt;
incremented by 1 . Now , let's analyse the statement due to which &lt;br&gt;
we are able to increment our State Property:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;return(&lt;br&gt;
SubscriberCount : prevState.SubscriberCount+1; &lt;br&gt;
)&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;One more interesting thing that you should observe about the &lt;strong&gt;setState()&lt;/strong&gt; method is that, this method implicitly provides us with &lt;br&gt;
a parameter which helps us to access the &lt;strong&gt;previous state&lt;/strong&gt; . &lt;/p&gt;

&lt;p&gt;Thats, what we are doing inside the return statement , we are changing our state at each click of the button by incrementing 1 to our previous state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VqJ2SSEn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rhjhs10dc02g7y2gyb2k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VqJ2SSEn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rhjhs10dc02g7y2gyb2k.png" alt="Previous State Figure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zGQa0xkJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lnqr6coljis9bqh10zlp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zGQa0xkJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lnqr6coljis9bqh10zlp.png" alt="Current State Figure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a look at the two figures above, initially value of Our SubscriberCount is 0 , when we click the button &lt;strong&gt;Click here to Subscribe Me&lt;/strong&gt; , it immediately changes the state property by incrementing it with 1 . &lt;strong&gt;In this Case , our prevState parameter is initialised with 0 implicitly , and when we click on the button , it immediately makes changes to the state property by incrementing the previous state by 1&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is how our whole component looks like&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZWAWbjCa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1xbjneby6te3smuoe828.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZWAWbjCa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1xbjneby6te3smuoe828.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you should have gotten a clear picture of how states work in React &lt;br&gt;
and my article added some value :) . &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Whole Intuition Behind Machine Learning ?What Exactly It Is ? </title>
      <dc:creator>Deepanshu Arora </dc:creator>
      <pubDate>Thu, 19 Dec 2019 09:07:32 +0000</pubDate>
      <link>https://forem.com/deepansharora27/whole-intuition-behind-machine-learning-what-exactly-it-is-ep6</link>
      <guid>https://forem.com/deepansharora27/whole-intuition-behind-machine-learning-what-exactly-it-is-ep6</guid>
      <description>&lt;p&gt;Hello Everyone !! &lt;/p&gt;

&lt;p&gt;Most of you who are newbies to the Field of Machine Learning , might be hearing These Technical Jagrons very frequently : &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"You have to train your Data in Machine Learning"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"The Machine Learning Models Learn from the Data"&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Well ,Today I am going to deep dive into this Whole Process and by the End of this Article , you will get a better intuition of this Whole Process Of Machine Learning . So Let's Start : &lt;/p&gt;

&lt;p&gt;Let's say we have been given a Task to create a System that Answers whether a Drink is a &lt;strong&gt;Wine&lt;/strong&gt; or a &lt;strong&gt;Beer&lt;/strong&gt; . &lt;/p&gt;

&lt;p&gt;--&amp;gt;This Question Answering System that we Build is in technical terms called a &lt;strong&gt;MODEL&lt;/strong&gt; , and this Model is created via a Process called as &lt;br&gt;
&lt;strong&gt;TRAINING&lt;/strong&gt; . &lt;/p&gt;

&lt;p&gt;In Machine Learning , the role of Training is to build a System that answers our Questions Correctly Most of the Time , but in order to train a Model we need to collect Data to Train On . &lt;/p&gt;

&lt;p&gt;In Our Example Data will be Collected from Glasses of Wine and Beer . There are many aspects of Drink that we could collect Data on --&lt;br&gt;
&lt;strong&gt;Everything from the Amount of Foam , to the Shape of the Glass&lt;/strong&gt; . &lt;/p&gt;

&lt;p&gt;But for Our Purposes , we will just pick two simple one's :&lt;br&gt;
1).&lt;strong&gt;The Color of the Drink&lt;/strong&gt;&lt;br&gt;
2).&lt;strong&gt;The Alcohol Content in the Drink(As a Percentage)&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The Hope is that we can split our two types of drinks based on these two factors alone . We'll call these &lt;strong&gt;FEATURES&lt;/strong&gt; from Now on(&lt;strong&gt;Again , please make note of this Technical Term as you will be hearing it Quite Frequently in the Machine Learning World&lt;/strong&gt;) . &lt;/p&gt;

&lt;p&gt;--&amp;gt;The First Step of Our Process will be Running to the Grocery Store and buy a bunch of Different Drinks and get some equipments to do our Measurements : &lt;br&gt;
1).A Spectrometer for Measuring the Color &lt;br&gt;
2).&amp;amp; A Hydrometer to Measure the Alcohol Content . &lt;/p&gt;

&lt;p&gt;Now , when we have set all of our Equipments , it's time for the First Important Step of Machine Learning : &lt;strong&gt;"GATHERING THE DATA"&lt;/strong&gt; . This Step is Important Because the Quality and Quantity of Data that we gather will directly determine How Good Our Predictive Model Can be . &lt;/p&gt;

&lt;p&gt;In our Case , the Data that we will collect will be the Color and Alcohol Content of Each Drink . This Will Yeild us a Table of Color , Alcohol Content and whether it's a Wine or a Beer ?  &lt;/p&gt;

&lt;p&gt;This Will be Our &lt;strong&gt;TRAINING DATA&lt;/strong&gt; . So After a Few Hours , we will gather all Of Our Training Data . &lt;/p&gt;

&lt;p&gt;--&amp;gt;Now it's time for Our Next Step of Machine Learning which is &lt;br&gt;
&lt;strong&gt;DATA PREPARATION&lt;/strong&gt; , where we load Our Data into a Suitable Place and prepare it for our Use in Machine Learning Training . &lt;/p&gt;

&lt;p&gt;Now, this is also the time to do any Visualisations of Our Data helping us see if there is Any Relationship between Two Different Variables , as well as to also show if there are any &lt;strong&gt;DATA IMBALANCES&lt;/strong&gt; . &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Jj_p2ia4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7mk9uv18fcrg0irf4wau.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Jj_p2ia4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7mk9uv18fcrg0irf4wau.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For Example , if we collected way more Data About Beer , then the Model that we will train will be heavily biased towards Beer than Wine . &lt;/p&gt;

&lt;p&gt;We also need to split our Data into two parts - the first part used in Training Our Model will be the Majority of Our Data Set . The Second Part will be used for evaluating our Trained Model's performance . &lt;/p&gt;

&lt;p&gt;We don't want to use the same data that the Model was trained on for Evaluation , since then it would just be able to memorise the Questions , just as you wouldn't want to use the Questions from your Maths Homework in the Maths Exam . &lt;/p&gt;

&lt;p&gt;The Next Step in Our Workflow is &lt;strong&gt;CHOOSING A MODEL&lt;/strong&gt; . There are many Models that Researcher and Data Scientists have created over the Years . Some are very well suited for Image Data , others for Sequences , such as Text Or Music , some For Numerical Data , and Others For Text Based Data . &lt;/p&gt;

&lt;p&gt;In Our Case , we have just Two Factors , Color and Alcohol Percentage . &lt;br&gt;
So in Our Case we can use a Simple Linear Model as Demonstrated Below : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0-j1aEx5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0n7ojk93jrwv5yue435e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0-j1aEx5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0n7ojk93jrwv5yue435e.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now , we will move on to the Most Important Part of the Machine Learning Process -- &lt;strong&gt;The Training Process&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this Step , we will Use our Data to incrementally improve our Model's Ability to predict Whether a Given Drink is Wine Or Beer . &lt;/p&gt;

&lt;p&gt;In Some Ways , this is Similar to Someone who is &lt;strong&gt;Learning to Drive&lt;/strong&gt; . &lt;br&gt;
At First , they don't know how any of the Pedals , Knobs and switches work or when they should be pressed or used . However , after lots of practice and correcting for their mistakes , a licensed driver emerges &lt;/p&gt;

&lt;p&gt;Similar to the Above Scenario , we will do the same thing on our Drinks . &lt;/p&gt;

&lt;p&gt;We Know that , Formula For a Straight line is : &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;y=m*x+b&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;where , x is the input &lt;br&gt;
        m is the slope of the Line &lt;br&gt;
        y is the Output Generated &lt;br&gt;
       &amp;amp; b is the y-intercept . &lt;/p&gt;

&lt;p&gt;The Values which we have available to us to Adjust or Train are just &lt;strong&gt;m&lt;/strong&gt; and &lt;strong&gt;b&lt;/strong&gt; , where m is the Slope of the Line &amp;amp; b is the y-intercept for the Line. There is no other way to affect the position of the Line since the only other Variables are &lt;strong&gt;x&lt;/strong&gt; , our input &amp;amp; &lt;strong&gt;y&lt;/strong&gt; that is Our Output . &lt;/p&gt;

&lt;p&gt;In Machine Learning , there are Multiple m's , since there might be Multiple Features&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qN5uGTly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0b00xn48x8x4ufp5bfuy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qN5uGTly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0b00xn48x8x4ufp5bfuy.png" alt="Alt Text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The Collection of these Values is usually formed into a Matrix  , that is Denoted by &lt;strong&gt;W&lt;/strong&gt; for the Weights Matrix . Similarly , for &lt;strong&gt;b&lt;/strong&gt;(the y-intercept) we arrange them together , and that's called the Biases . &lt;/p&gt;

&lt;p&gt;The Training Proces involves initialising random values for w and b and attempting to predict the Output with those Values . It does pretty poorly at First , but we can compare our Model's Prediction with the Output it should have Produced and then adjust the Values in &lt;strong&gt;w&lt;/strong&gt; and &lt;strong&gt;b&lt;/strong&gt; , such that we will have more Accurate Predictions on the next time Around . So this Process , then Repeats . &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WV51tJoO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4d0kukaigtekdby1yrtn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WV51tJoO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4d0kukaigtekdby1yrtn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each iteration or cycle of Updating the Weights and the Biases is called &lt;br&gt;
&lt;strong&gt;One Training Step&lt;/strong&gt; . So Let's look what that Means for Our Data Set . &lt;/p&gt;

&lt;p&gt;When we First Start the Training , it's as if we drew a Random Line through the Data . Then , each Step of the Training Progresses , the line moves step by step closer to Ideal Separation Between Wine and Beer Like this : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1SNpUa12--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qo3nduwd5p9dwhxw3n14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1SNpUa12--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qo3nduwd5p9dwhxw3n14.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the Training is Completed , it's time to see if the Model is Any Good . We do so by doing &lt;strong&gt;Evaluation&lt;/strong&gt; . This is the Step where the Data Set that we set aside Earilier for Evaluation Comes into Play . &lt;strong&gt;Evaluation allows us to test Our Model Against Data that has Never Been Used Before&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;This is a Representative of How the Model Might Perform in the Real World &lt;/p&gt;

&lt;p&gt;Once we have done the Evalution , it's possible if we want to see if we can further improve our Training in Any Way . We can do so by tuning some Of Our Parameters which is known as &lt;strong&gt;PARAMETER TUNING&lt;/strong&gt; .&lt;/p&gt;

&lt;p&gt;So Summing up this Article , Machine Learning is an Interesting Way of Answering Questions from Our Data . &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I hope you Liked my Article , and it was able to provide some Value to You&lt;/strong&gt; . &lt;/p&gt;

&lt;p&gt;Signing Off for Now :D , &lt;/p&gt;

&lt;p&gt;Connect with Me On LinkedIn : &lt;a href="https://www.linkedin.com/in/deepanshu-arora-a87846132/"&gt;https://www.linkedin.com/in/deepanshu-arora-a87846132/&lt;/a&gt; &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introduction to AI at the Edge — A Beginner’s Perspective</title>
      <dc:creator>Deepanshu Arora </dc:creator>
      <pubDate>Wed, 18 Dec 2019 11:17:47 +0000</pubDate>
      <link>https://forem.com/deepansharora27/introduction-to-ai-at-the-edge-a-beginner-s-perspective-9ig</link>
      <guid>https://forem.com/deepansharora27/introduction-to-ai-at-the-edge-a-beginner-s-perspective-9ig</guid>
      <description>&lt;p&gt;Before we jump on to Talk About , Edge Computing and AI at the Whole , let’s first talk about the Internet of Things Platform and its Relation with Cloud , so that we can derive differences between the Cloud Computing Platform and Edge Computing Platform .&lt;/p&gt;

&lt;p&gt;Let’s first Talk About the Layman Meaning of Internet of Things . If we look up in the Dictionary , IoT is defined as Follows :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interconnection of Computing Devices embedded in Everyday Things via the Internet&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Essentially , it is everyday things connected to the Internet and hence , Internet of Things . Now , in this Path of Interconnection there are 3 interacting Units :&lt;/p&gt;

&lt;p&gt;1).There is a Network of Objects that Connected Wired or Wirelessly to the Internet , and these Objects can be anything ranging from Appliances , Cars etc&lt;/p&gt;

&lt;p&gt;2).Next , there are Gateways with access bridges between these Devices and the Internet .&lt;/p&gt;

&lt;p&gt;3).And , the Final thing is the Cloud where we want to store the Information which we are receiving from the Devices for processing it and then analyzing it to Derive Intelligence .&lt;/p&gt;

&lt;p&gt;Now , the Data that is being Generated by these IoT Devices is increasing Exponentially , and the Cloud Platform is not sufficient enough to store this Data . So , we need a substitute for this to combat this problem .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now , here comes in play the Edge Computing Platform . There is an emergent need for running Local Services close to the Devices itself , to the Edge Devices itself .&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now , lets dwell into What do we mean by this Term “Intelligence at the Edge” . Let’s take some Example Use Cases :&lt;/p&gt;

&lt;p&gt;Suppose you have a Camera pointed at your Parking Lot , where you are using the Camera to count in Real Time , the number of Cars that are Parked in the Parking Lot . It isn’t really cost effective and it doesn’t make any sense to send every frame of the Video from the Camera to Cloud to Analyze and count the Number of Cars that are Parked in the Parking Lot .&lt;/p&gt;

&lt;p&gt;What if we could do it in the Camera itself ?&lt;/p&gt;

&lt;p&gt;If you are using Object Detection using your Camera . For Privacy Reasons , you may not want to send your Data to the Cloud , but you would want to run some of those analyses and intelligence on the Device itself .&lt;/p&gt;

&lt;p&gt;So these above two reasons are the major reasons for Using Intelligence at the Edge .&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
