<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ragul P on Medium]]></title>
        <description><![CDATA[Stories by Ragul P on Medium]]></description>
        <link>https://medium.com/@ragulp14032000?source=rss-2a5d6af260ef------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GcJS8T0RdKqmW5fs</url>
            <title>Stories by Ragul P on Medium</title>
            <link>https://medium.com/@ragulp14032000?source=rss-2a5d6af260ef------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:36:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ragulp14032000/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Episode — 14 | Building Feed API & Pagination:-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-14-building-feed-api-pagination-ce71be16556a?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce71be16556a</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Sat, 14 Nov 2026 02:50:21 GMT</pubDate>
            <atom:updated>2026-11-14T02:50:21.689Z</atom:updated>
            <content:encoded><![CDATA[<p>// user should see all the user cards expert</p><p>0. his own card<br>1. his connections<br>2. ignored people<br>3. already send the connection request</p><p>Example: Rahul = [Mark, Donald, MS Dhoni, Virat];<br>Rahul -&gt; Akshay -&gt; Rejected<br>Rahul -&gt; Elon -&gt; Accepted<br>[Mark, Donald, MS Dhoni, Virat]</p><pre> const loggedInUser = req.user;<br><br>     const connectionRequests = await ConnectionRequest.find({<br>      $or: [{ fromUserId: loggedInUser._id }, { toUserId: loggedInUser._id }],<br>    }).select(&quot;fromUserId  toUserId&quot;);<br><br>    const hideUsersFromFeed = new Set();<br>    connectionRequests.forEach((req) =&gt; {<br>      hideUsersFromFeed.add(req.fromUserId.toString());<br>      hideUsersFromFeed.add(req.toUserId.toString());<br>    });<br><br>    const users = await User.find({<br>      $and: [<br>        { _id: { $nin: Array.from(hideUsersFromFeed) } },<br>        { _id: { $ne: loggedInUser._id } },<br>      ],<br>    }) .select(USER_SAFE_DATA);</pre><p>HomeWork:-</p><pre>- Logic for GET /feed API<br>- Explore the $nin , $and, $ne and other query operatorators<br>- Pagination</pre><p>NOTES:-<br>/feed?page=1&amp;limit=10 =&gt; 1–10 =&gt; .skip(0) &amp; .limit(10)<br>/feed?page=2&amp;limit=10 =&gt; 11–20 =&gt; .skip(10) &amp; .limit(10)<br>/feed?page=3&amp;limit=10 =&gt; 21–30 =&gt; .skip(20) &amp; .limit(10)<br>/feed?page=4&amp;limit=10 =&gt; 21–30 =&gt; .skip(20) &amp; .limit(10)</p><p>skip = (page-1)*limit;<br>const page = parseInt(req.query.page) || 1;<br>let limit = parseInt(req.query.limit) || 10;<br>limit = limit &gt; 50 ? 50 : limit;<br>const skip = (page — 1) * limit;</p><p>.skip(skip)<br>.limit(limit);</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce71be16556a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode — 13 | ref, Populate & Thought process of writing APIs:-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-13-ref-populate-thought-process-of-writing-apis-e4292a06197f?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4292a06197f</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Sat, 14 Nov 2026 02:48:20 GMT</pubDate>
            <atom:updated>2026-11-14T02:48:20.844Z</atom:updated>
            <content:encoded><![CDATA[<pre>requestRouter.post(<br>  &quot;/request/review/:status/:requestId&quot;,<br>  userAuth,<br>  async (req, res) =&gt; {<br>    try {<br>      const loggedInUser = req.user;<br>      const { status, requestId } = req.params;<br><br>      const allowedStatus = [&quot;accepted&quot;, &quot;rejected&quot;];<br>      if (!allowedStatus.includes(status)) {<br>        return res.status(400).json({ messaage: &quot;Status not allowed!&quot; });<br>      }<br><br>      const connectionRequest = await ConnectionRequest.findOne({<br>        _id: requestId,<br>        toUserId: loggedInUser._id,<br>        status: &quot;interested&quot;,<br>      });<br>      if (!connectionRequest) {<br>        return res<br>          .status(404)<br>          .json({ message: &quot;Connection request not found&quot; });<br>      }<br><br>      connectionRequest.status = status;<br><br>      const data = await connectionRequest.save();<br><br>      res.json({ message: &quot;Connection request &quot; + status, data });<br>    } catch (err) {<br>      res.status(400).send(&quot;ERROR: &quot; + err.message);<br>    }<br>  }<br>);</pre><p>HomeWork:-</p><pre>- Write code with proper validations for POST /request/review/:status/:requestId<br>- Thought process - POST vs GET</pre><pre>src/models/connectionRequest.js<br><br> fromUserId: {<br>      type: mongoose.Schema.Types.ObjectId,<br>      ref: &quot;User&quot;,<br>      required: true,<br>    },<br>     toUserId: {<br>      type: mongoose.Schema.Types.ObjectId,<br>      ref: &quot;User&quot;,<br>      required: true,<br>    }<br><br><br><br><br><br>src/routes/user.js<br>    const connectionRequests = await ConnectionRequest.find({<br>      toUserId: loggedInUser._id,<br>      status: &quot;interested&quot;,<br>    }).populate(&quot;fromUserId&quot;, USER_SAFE_DATA);<br>    // }).populate(&quot;fromUserId&quot;, [&quot;firstName&quot;, &quot;lastName&quot;]);<br><br>    </pre><p>HomeWork:-</p><pre>- Create GET /user/requests/received with all the checks    </pre><pre><br>// Get all the pending connection request for the loggedIn user<br>userRouter.get(&quot;/user/requests/received&quot;, userAuth, async (req, res) =&gt; {<br>  try {<br>    const loggedInUser = req.user;<br><br>    const connectionRequests = await ConnectionRequest.find({<br>      toUserId: loggedInUser._id,<br>      status: &quot;interested&quot;,<br>    }).populate(&quot;fromUserId&quot;, USER_SAFE_DATA);<br>    // }).populate(&quot;fromUserId&quot;, [&quot;firstName&quot;, &quot;lastName&quot;]);<br><br>    res.json({<br>      message: &quot;Data fetched successfully&quot;,<br>      data: connectionRequests,<br>    });<br>  } catch (err) {<br>    req.statusCode(400).send(&quot;ERROR: &quot; + err.message);<br>  }<br>});</pre><pre><br>userRouter.get(&quot;/user/connections&quot;, userAuth, async (req, res) =&gt; {<br>  try {<br>    const loggedInUser = req.user;<br><br>    const connectionRequests = await ConnectionRequest.find({<br>      $or: [<br>        { toUserId: loggedInUser._id, status: &quot;accepted&quot; },<br>        { fromUserId: loggedInUser._id, status: &quot;accepted&quot; },<br>      ],<br>    })<br>      .populate(&quot;fromUserId&quot;, USER_SAFE_DATA)<br>      .populate(&quot;toUserId&quot;, USER_SAFE_DATA);<br><br>    console.log(connectionRequests);<br><br>    const data = connectionRequests.map((row) =&gt; {<br>      if (row.fromUserId._id.toString() === loggedInUser._id.toString()) {<br>        return row.toUserId;<br>      }<br>      return row.fromUserId;<br>    });<br><br>    res.json({ data });<br>  } catch (err) {<br>    res.status(400).send({ message: err.message });<br>  }<br>});</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4292a06197f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode — 12 | Logical DB Query & Compound Indexes:-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-12-logical-db-query-compound-indexes-10089c03d6e2?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/10089c03d6e2</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Sat, 14 Nov 2026 02:46:16 GMT</pubDate>
            <atom:updated>2026-11-14T02:46:16.797Z</atom:updated>
            <content:encoded><![CDATA[<p>1.</p><pre>src/models/conneectionRequest.js<br><br>const mongoose = require(&quot;mongoose&quot;);<br><br>const connectionRequestSchema = new mongoose.Schema(<br>  {<br>    fromUserId: {<br>      type: mongoose.Schema.Types.ObjectId,<br>      ref: &quot;User&quot;,<br>      required: true,<br>    },<br>    toUserId: {<br>      type: mongoose.Schema.Types.ObjectId,<br>      ref: &quot;User&quot;,<br>      required: true,<br>    },<br>    status: {<br>      type: String,<br>      required: true,<br>      enum: {<br>        values: [&quot;ignored&quot;, &quot;interested&quot;, &quot;accepted&quot;, &quot;rejected&quot;],<br>        message: `{VALUE} is incorrect status type`,<br>      },<br>    },<br>  },<br>  { timestamps: true }<br>);<br><br><br>const ConnectionRequestModel = new mongoose.model(<br>  &quot;ConnectionRequest&quot;,<br>  connectionRequestSchema<br>);<br><br>module.exports = ConnectionRequestModel;<br><br></pre><p>2.</p><pre>requestRouter.post(<br>  &quot;/request/send/:status/:toUserId&quot;,<br>  userAuth,<br>  async (req, res) =&gt; {<br>    try {<br>      const fromUserId = req.user._id;<br>      const toUserId = req.params.toUserId;<br>      const status = req.params.status;<br><br>      const allowedStatus = [&quot;ignored&quot;, &quot;interested&quot;];<br>      if (!allowedStatus.includes(status)) {<br>        return res<br>          .status(400)<br>          .json({ message: &quot;Invalid status type: &quot; + status });<br>      }<br><br>      const toUser = await User.findById(toUserId);<br>      if (!toUser) {<br>        return res.status(404).json({ message: &quot;User not found!&quot; });<br>      }<br><br>      const existingConnectionRequest = await ConnectionRequest.findOne({<br>        $or: [<br>          { fromUserId, toUserId },<br>          { fromUserId: toUserId, toUserId: fromUserId },<br>        ],<br>      });<br>      if (existingConnectionRequest) {<br>        return res<br>          .status(400)<br>          .send({ message: &quot;Connection Request Already Exists!!&quot; });<br>      }<br><br>      const connectionRequest = new ConnectionRequest({<br>        fromUserId,<br>        toUserId,<br>        status,<br>      });<br><br>      const data = await connectionRequest.save();<br><br>      res.json({<br>        message:<br>          req.user.firstName + &quot; is &quot; + status + &quot; in &quot; + toUser.firstName,<br>        data,<br>      });<br>    } catch (err) {<br>      res.status(400).send(&quot;ERROR: &quot; + err.message);<br>    }<br>  }<br>);</pre><p>3.</p><pre>connectionRequestSchema.pre(&quot;save&quot;, function (next) {<br>  const connectionRequest = this;<br>  // Check if the fromUserId is same as toUserId<br>  if (connectionRequest.fromUserId.equals(connectionRequest.toUserId)) {<br>    throw new Error(&quot;Cannot send connection request to yourself!&quot;);<br>  }<br>  next();<br>});</pre><p>4.</p><pre>// ConnectionRequest.find({fromUserId: 273478465864786587, toUserId: 273478465864786587})<br>connectionRequestSchema.index({ fromUserId: 1, toUserId: 1 });<br><br><br>index use - fast query<br>no index query - slow<br><br>User.find({firstName:&quot;ragul&quot;});<br>index:true (or) unique:true<br><br>Compount Indexs in mongoose - Docs<br><br>connectionRequestSchema.index({fromUserId:1,toUserId:1});<br>User.find({ fromUserId: 09843, toUserId: 498540 });<br><br>1 - ascending<br>-1 - descending<br><br><br>connectionRequestSchema.index({firstName:1,lastName:1});<br>User.find({ firstName: &#39;akshay&#39;, lastName: &#39;shainy&#39; });<br></pre><p>HomeWork:-</p><pre>- Create Connnection Request Schema<br>- Send Connection Request API<br>- Proper validation of Data<br>- Think about ALL corner cases<br>- $or query $and query in mongoose - https://www.mongodb.com/docs/manual/reference/operator/query-logical/<br>- schema.pre(&quot;save&quot;) function<br>- Read more about indexes in MongoDB<br>- Why do we need index in DB?<br>- What is the advantages and disadvantage of creating?<br>- Read this arcticle about compond indexes - https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound/<br>- ALWAYS THINK ABOUT CORNER CASES</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10089c03d6e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode — 11 | Diving into the APIs and express Router:-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-11-diving-into-the-apis-and-express-router-81a7729b0036?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/81a7729b0036</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Sat, 14 Nov 2026 02:43:51 GMT</pubDate>
            <atom:updated>2026-11-14T02:43:51.548Z</atom:updated>
            <content:encoded><![CDATA[<p>DevTinder APIs</p><pre>1.authRouter<br>   POST /signup<br>   POST /login<br>   POST /logout<br><br>2.profileRouter<br>   GET /profile/view<br>   PATCH /profile/edit<br>   PATCH /profile/password // Forgot password API<br><br>3.connectionRequestRouter<br>   POST /request/send/:status/:userId<br>   POST /request/review/:status/:requestId<br><br>4.userRouter<br>   GET /user/requests/received<br>   GET /user/connections<br>   GET /user/feed - Gets you the profiles of other users on platform<br>Status: ignored, interested, accepeted, rejected</pre><p>Express Router — Docs</p><p>HomeWork:-</p><pre>- Explore tinder APIs<br>- Create a list all API you can think of in Dev Tinder<br>- Group multiple routes under repective routers</pre><pre>Folder : src/routes<br>         auth.js<br>         profile.js<br>         request.js</pre><pre>const express = require(&#39;express&#39;);<br>const router = express.Router();<br><br>module.export = router;<br><br>app.js<br><br>    app.use(&#39;/&#39;,authRouter);</pre><p>HomeWork:-</p><pre>- Read documentation for express.Router<br>- Create routes folder for managing auth,profile, request routers<br>- create authRouter, profileRouter, requestRouter<br>- Import these routers in app.js</pre><pre>app.post(&#39;/logout&#39;,(req,res)=&gt;{<br>    res.cookie(&#39;token&#39;,null,{<br>        expires: new Date(Date.now())<br>    });<br>    res.send();<br>});</pre><pre>validation.js:-<br>const validateEditProfileData = (req) =&gt;{<br>    const allowdEditFields = [&#39;firstName&#39;,&#39;lastName&#39;,&#39;emailId&#39;,&#39;photoUrl&#39;,&#39;gender&#39;,&#39;age&#39;,&#39;about&#39;,&#39;skills&#39;];<br>    const isEditAllowed = Object.keys(req.body).every((field)=&gt;allowdEditFields.includes(field));<br>    return isEditAllowed;<br>}</pre><pre><br>app.patch(&#39;/profile/edit&#39;,userAuth, (req,res)=&gt;{<br>    if(!validateEditProfileData(req)){<br>       throw new Error(&#39;Invalid Edit Request&#39;);<br>    }<br><br>    const logedInUser = req.user;<br>    Object.keys(req.body).forEach((key)=&gt;logedInUser[key]=req.body[key]);<br>    await logedInUser.save();<br>    res.json({message:&#39;success&#39;,&#39;user update successfully&#39;});<br>});</pre><p>HomeWork:-</p><pre>- Create POST /logout API<br>- Create PATCH /profile/edit<br>- Create PATCH /profile/password API =&gt; forgot password API<br>- Make you validate all data in every POST, PATCH apis</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81a7729b0036" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode — 10 | Authentication, JWT & Cookies:-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-10-authentication-jwt-cookies-42e7804ea252?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/42e7804ea252</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 13:12:38 GMT</pubDate>
            <atom:updated>2026-11-08T13:12:38.939Z</atom:updated>
            <content:encoded><![CDATA[<pre><br><br> _______    /profile      ______<br>|       | ----------&gt;    |      |<br>|       |                |      |    connection made and close<br>|       | &lt;----------    |      |<br>|_______|                |______|<br>            data</pre><pre>User   |    GET/profile  |   Server<br>       |----------------&gt;|<br>       |&lt;------data------|<br>       |                 |<br>       |--PATCH/profile-&gt;|<br>       |&lt;--------------- |<br>       |                 |<br>       |----------------&gt;|<br>       |&lt;----------------|<br>       |                 |</pre><pre>User   |login (email,pws)|   Server<br>       |----------------&gt;|    JWT<br>       |&lt;------token-----|<br>       |                 |<br>       |-------/profile-&gt;|<br>JWT    |&lt;--------------- |<br>       |                 |<br>       |----------------&gt;|<br>       |&lt;----------------|<br>       |                 |</pre><p>Cookies</p><pre><br>User     |login (email,pws)|   Server<br>         |----------------&gt;|   validate (email,pwd) cookie inside JWT<br>         |&lt;------token-----|<br>         |                 |<br>         |-------/profile-&gt;|<br>browser  |&lt;--------------- |<br>default  |                 |<br>store    |----------------&gt;|  validate failed<br>cookie   |&lt;----------------|<br>         |                 |<br><br></pre><pre>/login<br>res.cookie(&#39;token&#39;,&#39;xyzsdkf&#39;);  // postman u see the cookie<br><br><br>/profile<br>const cookies = req.cookie;</pre><pre>npm i cookie-parser<br><br>const cookieParser = require(&#39;cookie-parser&#39;);<br>app.use(cookieParser());</pre><pre>jwt.io<br>jwt token contain 3 things { Header, Payload, Signature}<br>npm i jsonwebtoken</pre><pre><br>/login<br>const token = await jwt.sign({_id:user._id},&#39;SECRET&#39;);<br>req.cookie(&#39;token&#39;,token);<br><br><br>/profile<br>const decodeMessage = await jwt.verify(token,&#39;SECRET&#39;);<br>const {_id} = decodeMessage;<br>const user = await User.findById(_id);</pre><p>HomeWork:-</p><pre>- install cookie-parser<br>- just sent a dummy cookie to user<br>- create GET /profile API and check if you get the cookie back<br>- install jsonwebtoken<br>- In login API , after email and password validation, create a JWT token and sent into  user in cookies<br>- send the cookie inside you profile API and find the logged in user</pre><pre>auth.js<br><br>const userAuth = async (req,res,next) =&gt; {<br>try{<br>    const {token} = req.cookies;<br>    if(!token) {throw new Error (&#39;Token is not valid&#39;) }<br><br>    const decodeObj = await jwt.verify(token,&#39;SECRET&#39;);<br>    const {_id} = decodeObj;<br>    const user = await User.findById(_id);<br>    if(!user){throw new Error(&#39;User not found&#39;)};<br>    req.user = user;<br>    next();<br>}catch(err){<br>   res.status(400).send(&#39;Error : &#39;+error.message);<br>}<br>}<br><br><br><br><br>app.get(&#39;/pofile&#39;,userAuth,(req,res)=&gt;{<br>    const user = req.user;<br>    res.send(user);<br>})<br><br><br><br>app.get(&#39;/sendConnection&#39;,userAuth,(req,res)=&gt;{<br>    const user = req.user;<br>    res.send(&#39;connection successfull&#39;);<br>})<br><br></pre><p>Expire:-</p><pre>const token = await jwt.sign({_id:user._id},&#39;SECRET&#39;,{expireIn:&#39;1d&#39;});<br>req.cookie(&#39;token&#39;,token,{expire:new Date()});</pre><p>HomeWork:-</p><pre>- user Auth Middleware<br>- Add the userAuth Middleware in Profile API and new sendConnection request API<br>- set the express of JWt token and cookie  to 7 days</pre><pre>user.js<br><br><br>UserSchema.method.getJWt = function() {<br>    const user = this;<br>    jwt.sign  <br>    return token;<br>}<br><br><br>const token = await user.getJWT();<br><br><br>UserSchema.method.validatePassword = function(passwordInputByUser) {<br>   <br>}<br><br></pre><p>HomeWork:-</p><pre>- create UserSchema method for getJWT();<br>- create UserSchema method to compare password(password);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42e7804ea252" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode — 09 | Encrypting Password :-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-09-encrypting-password-eab37a9d84c3?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/eab37a9d84c3</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 13:09:06 GMT</pubDate>
            <atom:updated>2026-11-08T13:09:06.677Z</atom:updated>
            <content:encoded><![CDATA[<pre><br>src/utils/validation.js<br><br>const validateSignUpData = (req) =&gt;{<br>  const {firstName, lastName, emailId, password} = req.body;<br><br>  if(!firstName || !lastName){<br>      throw new Error(&quot;Name is not valid !&quot;);<br>  }else  if(firstName.length&lt;4 || firstName.length&gt;50){<br>      throw new Error(&quot;firstName should be 4-50 character&quot;);<br>  }else  if(!validator.isEmail(emailId)){<br>      throw new Error(&quot;Email is not valid!&quot;);<br>  }else  if(!validator.isStrongPassword(password)){<br>      throw new Error(&quot;Please enter a Strong password!&quot;);<br>  }<br>}<br><br>module.export = {validateSignUpData}</pre><pre><br>app.js<br>const { validateSignUpData } = require(&#39;./utils/validations&#39;);<br><br><br><br>&#39;/signUp&#39; {<br>    // validation of data<br>    validateSignUpData(req);<br>}<br><br>www.google.com ---&gt; bcrypt<br>$ npm i bcrypt<br><br>// Encrypt the password<br>const passwordHash = await = bcrypt.hash(password,10);</pre><p>HomeWork:-</p><pre>- Validate data in /signUp API<br>- Install bcrypt package<br>- create password hash using bcrypt.hash &amp; save the user in excripted password</pre><pre>/login<br>const {emailId, password} = req.body;<br>const user = await User.findOne({emailId:emailId});<br> if(!user){  throw new Error(&#39;EmailId  is not present in DB&#39;); }<br><br> const isPasswordValid = await bcrypt.compare(password,user.password);<br> if(isPasswordValid){  res.send(&#39;login successfull !!!&#39;); }<br> else{ throw new Error (&#39;password not correct&#39;)}<br><br><br><br> Not Explict Error<br> - Common Error Invalid Credentials</pre><p>HomeWork:-</p><pre>- Create login api<br>- compare password and throw error if email or password is invalid</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eab37a9d84c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode — 08 | Data Sanization & Schema Validations:-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-08-data-sanization-schema-validations-315e77c71d66?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/315e77c71d66</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 13:07:27 GMT</pubDate>
            <atom:updated>2026-11-08T13:07:27.020Z</atom:updated>
            <content:encoded><![CDATA[<pre>1. require:true<br>Error: Error saving the user:User validation failed<br><br><br>2.Unique:true<br>Error: duplicate key error<br><br>3.photoUrl: { type: String, default: &quot;url&quot; }<br>  about : {type:String, default:&quot; This is default&quot;};<br>  skills : {type:[String]}<br><br>4. emailId:{ lowercase:true}<br><br>5.trim:true<br><br>6.minlength:4<br><br>7.maxlength:100<br><br>8.min:18<br><br>9.gender : {<br>    validate(value){<br>       if(![&#39;male&#39;,&#39;female&#39;,&#39;others&#39;].includes(values)){<br>          throw new Error(&#39;Gender data is not valide&#39;);<br>       }<br>    }<br>}<br><br>validate method only called create time <br><br><br>update methoding<br>    User.findByIdAndUpdate({},data,{ returnDocument:&#39;after&#39;, runValidators:true });<br><br><br>10. {timestamps:true}</pre><p>HomeWork:-</p><pre>- Explore SchemaType options from the Documentation<br>- add required, unique, lowercase, min, minlength, trim<br>- add default<br>- create a custom validate function for gender<br>- Improve the DB Schema<br>- Put all appropriate validation on each field in Schema<br>- Add timestamps to the UserSchema</pre><pre>const ALLOWED_UPDATES = [&#39;photoUrl&#39;,&#39;about&#39;,&#39;gender&#39;,&#39;age&#39;,&#39;skills&#39;];<br>const isUpdateAllowed = Object.keys(data).every((k)=&gt; ALLOWED_UPDATES.includes(k));<br><br>if(!isUpdateAllowed){ throw new Error(&#39;Update not allowed&#39;)};<br>if(data.skills.length&gt;10){ throw new Error(&#39;Skills cannot be more than 10&#39;)};</pre><p>HomeWork:-</p><pre>- Add API level validation on Data request &amp; SignUp Post API<br>- Add API validation for each field - Data Sanization</pre><p><a href="http://www.google.com/">www.google.com</a> — -&gt; npm validator</p><pre>$ npm i validator<br><br><br>const validator = require(&#39;validator&#39;);<br><br>emailId :{<br>    validate(value){<br>        if(!validator.isEmail(value)){<br>           throw new Error(&#39;Invalid email address&#39;+ value);<br>        }<br>    }<br>}<br><br><br>photoUrl:{<br>        validate(value){<br>        if(!validator.isUrl(value)){<br>           throw new Error(&#39;Invalid url&#39;+ value);<br>        }<br>    }<br>}<br><br><br>password:{<br>        validate(value){<br>        if(!validator.isStrongPassword(value)){<br>           throw new Error(&#39;Invalid password&#39;+ value);<br>        }<br>    }<br>}</pre><p>HomeWork:-</p><pre>- Install validator<br>- use validator function for password, email, photoUrl<br>- Explore validator library function<br>- never trust req.body</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=315e77c71d66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode — 07 | Diving into the APIs:-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-07-diving-into-the-apis-b1a9557193b1?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1a9557193b1</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 13:05:30 GMT</pubDate>
            <atom:updated>2026-11-08T13:05:30.169Z</atom:updated>
            <content:encoded><![CDATA[<p>before JSON → XML used</p><p>Postman :-</p><pre>POST -&gt; http://localhost:7777/signup<br>Body -&gt; raw -&gt; JSON <br>{<br>    &#39;firstName&#39;:&#39;MS&#39;,<br>    &#39;lastName&#39;:&#39;Dhoni&#39;<br>}</pre><p>HomeWork:-</p><pre>   - JS Object vs JSON (difference between)<br>   JSON - key, value, as string</pre><pre>   JSON ---&gt; req.body   ---&gt; undefined<br>        ---&gt; middleware ---&gt; Javascript Object<br><br><br>app.use(express.json());   // run of every request<br><br>new User(req.body);</pre><p>HomeWork:-</p><pre>- Add the express.json middleware to your app<br>- Make you signUp API dynamic to receive data from the end user</pre><pre><br>Feed API - GET /feed - get all the user from the data base<br><br>app.get(&#39;/feed&#39;,(req,res)=&gt;{<br><br>});<br><br>DB always Promise use async/ awit, try catch block{ }<br><br>app.get(&#39;/user&#39;,async(req,res)=&gt;{<br><br>   const userEmail = req.body.emailId;<br>   try{<br>       const users = awit User.find({emailId:userEmailId});<br>       if(users.length===0){<br>          res.status(404).send(&quot;user not found&quot;);<br>        }<br>       }catch(err){<br>          return res.status(400).send(&#39;sometimes went wrong&#39;);<br>   }<br><br>});<br><br><br>app.get(&#39;/feed&#39;,async(req,res)=&gt;{<br><br>   try{<br>       const users = awit User.find();<br>          res.send(users);<br>       } catch(err){<br>          return res.status(400).send(&#39;sometimes went wrong&#39;);<br>   }<br><br>});<br><br><br>findOne({emailId:req.body.emailId});<br><br></pre><p>HomeWork:-</p><pre>- user.findOne with duplicate email ids which object returned<br>- API get user by email<br>- API - Feed API - GET /feed-get-all the users from the database<br>- API - Got user by ID</pre><pre>app.delete(&#39;/user&#39;,async(req,res)=&gt;{<br>   const userId = req.body.userId;<br>   try{<br>       const users = awit User.findbyIdAndDelete(id);<br>          res.send(users);<br>       } catch(err){<br>          return res.status(400).send(&#39;sometimes went wrong&#39;);<br>   }<br><br>});</pre><p>HomeWork:-</p><pre>- create a delete use API call<br>- Different B/W PATCH and PUT</pre><pre>app.patch(&#39;/user&#39;,async(req,res)=&gt;{<br>   const userId = req.body.userId;<br>   const data = req.body;<br>   try{<br>           awit User.findbyIdAndUpdate({_id:userd},data);<br>           res.send(&quot;user update successfully&quot;);<br>       } catch(err){<br>          return res.status(400).send(&#39;sometimes went wrong&#39;);<br>   }<br><br>});<br><br><br>options:-<br>          awit User.findbyIdAndUpdate({_id:userd},data,{<br>            returnDocument : &quot;before&quot;<br>          });</pre><p>HomeWork:-</p><pre>- API  update user<br>- Explore the mongoose document for module and methods<br>- what are options in a model.findOne and update model, explore more about it<br>- API update the user with emailID</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1a9557193b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode — 06 | Databse, Schema & Models | Mongoose:-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-06-databse-schema-models-mongoose-630b3e0e4ebf?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/630b3e0e4ebf</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 13:01:49 GMT</pubDate>
            <atom:updated>2026-11-08T13:01:49.537Z</atom:updated>
            <content:encoded><![CDATA[<p>Folder — src/config/database.js</p><p>google -&gt; mongoose -&gt; refer Docs</p><pre>$ npm i mongoose<br><br>const mongoose = require(&#39;mongoose&#39;);<br>const connectDB = async() =&gt;{<br>    await mongoose.connect(&#39;url/devTinder&#39;);<br>}<br><br>connectDB().then(()=&gt;{<br><br>}).catch(err=&gt;{<br><br>});<br><br>module.exports = connectDB;<br><br>app.js<br>const connectDB = require(&#39;./config/database&#39;);   // inside server connect<br><br>step<br>1. connect database<br>2. connect server</pre><p>HomeWork:-</p><pre>- create a free cluster on MongoDB official website (Mongo Atlas)<br>- Install mongoose library<br>- Connect your application to the Database &lt;&#39;connection_url&#39;/devTinder&gt;<br>- call the connect DB function and connect to database before status application on 7777<br>- Refer docs mongoose schema</pre><pre>src/models/user.js<br><br>const mongoose = require(&#39;mongoose&#39;);<br>const userSchema = new mongoose.Schema({first_name:{<br>    type:String<br>}});<br><br>const User = Mongoose.model(&quot;User&quot;,userSchema);<br>module.exports = User;<br><br>- capital letter like Model<br>- (or) directly export<br><br>HomeWork:-<br>- Create a user Schema &amp; userModel<br><br>app.post(&#39;/signup&#39;,(req,res)=&gt;{<br>    const userObj = {<br>        firstName : &#39;Akshay&#39;,<br>        lastName : &#39;Saini&#39;,<br>        emailId : &#39;akshay@saini.com&#39;,<br>        password : &#39;akshay@123&#39;<br>    }</pre><pre>// Creating a new instance of the User Model<br>const user = new User(userObj);<br><br>try{<br>    await user.save();<br>    res.send(&#39;user added successfully&#39;);<br>} catch(err){<br> console.log(err);<br>}<br><br>})</pre><p>hit api postman</p><pre> mongodb created default<br>{<br>    _id<br>    __v:0  (update maintain version of data )<br>}</pre><p>HomeWork:-</p><pre>- create /signup API to add to database<br>- Push some document using API calls from postman</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=630b3e0e4ebf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode — 05 | Middleware & Error Handlers:-]]></title>
            <link>https://medium.com/@ragulp14032000/episode-05-middleware-error-handlers-1a1c5878ad26?source=rss-2a5d6af260ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a1c5878ad26</guid>
            <dc:creator><![CDATA[Ragul P]]></dc:creator>
            <pubDate>Fri, 06 Nov 2026 13:57:33 GMT</pubDate>
            <atom:updated>2026-11-06T13:57:33.613Z</atom:updated>
            <content:encoded><![CDATA[<pre>app.use(&#39;/user&#39;); // use method handle all request GET,POST,PATCH<br>app.get(&#39;/user);<br>app.post(&#39;/user&#39;);<br><br>app.use(&#39;/user&#39;,()=&gt;{<br>    //empty --&gt;  infinite Request Send<br>});<br><br><br>app.use(&#39;/user&#39;,(req,res)=&gt;{<br> res.send(&#39;Response&#39;);   // if commend this line infinite loop not send response<br>},(req,res)=&gt;{<br> res.send(&#39;2nd Response&#39;);<br>});<br><br><br>app.use(&#39;/user&#39;,(req,res,next)=&gt;{<br> res.send(&#39;Response&#39;);   // if commend this line infinite loop not send response<br> next();<br>},(req,res)=&gt;{<br> res.send(&#39;2nd Response&#39;);<br>});</pre><p>Uncomment :-<br> Error : Cannot sent header after they are send to the client</p><pre>next();<br>res.send(&#39;Response 1&#39;);<br>res.send(&#39;Response 2&#39;);<br><br><br>Adding Multiple Route Handlers:-<br>1<br>2<br>3<br>4<br>5 -&gt; last put next();  <br><br>it throw error cannot get<br>// comment next(); it hanging</pre><pre>app.use(&#39;/route&#39;,rH,rH2,rH3,rH4,rH5);<br>app.use(&#39;/route&#39;,[rH,rH2,rH3,rH4,rH5]);<br>app.use(&#39;/route&#39;,[rH4]);</pre><p>HomeWork:-</p><pre>- Multiple Route Handlers - Play with the code<br>- next()<br>- next function and error alow with res send()<br>- app.use(&quot;/route&quot;,rH,[rH2,rH3,rH4,rH5]);<br>- what is middleware<br>- How express it basically handles request behind the scenes</pre><pre>app.get(&#39;/user&#39;); next();<br>app.get(&#39;/user&#39;); next();<br><br>Error : cannot get<br><br>app.use(&#39;/&#39;); handle all the request<br><br>// GET  /users =&gt; It checks all the  app.xxx(&#39;matching route&#39;) function;<br>// GET  /users =&gt; middleware chain =&gt; request handler<br><br>Good http -&gt; status code</pre><pre>/admin/getAllData<br>const token = &#39;xyz&#39;;<br>const isAdminAuthorized = token === &#39;xyz&#39;;<br>if(isAdminAuthorized){<br>    res.send(&#39;All Data Send&#39;);<br>}else{<br>     res.status(401).send(&#39;Unauthorized request&#39;);<br>}<br><br><br>// Handle Auth Middleware for only GET requests GET, POST</pre><p>HommeWork:-<br> — Difference app.use and app.all</p><pre><br> app.use(&#39;/admin&#39;,(req,res)=&gt;{                      ----&gt; only called /admin<br>    const token = &#39;xyz&#39;;<br>const isAdminAuthorized = token === &#39;xyz&#39;;<br>if(isAdminAuthorized){<br>    res.send(&#39;All Data Send&#39;);<br>}else{<br>     next();<br>}<br> });</pre><p>Folder — utils/middlewares/auth.js</p><pre><br> module.export const 1.adminAuth = () =&gt;{}<br> module.export const 2.userAuth = () =&gt;{}<br><br>const {adminAuth} = require(&#39;./middleware/auth&#39;);</pre><p>HomeWork:-</p><pre>- write a dummy auth middleware for admin<br>- write a dummy auth middleware for all user route, expt /user/login</pre><pre>app.get(&#39;/getUserData&#39;,(req,res)=&gt;{<br>throw new Error(&#39;auth&#39;);<br>});<br><br>app.use(&#39;/&#39;,(err,req,res,next)=&gt;{<br>  if(err){<br>     res.status(500).send(&#39;something went wrong&#39;);<br>  }<br>});<br><br>use <br>try{<br><br>} catch(err){<br>   res.status(500).send(&#39;sending error&#39;);<br>}</pre><p>HomeWork:-<br>- error Hadling app.use(‘/’,err,req,res,next);</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a1c5878ad26" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>