<?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: Shahnawaz Alam</title>
    <description>The latest articles on DEV Community by Shahnawaz Alam (@iamshahnawaz7).</description>
    <link>https://dev.to/iamshahnawaz7</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%2F829092%2Ffbe79580-2df3-4e37-9caa-815d97921739.jpeg</url>
      <title>DEV Community: Shahnawaz Alam</title>
      <link>https://dev.to/iamshahnawaz7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamshahnawaz7"/>
    <language>en</language>
    <item>
      <title>MongoDB Connection using Mongoose</title>
      <dc:creator>Shahnawaz Alam</dc:creator>
      <pubDate>Sat, 18 Jun 2022 11:20:17 +0000</pubDate>
      <link>https://dev.to/iamshahnawaz7/mongodb-connection-using-mongoose-5951</link>
      <guid>https://dev.to/iamshahnawaz7/mongodb-connection-using-mongoose-5951</guid>
      <description>&lt;p&gt;An important step in the process of Development is connecting with the database. This has been made easy with &lt;code&gt;mongoose&lt;/code&gt;, which is an npm dependency. &lt;/p&gt;

&lt;p&gt;After you have initialized your express app, install mongoose using the following npm command : &lt;/p&gt;

&lt;p&gt;npm install mongoose&lt;/p&gt;

&lt;p&gt;Mongoose can be used in 3 simple steps : &lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up a port
&lt;/h2&gt;

&lt;p&gt;Since &lt;code&gt;mongoDB&lt;/code&gt; runs on a server, we need to run a mongoDB server locally. If you have mongoDB installed locally, just head to your preferred terminal and run : &lt;/p&gt;

&lt;p&gt;mongod&lt;/p&gt;

&lt;p&gt;Your mongoDB server is up and running on &lt;em&gt;port: 27017&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Importing Mongoose
&lt;/h2&gt;

&lt;p&gt;You can import and use mongoose in 2 places : &lt;/p&gt;

&lt;h3&gt;
  
  
  In the &lt;code&gt;server.js&lt;/code&gt; file
&lt;/h3&gt;

&lt;p&gt;You can import and use mongoose in the main server file itself : &lt;br&gt;
javascript&lt;br&gt;
const mongoose = require("mongoose");&lt;/p&gt;

&lt;h3&gt;
  
  
  In a Separate Database Folder
&lt;/h3&gt;

&lt;p&gt;You can also implement the modular approach where you can create a separate &lt;code&gt;db&lt;/code&gt; folder and setup connection inside it in a &lt;code&gt;connections.js&lt;/code&gt; file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting To Server
&lt;/h2&gt;

&lt;p&gt;The final step is to initialize and setup the mongoDB connection. &lt;br&gt;
The process is to initialize the mongoose connection and listen for the result returned.&lt;/p&gt;

&lt;p&gt;javascript&lt;br&gt;
const mongoose = require("mongoose");&lt;/p&gt;

&lt;p&gt;mongoose&lt;br&gt;
  .connect(process.env.DB_URL, {&lt;br&gt;
    useNewUrlParser: true,&lt;br&gt;
    useFindAndModify: false,&lt;br&gt;
    useUnifiedTopology: true&lt;br&gt;
  })&lt;br&gt;
  .then((result) =&amp;gt; {&lt;br&gt;
    console.log("Database connected at port : "+process.env.DB_URL);&lt;br&gt;
  })&lt;br&gt;
  .catch((err) =&amp;gt; {&lt;br&gt;
    console.log(err);&lt;br&gt;
  });&lt;/p&gt;

&lt;p&gt;Now the question is what are these terms : &lt;br&gt;
javascript&lt;br&gt;
    useNewUrlParser: true,&lt;br&gt;
    useFindAndModify: false,&lt;br&gt;
    useUnifiedTopology: true&lt;/p&gt;

&lt;p&gt;These are optional arguments being passed to the connection method.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;code&gt;useNewUrlParser&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The underlying MongoDB driver has deprecated their current connection string parser. Because this is a major change, they added the useNewUrlParser flag to allow users to fall back to the old parser if they find a bug in the new parser. You should set&lt;br&gt;
javascript&lt;br&gt;
useNewUrlParser: true&lt;/p&gt;

&lt;p&gt;unless that prevents you from connecting.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;code&gt;useFindAndModify&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;true&lt;/code&gt; by default. Set to false to make findOneAndUpdate() and findOneAndRemove() use native findOneAndUpdate() rather than findAndModify().&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;findOneAndUpdate&lt;/code&gt; allows for just updates - no deletes or replaces etc.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;findAndModify&lt;/code&gt; can do a lot more including replace, delete and so on.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  3. &lt;code&gt;useUnifiedTopology&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;false&lt;/code&gt; by default. Set to true to use the MongoDB driver's new connection management engine. This option should always be set to true, except for the unlikely case that it prevents you from maintaining a stable connection.&lt;/p&gt;

&lt;p&gt;There we go! We have successfully setup a mongoDB connection.&lt;br&gt;
Happy Hacking!!&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Web Sockets : The Handshake Technology</title>
      <dc:creator>Shahnawaz Alam</dc:creator>
      <pubDate>Sat, 18 Jun 2022 11:16:50 +0000</pubDate>
      <link>https://dev.to/iamshahnawaz7/web-sockets-the-handshake-technology-149d</link>
      <guid>https://dev.to/iamshahnawaz7/web-sockets-the-handshake-technology-149d</guid>
      <description>&lt;p&gt;We all have used Instagram or WhatsApp to have a healthy chat with our friends. Being a developer, I always wondered how this happens so fast without reloading. The answer is Web Sockets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Sockets vs HTTP
&lt;/h2&gt;

&lt;p&gt;Why Web Sockets you might ask? Well what happens in HTTP is that a connection is established and once the request result process is completed, the connection is terminated.&lt;br&gt;
So if we use this process for real time messaging, it would take some time to create new connections, thus making our chatting process slower. No one would like that, right?&lt;/p&gt;

&lt;p&gt;This is where Web Sockets come in. The major difference is that the connection once established, is not destroyed until there is no more need for it. &lt;/p&gt;

&lt;h3&gt;
  
  
  Pipelines in Web Sockets
&lt;/h3&gt;

&lt;p&gt;This might feel like one of those tech terminologies which scare us. But in simpler terms, pipelines in tech are same as real life pipelines. A connection through which things can be passed in any direction easily. &lt;br&gt;
This is how Web Sockets work, through pipelines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bgm-Rxsy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7rzkaxcy9syusdtbpdb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bgm-Rxsy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7rzkaxcy9syusdtbpdb.png" alt="How web sockets work" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many libraries that help with the implementation of Web Sockets like Socket.io&lt;/p&gt;

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