<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dezina</title>
    <description>The latest articles on DEV Community by Dezina (@dezforb).</description>
    <link>https://dev.to/dezforb</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%2F364578%2Fdf098004-eb70-4875-964d-777dc0f914bc.jpg</url>
      <title>DEV Community: Dezina</title>
      <link>https://dev.to/dezforb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dezforb"/>
    <language>en</language>
    <item>
      <title>Install Redis On Windows 11</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Tue, 12 Dec 2023 15:55:27 +0000</pubDate>
      <link>https://dev.to/dezforb/install-redis-on-windows-11-4p5d</link>
      <guid>https://dev.to/dezforb/install-redis-on-windows-11-4p5d</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.youtube.com/watch?v=DLKzd3bvgt8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Postgres with typeorm</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Tue, 12 Dec 2023 07:06:34 +0000</pubDate>
      <link>https://dev.to/dezforb/postgres-with-typorm-1o10</link>
      <guid>https://dev.to/dezforb/postgres-with-typorm-1o10</guid>
      <description>&lt;p&gt;&lt;strong&gt;How to Install PostgreSQL on Windows 11&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;https://www.youtube.com/watch?v=IYHx0ovvxPs&amp;amp;t=321s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Difference between display:none and visiblity: hidden</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Wed, 27 Sep 2023 10:12:26 +0000</pubDate>
      <link>https://dev.to/dezforb/difference-between-displaynone-and-visiblity-hidden-1fak</link>
      <guid>https://dev.to/dezforb/difference-between-displaynone-and-visiblity-hidden-1fak</guid>
      <description>&lt;p&gt;visibility:hidden hides the element, but it still takes up space in the layout.&lt;/p&gt;

&lt;p&gt;display:none removes the element from the document. It does not take up any space.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/css/tryit.asp?filename=trycss_display"&gt;https://www.w3schools.com/css/tryit.asp?filename=trycss_display&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Enable and disable APIs - API Console</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Tue, 19 Sep 2023 13:23:48 +0000</pubDate>
      <link>https://dev.to/dezforb/enable-and-disable-apis-api-console-57g4</link>
      <guid>https://dev.to/dezforb/enable-and-disable-apis-api-console-57g4</guid>
      <description>&lt;p&gt;&lt;a href="https://support.google.com/googleapi/answer/6158841?hl=en"&gt;https://support.google.com/googleapi/answer/6158841?hl=en&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Go crazy with react.js</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Mon, 24 Apr 2023 08:03:51 +0000</pubDate>
      <link>https://dev.to/dezforb/all-about-reactjs-4l63</link>
      <guid>https://dev.to/dezforb/all-about-reactjs-4l63</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;public &amp;amp; private routes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://stackoverflow.com/questions/69923420/how-to-use-private-route-in-react-router-domv6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;stripe payment with api&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.jsmount.com/react-js-stripe-payment-gateway-integration-with-node-step-by-step-guide/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;convert html to pdf&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://pspdfkit.com/blog/2022/how-to-convert-html-to-pdf-using-react/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;React useState Hook Typescript&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://codedamn.com/news/reactjs/usestate-hook-typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;React.Js - Typescript how to pass an array of Objects as props?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://stackoverflow.com/questions/72713498/react-js-typescript-how-to-pass-an-array-of-objects-as-props#:~:text=You%20can%20just%20replace%20props,from%20there%20in%20your%20UserIListtem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Dates conversion&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{Intl.DateTimeFormat("en").format(new Date(2023-04-28T06:07:41.065Z))}
Output: 4/28/2023
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Express application generator</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Mon, 27 Mar 2023 11:02:12 +0000</pubDate>
      <link>https://dev.to/dezforb/express-application-generator-2aoe</link>
      <guid>https://dev.to/dezforb/express-application-generator-2aoe</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Create a folder &amp;amp; in the terminal enter 
npx express-generator&lt;/li&gt;
&lt;li&gt;next install dependencies by npm i&lt;/li&gt;
&lt;li&gt;Make sure that node.js is installed&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>express</category>
      <category>server</category>
    </item>
    <item>
      <title>Javascript interview preparations</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Thu, 25 Aug 2022 13:10:00 +0000</pubDate>
      <link>https://dev.to/dezforb/javascript-interview-preparations-1eg</link>
      <guid>https://dev.to/dezforb/javascript-interview-preparations-1eg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;There are thousands of self-taught JavaScript programmers looking for web development positions. Unfortunately, self-learning or training classes, often leaves gaps in people’s understanding of the language itself. The problem is that questions testing your understanding of JS are exactly what many tech companies ask in their interviews. Some many know to do coding, but lack a solid grasp of the language. Just writing the some important concepts of js.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Shallow clone(copy) &amp;amp; deep clone(copy)&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;Shallow copy
copy the original object into the clone object then the clone object has the copy of the memory address of the original object. Means both points to the same memory address. A shallow copy means once we make changes in the clone object it will be reflected back to the original object as well.
_code:_
var obj1 = {
    id: 1,
    company: "GFG"
};
var obj2 = obj1;
obj2.id = 2;
console.log(obj1.id);
console.log(obj2.id);
_output:_
2
2

Deep copy
But in the case of deep copy, changing the value of the cloned object will not reflect into the original object, because the original object has its own reference object and after cloning, the cloned object has its own referenced object. Both are different.
_code:_
var student1 ={ 
    name : "Manish",
    company : "Gfg"

    }
    var student2 =  { ...student1 } ;
    student1.name = "Rakesh"
    console.log("student 1 name is",student1.name)
    console.log("student 2 name is ",student2.name);
_output_
student 1 name is Rakesh
student 2 name is  Manish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Events&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;Browser events
Js events
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Value vs. Reference&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Scope&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Hoisting&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Closures&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;this&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;new&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;apply, call, bind&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Prototypes &amp;amp; Inheritance&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Asynchronous JS&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Higher Order Functions&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React js &amp; material UI</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Thu, 30 Jun 2022 04:08:58 +0000</pubDate>
      <link>https://dev.to/dezforb/react-js-material-ui-1418</link>
      <guid>https://dev.to/dezforb/react-js-material-ui-1418</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. Link&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;**Parent component**
import { Link } from 'react-router-dom'

&amp;lt;Link
                              to={{
                                pathname: "/dashboard/selectmapsubjctefaculaty",
                                state: { row }
                              }}
                            &amp;gt;
                              &amp;lt;Button
                                size='small'
                                className='mr-1 fullWidth'
                                color="secondary"
                                variant='contained'
                                sx={{ width: "100%", p: "0.1em", borderRadius: "2px" }}
                              &amp;gt;Assign Faculty&amp;lt;/Button&amp;gt;&amp;lt;/Link&amp;gt;

**Child component**

import { useLocation } from 'react-router-dom/cjs/react-router-dom.min'

 const location = useLocation()

  let subject = location.state.row

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. MUI Autocomplete&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;import { Autocomplete, Box, TextField } from '@mui/material'
import React, { Fragment, useState } from 'react'
import styled from '@emotion/styled';

 const _handleInputChange = (e, data) =&amp;gt; {
    if (e.target.value.length &amp;gt; 3) {
      GET_SEARCH_STUDENT(e.target.value)
    }
  }
  const _handleChnage = async (e, value) =&amp;gt; {
    let res = await GET_STUDENT_DETAILS(value?.id)
    setStudentDetails(res)
  }
  const _handleAddFee = () =&amp;gt; {
    setAddFeeType(!AddFeeType)
  }

  &amp;lt;Autocomplete
        sx={{ boxShadow: 4 }}
        id="auto-com"
        options={searchStudent}
        renderInput={params =&amp;gt; (
          &amp;lt;StyledInputBase {...params} label="Search student" /&amp;gt;
        )}
        getOptionLabel={option =&amp;gt; `${option?.firstname} ${option?.lastname} ${option?.phone}`}
        style={{ boxShadow: 3 }}
        onChange={(e, newvalue) =&amp;gt; {
          _handleChnage(e, newvalue)
        }}
        onInputChange={handleInputChange}
      /&amp;gt;


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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>How easy to deploy your app on vercel</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Sun, 17 Apr 2022 07:56:37 +0000</pubDate>
      <link>https://dev.to/dezforb/how-easy-to-deploy-your-app-on-vercel-pem</link>
      <guid>https://dev.to/dezforb/how-easy-to-deploy-your-app-on-vercel-pem</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Deploying app to vercel&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Login to vercel by git account signup&lt;/li&gt;
&lt;li&gt;Go to &lt;a href="https://vercel.com/dashboard"&gt;https://vercel.com/dashboard&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Click on Create new project button on top right&lt;/li&gt;
&lt;li&gt;Import git repository, (where you have to push your code excluding the node_modules folder)&lt;/li&gt;
&lt;li&gt;After importing the git repo of your application, click on Import&lt;/li&gt;
&lt;li&gt;Next click on Deploy. (Note – It will take few minutes)&lt;/li&gt;
&lt;li&gt;Once deployed, click on the app image on left side to view&lt;/li&gt;
&lt;li&gt;To edit the domain, click on domains &amp;amp; edit your domain&lt;/li&gt;
&lt;li&gt;Thankyou &amp;amp; enjoy&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>nextjs</category>
      <category>vercel</category>
      <category>deployment</category>
      <category>easy</category>
    </item>
    <item>
      <title>JS problems</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Tue, 01 Feb 2022 10:18:44 +0000</pubDate>
      <link>https://dev.to/dezforb/js-problems-5da9</link>
      <guid>https://dev.to/dezforb/js-problems-5da9</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. How to add array to an object&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;&amp;lt;script&amp;gt;
// JavaScript program to add array into
// an object using push() function

// Creating a JS object to add array into
var Obj = {         
    arrayOne: ['Geeks', 'for', 'Geeks'],
    arrayTwo: []
};

// Array to be inserted
var arraynew = ['Hello', 'World', '!!!'];

// Pushing of array into arrayTwo
Obj['arrayTwo'].push(arraynew); 

alert(Obj.arrayTwo);

&amp;lt;/script&amp;gt;                   

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Add &amp;amp; Delete dynamic input fields&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 inputArr = [
    {
      type: "time",
      id: 1,
      value: "",

    }
  ];

const [field, setField] = useState(inputArr);
const [tempfield, setTempfield] = useState("");

// Add input field
const addInputField = (e) =&amp;gt; {
    e.preventDefault();

      setField(s =&amp;gt; {
        const lastId = s[s.length - 1].id;
        const nextId = lastId + 1;
        console.log("lastId", lastId)
        return [
          ...s,
          {
            type: "time",
            id: nextId,
            value: tempfield
          }
        ];
      });
}

 // Delete the input field
  const deleteField = (fieldId) =&amp;gt; {

  let filterField = field.filter(arr =&amp;gt; arr.id !== fieldId + 1)
      setField(filterField)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Checkboxes&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 [checked, setChecked] = useState(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"])

  // Add/Remove checked item from list
  const handleCheck = (event) =&amp;gt; {
    var updatedList = [...checked];
    if (event.target.checked) {
      updatedList = [...checked, event.target.value];
    } else {
      updatedList.splice(checked.indexOf(event.target.value), 1);
    }
    setChecked(updatedList);
  };

&amp;lt;div&amp;gt;
              &amp;lt;input
                className="form-check-input"
                value="Monday"
                type="checkbox"
                defaultChecked
                onChange={handleCheck} /&amp;gt;
              Monday
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Find &amp;amp; replace array object&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;// can use find or map
 let find = cartData.find((o, i) =&amp;gt; {
      if (o.product_id === pid) {
        // cartData[i] =
        //   { name: 'new string', value: 'this', other: 'that' };
        cartData[i].quantity += 1
        return true; // stop searching
      }
    });
    console.log("Replaced data", cartData)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>React hooks</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Sat, 29 Jan 2022 13:46:27 +0000</pubDate>
      <link>https://dev.to/dezforb/react-hooks-1od5</link>
      <guid>https://dev.to/dezforb/react-hooks-1od5</guid>
      <description>&lt;p&gt;Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. Hooks allow to easily manipulate the state of our functional component without needing to convert them into class components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useEffect&lt;/strong&gt;&lt;br&gt;
The first one is a callback (a function), and the second one is the dependency array. It takes the form of an array of variables. The React hooks that have dependency arrays are useEffect, useLayoutEffect, useCallback, useMemo.&lt;br&gt;
&lt;a href="https://devtrium.com/posts/dependency-arrays"&gt;https://devtrium.com/posts/dependency-arrays&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The dependency array basically tells the hook to "only trigger when the dependency array changes". &lt;br&gt;
useEffect(() =&amp;gt; {&lt;br&gt;
// this will run if &lt;code&gt;counter1&lt;/code&gt; OR &lt;code&gt;counter2&lt;/code&gt; changes&lt;br&gt;
console.log('Either counter1 or counter2 changed (or both');&lt;br&gt;
}, [counter1, counter2]);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Empty dependendy array means that the hook will only trigger once when the component is first rendered.&lt;br&gt;
useEffect(() =&amp;gt; {&lt;br&gt;
console.log('I will run only once');&lt;br&gt;
}, []);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The rule is: if any variable is used inside the hook but is defined outside of it, then it should go in the dependency array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The goal of the dependency array is to make the hook trigger when one of the values changes. There's no point putting stuff in there that won't change.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;useState&lt;/strong&gt;&lt;br&gt;
The first parameter is the state &amp;amp; second parameter is used to change/update the state using setState. useState Hook does not update immediately.&lt;br&gt;
const [count, setCounter] = useState(0);&lt;br&gt;
&lt;strong&gt;useParams()&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;The react-router-dom package has useParams hooks that let you access the parameters of the current route. This is only to get the url paramerters. URL parameters are the ones that appear before the ? in the URL.
import {useParams} from "react-router-dom";
const { jobId } = useParams();
console.log("jobId", jobId)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;useLocation&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;The useLocation hook is a function that returns the location object that contains information about the current URL. Whenever the URL changes, a new location object will be returned. It is also used to get query parameter of the url.
Location object properties:

hash: the anchor part (#)
pathname: the path name
search: the query string part
state
key
_example:_
const search = useLocation().search;
const candId = new URLSearchParams(search).get('candId');
console.log("candId", candId)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Node.js interview preparations</title>
      <dc:creator>Dezina</dc:creator>
      <pubDate>Sun, 23 Jan 2022 14:40:03 +0000</pubDate>
      <link>https://dev.to/dezforb/nodejs-interview-preparations-2f45</link>
      <guid>https://dev.to/dezforb/nodejs-interview-preparations-2f45</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Backend development
Backend refers to the server-side of an application. It generally includes a web server that communicates with a database to serve requests. Java, PHP, Python, and Node.js are some of the backend development technologies.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Node.js&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;Node.js is an open-source, cross-platform JavaScript runtime environment and library for applications written in JavaScript language. The Node.js driver uses the asynchronous Javascript API to communicate with your MongoDB cluster.

- Node.js is single-threaded for async processing. It means the web requests and processing runs on the same thread.By doing async processing on a single-thread under typical web loads, more performance and scalability.

- Asynchronous code allows the program to be executed immediately where the synchronous code will block further execution of the remaining code until it finishes the current one. This may not look like a big problem but when you see it in a bigger picture you realize that it may lead to delaying the User Interface. So it does not block the rest of the code from executing and after all the code its execution, it gets pushed to the call stack and then finally gets executed. This is what happens in asynchronous JavaScript.
Asynchronous code example: _
&amp;lt;script&amp;gt;
    document.write("Hi");
    document.write("&amp;lt;br&amp;gt;");

    setTimeout(() =&amp;gt; {
        document.write("Test");
    }, 2000);

    document.write("&amp;lt;br&amp;gt;");
    document.write("End");
    document.write("&amp;lt;br&amp;gt;");
&amp;lt;/script&amp;gt;
**Output:** 
Hi
End
Test
- Synchronous means to be in a sequence, i.e. every statement of the code gets executed one by one. So, basically a statement has to wait for the earlier statement to get executed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Promises
A Promise is an object returned by the asynchronous method call that allows you to access information on the eventual success or failure of the operation that they wrap. The Promise is in the Pending state if the operation is still running, Fulfilled if the operation completed successfully, and Rejected if the operation threw an exception. You can define your own logic that executes once the Promise reaches the Fulfilled or Rejected state by appending the then() method. When you append one or more then() methods to a Promise, each call passes its execution result to the next one. This pattern is called Promise chaining.
_Promise chaining example:_
collection.updateOne({ name: "Mount McKinley" }, { $set: { meters: 6190 } })
  .then(
    res =&amp;gt; console.log(`Updated ${res.result.n} documents`),
    err =&amp;gt; console.error(`Something went wrong: ${err}`),
  );

the catch() method which accepts a single callback, executed when the Promise transitions to the Rejected state.

_Await:_ If you are using async functions, you can use the await operator on a Promise to pause further execution until the Promise reaches either the Fulfilled or Rejected state and returns. 

- Callbacks
A callback is a method that gets called after another method has finished executing. This allows the enclosing method to continue to execute other commands until the original operation completes. A callback function is called after a given task. It allows other code to be run in the meantime and prevents any blocking.  Being an asynchronous platform, Node.js heavily relies on callback. All APIs of Node are written to support callbacks. Using callback is complex since you end up with several nested callbacks

- asynchronous and non-blocking APIs in Node.js
All Node.js library APIs are asynchronous, which means they are also non-blocking
A Node.js-based server never waits for an API to return data. Instead, it moves to the next API after calling it, and a notification mechanism from a Node.js event responds to the server for the previous API call

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;commonly used libraries in Node.js&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;ExpressJS - Express is a flexible Node.js web application framework that provides a wide set of features to develop web and mobile applications. Allows you to define routes of your application based on HTTP methods and URLs. Includes various middleware modules which you can use to perform additional tasks on request and response. Easy to integrate with different template engines like Jade, Vash, EJS etc.
Mongoose - Mongoose is basically a package that serves as a mediator between the NodeJS application and MongoDB server. It is an Object Document Mapper(ODM) that allows us to define objects with strongly-typed-schema that is mapped to a MongoDB document. Mongoose supports all the CRUD operations – Creating, Retrieving, Updating, and Deleting.
body-parser - parses your request and converts it into a format from which you can easily extract relevant information that you may need.
.env file - Its environment variables file. In simple term, it is a variable text file. In this file we set a variable with value that you wouldn’t want to share with anyone, purpose of file is keep as secret and secure because in .env file we store our database password, username, API key etc.
syntax =&amp;gt; ENV_VARIABLE=VALUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;modules in Node.js&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;In Node.js applications, modules are like JavaScript libraries and include a set of functions. To include a module in a Node.js application, we must use the require() function with the parentheses containing the module's name.

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Http (Hypertext Transfer Protocol) methods
HTTP is an asymmetric request-response client-server protocol as illustrated.  An HTTP client sends a request message to an HTTP server.  The server, in turn, returns a response message.  In other words, HTTP is a pull protocol, the client pulls information from the server (instead of server pushes information down to the client). An HTTP client sends an HTTP request to a server in the form of a request message which has a request method indicates the method to be performed on the resource identified by the given Request-URI. The method is case-sensitive and should always be mentioned in uppercase.

GET - The GET method is used to retrieve information from the given server using a given URI. Requests using GET should only retrieve data and should have no other effect on the data.

HEAD - Same as GET, but transfers the status line and header section only.

POST - A POST request is used to send data to the server, for example, customer information, file upload, etc. using HTML forms.

PUT - Replaces all current representations of the target resource with the uploaded content.

DELETE - Removes all current representations of the target resource given by a URI.

CONNECT - Establishes a tunnel to the server identified by a given URI.

OPTIONS - Describes the communication options for the target resource.

TRACE - Performs a message loop-back test along the path to the target resource.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- HTTP response
After receiving and interpreting a request message, a server responds with an HTTP response message:

1. A Status-line

2. Zero or more header

3. An empty line

4. Optionally a message-body

HTTP Status Codes
1xx: Informational
It means the request has been received and the process is continuing.
2xx: Success
It means the action was successfully received, understood, and accepted.
3xx: Redirection
It means further action must be taken in order to complete the request.
4xx: Client Error
It means the request contains incorrect syntax or cannot be fulfilled.
5xx: Server Error
It means the server failed to fulfill an apparently valid request.

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

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Node.js CRUD Operations Using Mongoose and MongoDB Atlas&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Install the mongoose and the express module through npm using the below command:

npm install express mongoose --save

Server Setup: Here, we’ll set up our server on port 3000 and call the express function that returns a server object in a variable named app. Then we start the listener saying app.listen with the port address. Finally, we create the /api route which will be triggered once request localhost:3000/api is received from the browser. 
const express=require('express');
const bodyParser=require('body-parser');
const api = require('./api');

const port=3000;
const app=express();

app.listen(port, function() {
    console.log("Server is listening at port:" + port);
});

// Parses the text as url encoded data
app.use(bodyParser.urlencoded({extended: true}));

// Parses the text as json
app.use(bodyParser.json());

app.use('/api', api);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Schema: Schema is a representation of the structure of the data. It allows us to decide exactly what data we want, and what options we want the data to have as an object.

var mongoose=require('mongoose');

var StudentSchema = new mongoose.Schema({
    StudentId:Number,
    Name:String,
    Roll:Number,
    Birthday:Date,
    Address:String
});

module.exports = mongoose.model(
    'student', StudentSchema, 'Students');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-----------------------------------------------------------
**Defining Routes using Express**
app.use("/shop", ShopRoute);
app.use('/receipts', ReceiptRoute);

When you make a request to server api, express will search for api route and execute the api

CRUD OPERATIONS

- Create: using .save() to save it to the database
router.route('/signup').post((req, res) =&amp;gt; {

    const newShop = new Shop(req.body);

    newShop.save()
        .then(() =&amp;gt; res.json('Shop created successfully.'))
        .catch(err =&amp;gt; res.status(400).json('Error : ' + err));

});

- Retrieve: To retrieve records from a database collection we make use of the .find() function.
router.route('/').get((req, res) =&amp;gt; {

    Shop.find()
        .then((Shop) =&amp;gt; { return res.json(Shop) })
        .catch(err =&amp;gt; res.status(400).json('Error: ' + err));
});

- Delete: To delete a record from database, we make use of the function .remove()
router.route('/deleteall').delete((req, res) =&amp;gt; {
    Shop.findByIdAndDelete(receipt._id)
        .then(() =&amp;gt; res.json('All Shops deleted.'))
        .catch(err =&amp;gt; res.status(400).json('Error : ' + err));
})

- Update
router.route('/update/:receiptId').post((req, res) =&amp;gt; {

    return Receipt.find({ _id: req.params.receiptId }).then(
        data =&amp;gt; {
            let Receipt = data[0];

            Receipt.phoneNo = Receipt.phoneNo;
            Receipt.paymentMethod = req.body.paymentMethod;
            Receipt.return = req.body.return;

            Receipt.save()
                .then(() =&amp;gt; {
                    res.json('Receipt updated.');
                })
                .catch(err =&amp;gt; res.status(400).json('Error : ' + err));
        }
    )

});

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Mongoose functions**
Mongoose models provide several static helper functions for CRUD operations. Each of these functions returns a mongoose Query object. When executing a query with a callback function, you specify your query as a JSON document.

Model.deleteMany()
Model.deleteOne()
Model.find()
Model.findById()
Model.findByIdAndDelete()
Model.findByIdAndRemove()
Model.findByIdAndUpdate()
Model.findOne()
Model.findOneAndDelete()
Model.findOneAndRemove()
Model.findOneAndReplace()
Model.findOneAndUpdate()
Model.replaceOne()
Model.updateMany()
Model.updateOne()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>node</category>
      <category>interview</category>
      <category>crud</category>
      <category>theory</category>
    </item>
  </channel>
</rss>
