<?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: MD.Tajkier Haque Raiyan</title>
    <description>The latest articles on DEV Community by MD.Tajkier Haque Raiyan (@coderboyraiyan).</description>
    <link>https://dev.to/coderboyraiyan</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%2F764962%2Feae0c46b-108c-42ed-90d0-26f118c8eef2.jpg</url>
      <title>DEV Community: MD.Tajkier Haque Raiyan</title>
      <link>https://dev.to/coderboyraiyan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/coderboyraiyan"/>
    <language>en</language>
    <item>
      <title>How to Build a Simple CRUD API using NodeJS, Express, and MongoDB</title>
      <dc:creator>MD.Tajkier Haque Raiyan</dc:creator>
      <pubDate>Thu, 23 Dec 2021 07:42:05 +0000</pubDate>
      <link>https://dev.to/coderboyraiyan/how-to-build-a-simple-crud-api-using-nodejs-express-and-mongodb-ila</link>
      <guid>https://dev.to/coderboyraiyan/how-to-build-a-simple-crud-api-using-nodejs-express-and-mongodb-ila</guid>
      <description>&lt;p&gt;In this blog, we are going to make a CRUD operation using node js and MongoDB.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Introduction *&lt;/em&gt;: &lt;br&gt;
CRUD stands for Create(insert data to database), Read(Retrieve a data from database), Update(Edit from database), and Delete(delete a data from database)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt; : &lt;br&gt;
At least NPM version &amp;gt;= 5.6&lt;br&gt;
Basic knowledge about node js&lt;br&gt;
Javascript core concepts like arrow function, object destructuring and async/await, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: I’m using windows 10 20H2. And the editor is VS Code editor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get started:
&lt;/h2&gt;

&lt;p&gt;First of all we need to create a folder. You can create it manually. I will use my terminal. So open your terminal then run this command : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TLdr3w4M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8jpdprqrqs1b8vqqsyf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TLdr3w4M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8jpdprqrqs1b8vqqsyf.png" alt="Image description" width="880" height="691"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now my file name is server.js so I’m going to start here:&lt;br&gt;
Add these codes to your server .js file :&lt;br&gt;
So in this picture, you have a question that what the hell requires doing here. Require is like import. Express js documentation follows the old method of import. Hopefully, it will be updated soon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ngFMaT_M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5jww7neod0d7al1akmw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ngFMaT_M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5jww7neod0d7al1akmw.png" alt="Image description" width="880" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So now I tell you the main steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First Import the express like above the picture.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then convention is to use the express into a variable and call it like a function. And my app variable is the express function now.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then the main is your port I use here the environment variable Cause when I deploy it to the server it uses the environment variable. And local machine Our port is 5000. You can give it any number you like.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then We see the CORS. CORS mainly stands for Cross-origin resource sharing. It allows you to make requests from one website to another website in the browser, which is normally prohibited by another browser policy called the Same-Origin Policy (SOP).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then I uses the dotenv library for environment variable.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Middleware:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bkl4P5yH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wesm8q7pihnr7e41wj3w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bkl4P5yH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wesm8q7pihnr7e41wj3w.png" alt="Image description" width="778" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I know you ask me a question what is middleware. Middleware is like a middle man who works from the middle. Here we use two middleware one is &lt;strong&gt;cors()&lt;/strong&gt; and the second one is &lt;strong&gt;express.json()&lt;/strong&gt;. So the first middleware &lt;strong&gt;cors **is for cross-origin policy and the **express.json()&lt;/strong&gt; is for parsing it to JSON format. &lt;/p&gt;

&lt;h2&gt;
  
  
  Connect the DataBase:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lb7UozcC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzpxofuysr6mztdt4lv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lb7UozcC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzpxofuysr6mztdt4lv9.png" alt="Image description" width="880" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find these codes in your own MongoDB database. Just go there and click on connect option they will provide you with the above code. Note: You can see the uri on the picture I use environment variables for security purposes. I hide my database username and password using the template literals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now we can dive into functionalities:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Main function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lSYehvvl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vk3gguqwdeoinp9ea82n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lSYehvvl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vk3gguqwdeoinp9ea82n.png" alt="Image description" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YH1_bPb8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cjy84tznuwfovvf0svz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YH1_bPb8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cjy84tznuwfovvf0svz.png" alt="Image description" width="880" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B6oQNfI_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj4chcmzzq415ntivbcm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B6oQNfI_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj4chcmzzq415ntivbcm.png" alt="Image description" width="880" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OatI93EB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/00e45plwt18hgpqbjdrt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OatI93EB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/00e45plwt18hgpqbjdrt.png" alt="Image description" width="880" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delete&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3scbMmVq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwwxq8q3d82qj6u7ku6b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3scbMmVq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwwxq8q3d82qj6u7ku6b.png" alt="Image description" width="880" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create-operation: In the picture, I used the async/await. You can use then. First of all, we need to connect the database so that is why I used client. connect(). Then create a database variable for your db and name it in your way. Then we need a collection so create a collection. I create two collections. Named order collection and foodcollection. Now In my picture you can see line number 14 I insert a document into the database. In the app.post function you can see I use the instertOne method which is provided by mongodb. For insert data or create data in MongoDB. &lt;/p&gt;

&lt;p&gt;You can follow the screenshot for all the operations or check here for more details: &lt;a href="https://docs.mongodb.com/drivers/node/current/usage-examples/"&gt;MongoDB Docs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>mongodb</category>
      <category>express</category>
    </item>
    <item>
      <title>React's new Context API and Actions</title>
      <dc:creator>MD.Tajkier Haque Raiyan</dc:creator>
      <pubDate>Wed, 22 Dec 2021 11:10:21 +0000</pubDate>
      <link>https://dev.to/coderboyraiyan/reacts-new-context-api-and-actions-4hi9</link>
      <guid>https://dev.to/coderboyraiyan/reacts-new-context-api-and-actions-4hi9</guid>
      <description>&lt;p&gt;Context API seems interesting. Context API comes with several solutions in react.  The solutions are : &lt;br&gt;
It provides a single source of truth for data that can be directly accessed by components that are interested, which means:&lt;br&gt;
It avoids the "prop-drilling" problem, where components receive data only to pass it on to their children, making it hard to reason about where changes to state are (or aren't) happening.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Context do?
&lt;/h2&gt;

&lt;p&gt;There are many articles on how the context api works. So you can check there. I’m here to tell you how to use the context api with some of my examples. &lt;/p&gt;

&lt;h2&gt;
  
  
  Simple Context Example?
&lt;/h2&gt;

&lt;p&gt;First of all, we have to create a custom component. And wrap the App.js. Here app.js will be children of the custom wrapper component. In the component, we have to create a context using createContext(). Like So: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5xPIFTAV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o71hbfwh58dt4r3uhah9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5xPIFTAV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o71hbfwh58dt4r3uhah9.png" alt="Image description" width="678" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can use the DuckifyConsumer to read that state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Passing Functions:
&lt;/h2&gt;

&lt;p&gt;In javascript, functions are known as “first-class”, meaning we can treat them as objects and pass them, around even in state and the providers value prop. The maintainers didn’t use state prop they uses the value prop. Because they want to separate the concepts of value and state. In this case, we can add an dispatch function to the DuckifyProvider state. dispatch will take in an action (defined as a simple object), and call a reducer function (see below) to update the Provider's state (I saw this method of implementing a redux-like reducer without redux somewhere, but I'm not sure where. If you know where, let me know so I can properly credit the source!).&lt;br&gt;
We pass the state into the value for the Provider, so the consumer will have access to that dispatch function as well.&lt;/p&gt;

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