<?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 Zain Ulabidin on Medium]]></title>
        <description><![CDATA[Stories by Zain Ulabidin on Medium]]></description>
        <link>https://medium.com/@ghatabala?source=rss-b2c204a2af27------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BE4uOFXEn8wOTpBTB3sKqQ.jpeg</url>
            <title>Stories by Zain Ulabidin on Medium</title>
            <link>https://medium.com/@ghatabala?source=rss-b2c204a2af27------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:58:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ghatabala/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[Men kon hun]]></title>
            <link>https://ghatabala.medium.com/men-kon-hun-5fc37f8d5e21?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fc37f8d5e21</guid>
            <category><![CDATA[who-am-i]]></category>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Sat, 18 Oct 2025 13:12:34 GMT</pubDate>
            <atom:updated>2025-10-18T13:14:42.298Z</atom:updated>
            <content:encoded><![CDATA[<p>bay maqsad samandar ke safar pe tha,</p><p>dard se paon ukhar gye</p><p>thokar lagi, aur me gir gia</p><p>ankh khuli tu laga yun mujhe</p><p>kisi ne dia hai sahara mujhe</p><p>aur jis ne giraya uthaya mujhe</p><p>usay pathar kahun ya chamakta sitara</p><p>haseen itna ke chamakta rahe</p><p>jag sare ko ujala kary</p><p>gumnam tha me usne naam dia</p><p>be maqsad tha me usne kaam dia</p><p>shooor bhi di</p><p>tashakkus bhi di</p><p>na tha kuch aur usne insan kia</p><p>aik maqsad dia aik idara dia</p><p>har aik kone ka usne ijara dia</p><p>phir aik din laga yun ke me hi tu hun</p><p>ke jis ne yeah sara ujala kia</p><p>ke pathar nahin hai yeah me hi tu hun</p><p>jisne yeah sara tamasha kia</p><p>ke thokar na khata tu kese janab</p><p>jag ne khuda na nazara kia</p><p>aur pathar ki chamak ulajhne lagi</p><p>ankhun ki thandak, ab chubhne lagi</p><p>aik aur pathar ki hui talab</p><p>jo samandar ke safar pe nikal giya</p><p>Jo tha me, na tha me, sab bhoolne laga</p><p>thakne laga aur dard hui, pathar ki chamak ab sard hui</p><p>ankhen ab fikr se nam ho gyeen</p><p>me kia tha, me kon, yeah kyon hai, yeah kia</p><p>cheekhne laga, phir chup hogya</p><p>kyonke pathar na tha, na chamak, na rasta</p><p>aik lamhe me sab kuch me bhol giya</p><p>aur phir se me</p><p>bay maqsad samandar ke safar pe tha</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fc37f8d5e21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Wasl]]></title>
            <link>https://ghatabala.medium.com/wasl-6cead5866f41?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cead5866f41</guid>
            <category><![CDATA[ghazl]]></category>
            <category><![CDATA[wasl]]></category>
            <category><![CDATA[poetry]]></category>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Wed, 11 May 2022 07:17:48 GMT</pubDate>
            <atom:updated>2022-05-11T07:17:48.901Z</atom:updated>
            <content:encoded><![CDATA[<p>Phir se yeah rooh tujhe khud se si bulati hogi,</p><p>Mujh ko khabar tak na hui, tujh se mil aye hogi.</p><p>Phir se khushboo ko teri paas jo paya hoga,</p><p>Meri har saans ko kis qadar mehkaya hoga.</p><p>Hai mere jism me wo zehr ki manend mojood,</p><p>Yeh jo be khud hun, asar apna dikhaya hoga.</p><p>Itni khaak mun par jo laga bethe ho,</p><p>Phir wasl me koi toor jalaya hoga.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cead5866f41" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[زما ورور]]></title>
            <link>https://ghatabala.medium.com/%D8%B2%D9%85%D8%A7-%D9%88%D8%B1%D9%88%D8%B1-9d48a5dbb580?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d48a5dbb580</guid>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Sun, 23 Jan 2022 08:35:09 GMT</pubDate>
            <atom:updated>2022-01-23T08:35:09.959Z</atom:updated>
            <content:encoded><![CDATA[<p>دا سے خو نہ دا چے ما نہ زما ورور ہیر دے<br>زہ دہ ندامت یو ڈیر لوے حصار یم</p><p>دا ندامت بہ کلہ ہم فتح نہ شی<br>ددے دیوال مضبوط او زہ اے چوکیدار یم</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d48a5dbb580" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[تنہائی]]></title>
            <link>https://ghatabala.medium.com/%D8%AA%D9%86%DB%81%D8%A7%D8%A6%DB%8C-270bb0e5442?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/270bb0e5442</guid>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Sun, 23 Jan 2022 08:25:26 GMT</pubDate>
            <atom:updated>2022-01-23T08:25:26.774Z</atom:updated>
            <content:encoded><![CDATA[<p>زہ دہ خپلے تنہائے نہ تنگ یم<br>دا خدائے پاک سنگہ نہ تنگیگی</p><p>زہ خپل سو چ پہ پردو کو ڑوند یم<br> دا دہ رڑاں پردے بہ کلہ آزادےگی</p><p>سومرہ جوختیگم، دومرہ لرے کیگم<br>دا فاصلے بہ سنگہ وصل کیگی</p><p>چے یو آزاد کم نو پہ بل کے گیر شم<br>دا گنجال بہ لا سنگہ آزادیگی</p><p>زہ خو پہ خدائے پاک ڈیر حیران یم<br>زمونگ پریشانی نہ ورتہ سہ حاصیلیگی</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=270bb0e5442" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[آزاد زوے]]></title>
            <link>https://ghatabala.medium.com/%D8%A7%D9%93%D8%B2%D8%A7%D8%AF-%D8%B2%D9%88%DB%92-dfe9b9c4b116?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfe9b9c4b116</guid>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Sun, 23 Jan 2022 08:05:09 GMT</pubDate>
            <atom:updated>2022-01-23T08:05:09.982Z</atom:updated>
            <content:encoded><![CDATA[<p>بازار تہ لارڑ شہ خو بازار تہ مہ زہ<br>ھر سہ کوہ خو ہیس ام مہ کوہ</p><p>تہ آزاد اے پہ خپلہ فیصلہ کے زویہ<br>خو تہ کم عقل اے، تہ فیصلہ مہ کوہ</p><p>چہ سہ غواڑے غواڑہ چہ سہ سکے سکہ<br>خو سہ ھوم زما نہ بے تپوسہ مہ کوہ</p><p>تہ غلام خو نہ اے زہ دے صرف پلار یم<br>زما پہ خبرہ تہ کلہ ہم غصہ مہ کوہ</p><p>زہ ستا خہ غواڑم تہ نہ خو لا نا پوھیگے<br>چے کلہ غٹ شے دخیرا،لا نا فرمانی مہ کوہ</p><p>ڈیر نا شکرا اے، او ڈیر بے پرواہ ہم،<br>بس کہ ڈیر دے اوکڑل، اوس نور مہ کوہ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfe9b9c4b116" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What keeps one from people?]]></title>
            <link>https://ghatabala.medium.com/what-keeps-one-from-people-52023eecc057?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/52023eecc057</guid>
            <category><![CDATA[thoughts]]></category>
            <category><![CDATA[thinking]]></category>
            <category><![CDATA[thinking-out-loud]]></category>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Mon, 08 Feb 2021 16:57:33 GMT</pubDate>
            <atom:updated>2021-02-08T16:57:33.165Z</atom:updated>
            <content:encoded><![CDATA[<p>Expectation. A person too low to stop hearting and too big to start hearting. The former is existent and the later is ideal.</p><p>Explaining or keeping things to unanswerable is the best. Who is that then I or God?</p><p>The disparity between said and heard is fathomless. The energy spent on educating and proving is infinite. Thoughts are wasted, voice is misspend. Opinions are not for judgement when invited. Hilarious are the ones who seek and judge. They thought worthless and corrupted their pure thoughts.</p><p>If you take you take it, if you don’t you don’t. I am not seeking and you are not allured.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52023eecc057" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On Pure thoughts]]></title>
            <link>https://ghatabala.medium.com/on-pure-thoughts-953d5a267d9b?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/953d5a267d9b</guid>
            <category><![CDATA[thoughts-and-feelings]]></category>
            <category><![CDATA[thoughts-and-ideas]]></category>
            <category><![CDATA[thoughts]]></category>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Mon, 08 Feb 2021 14:35:48 GMT</pubDate>
            <atom:updated>2021-02-08T14:35:48.489Z</atom:updated>
            <content:encoded><![CDATA[<p>Where does purity of thoughts lie? Not on the internet.</p><p>Noise will always overcome purity in thoughts. But who cares about pure thought? I care. Why is the noise (other’s thoughts) less important?</p><p>To decide, imagine a thought is a son of brain. Then the answer is evident.</p><p>Second opinions or reviews are good or bad? not for colluding with pure thoughts. It’s ok for energizing and motivating. It’s very easy for a thought to be a victim.</p><p>Is it egotistic to stop listening? It’s natural that the brain would prefer his own son, so it’s not ego.</p><p>How about a sacrifice? selfless deed don’t exist! You don’t agree? then auto response of Human body and coincidence are the answer. But that is not blame a sacrifice or selfless for they are innocent even when just want heroism. Innately, everyone is innocent. Collusion of thoughts force them to act. A person is unlucky and a victim, but never guilty or criminal.</p><p>How pure thought can exist? Another way to say is How one removes noise? by being biased. Decisions and controlling the input. Input can not be controlled sometimes and can dropped or ignored. It works too.</p><p>Pure thoughts over educated guesses? For sure. What about educated guesses? Only for motivating or energizing pure thoughts.</p><p>Order of constructing pure thought remain a challenge. First educated guess and then pure thought or the other way around? The bias would devastate pure thought and a blank mind is incapable of pure thought. What is a blank mind? does it exists. In theory I guess.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=953d5a267d9b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How “Writely” utilizes Computer Vision]]></title>
            <link>https://ghatabala.medium.com/how-writely-utilizes-computer-vision-1d3029c2829?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d3029c2829</guid>
            <category><![CDATA[sift]]></category>
            <category><![CDATA[surf]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Mon, 21 Oct 2019 11:25:57 GMT</pubDate>
            <atom:updated>2019-10-21T11:25:57.874Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hello,</h3><p>I would like to share my recent project which is related to computer vision. Not only It helped me gain some insight into the subject, but it also gave me a taste of what is possible which is a lot. To find out more about Writely, please visit <a href="http://writelynotebook.com/">Writelynotebook.com</a></p><p>Since last summer, I have been working on a digital diary called Writely. Its an environment-friendly and reusable notebook. Because it’s erasable, we wanted to preserve the content of the pages in electronic format via smartphone. Given a notebook image, we want to categorize it (based on icons on the notebook image), recognize the data (such as the date and topic) and find keywords by which the notebook image can be searched later. The problem is mostly related to object detection, image segmentation and NLP (OCR).</p><p>The first challenge was to align/register the images. Because user is lazy, he takes images with background and rotations. To remove the effect of rotation and skew as well as subtract the background, I have used an image registration technique. Because I had a reference notebook image, I used SIFT features to align the images. By finding a homography/(perspective transform), I was able to reverse the distortion effect. While SIFT/SURF both worked greatly, SURF was 2x faster. Now even rotated and skewed images are reversed to the original shape. It works pretty well for the images which have good landmarks. So at this part, I was successful and now in an arbitrarily taken photo of a notebook, I was able to find the real content in the image and subtract the background.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eKtyCFL6EGD3orFT" /></figure><p>(This image was generated using drawMatches function of OpenCV to find out how well the feature matching was working. These are SIFT features. )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*feo2_fDYT6AXXLf8" /></figure><p>(This demo was made with a react native application that I built for testing the results. The image processing was done via flask HTTP server in python. In the image, you can see that the user image is rotated and has a background. After image registration, the only the relevant part is captured and the rest is discarded.)</p><p>The second task was to find some special icons located in the image. With those icons, we could categorize the documents With simple template matching, this task performed poorly so I tried histogram matching. Although this seemingly straightforward task is very hard to do with preciseness. I am still working on it and as I discussed it with some friends, they suggested some techniques with machine learning. The only problem is to collect a data set that will resemble the actual user situation. But if it is done correctly, to my known knowledge, it will be the best solution.</p><p>For the third task, I will use the most models to extract date information from the notebook. I will be finding digits with deep learning because really of its accuracy and speed (Thanks to people who did the hard part of training these models). I will be picking some models with the RNN model or similar. But before, I want to segment the image. For segmenting I am playing around flood fill, opening, closing and image morphology. It’s a fun exercise for me I hope it will work out.</p><p>I hope you find this project interesting.</p><p>You can find more about my project here<a href="https://github.com/zainulabidin302/image-registration"> https://github.com/zainulabidin302/image-registration</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d3029c2829" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How top Javascript Developers learn new Javascript Technologies (Series of Articles)]]></title>
            <link>https://ghatabala.medium.com/how-top-javascript-developers-learn-new-javascript-technologies-series-of-articles-3a2d0ea01138?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a2d0ea01138</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[top-10]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Tue, 04 Dec 2018 06:13:43 GMT</pubDate>
            <atom:updated>2018-12-04T06:13:43.081Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*3Bf5DMZ_cN3SOC-0px8Crw.png" /></figure><p>Ever since I started web development with NodeJS, I have a feeling of hollowness. There is a lot of ground to cover and I have not even scratched the surface. I learned about “cluster” and “net” modules yesterday and I am learning about SSR and universal applications now. Web assembly and web VR are out and Vue 3 is using Typescript now so I need to start learning typescript. There is a lot more going on and I don’t know how to catch up in the race.</p><p>Not only that, it is hard to invent a new idea. Imagine you are thinking about a new javascript module that can help a group of people. A single google search will tell you that there 10 module of similar nature. Space seems to be saturated. This can be frustrating and discouraging.</p><p>In order to be a full stack javascript developer, it’s not only how you can use these things, but also how to learn new things quickly.</p><p>In this article series of articles, I will talk with hero javascript developers on how they cop up with their javascript skills.</p><p>I am looking for top tips from Guru JS Developers on how to become a rockstar developer in 2019.</p><p>Are you interested in knowing these tips? Drop your email in the comments and I will add you to the mailing list in which I will be sending these interviews and podcasts with the top Javascript Gurus.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a2d0ea01138" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing HTTP Rest API in NodeJS with MongoDB]]></title>
            <link>https://ghatabala.medium.com/writing-http-rest-api-in-nodejs-with-mongodb-40edaf0f52b5?source=rss-b2c204a2af27------2</link>
            <guid isPermaLink="false">https://medium.com/p/40edaf0f52b5</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Zain Ulabidin]]></dc:creator>
            <pubDate>Thu, 22 Nov 2018 11:07:03 GMT</pubDate>
            <atom:updated>2018-11-22T11:27:31.117Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will create an application which can create, update, fetch and delete products from a MongoDB with NodeJS. I will explain how can you create an HTTP rest API in nodejs which can communicate with the database.</p><p>Let’s start!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1gMvmpcYF5ulS_BP" /><figcaption>Photo by <a href="https://unsplash.com/@sapegin?utm_source=medium&amp;utm_medium=referral">Artem Sapegin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Installing NodeJS</h3><blockquote>Node.js® is a JavaScript runtime built on <a href="https://developers.google.com/v8/">Chrome’s V8 JavaScript engine</a>.</blockquote><p>If you have not installed <a href="https://nodejs.org/">NodeJS</a> yet, now is the time to do it. You will need it for this tutorial. In order to install NodeJS, you can go to <a href="https://nodejs.org/en/">NodeJS </a>website, download and install the binaries. The other way is to follow the <a href="https://nodejs.org/en/download/package-manager/">Installation Guide</a> which gives instructions on how to install NodeJS on a specific platform. If you have any trouble installing nodejs, check out <a href="https://nodejs.org/en/download/package-manager/">installation guide</a> and follow the instructions for your platform.</p><h3>Express</h3><blockquote>Express is a “Fast, unopinionated, minimalist web framework for NodeJS”</blockquote><p>“express” is a Framework for building APIs and web applications in NodeJS. In order to start building a website or API with express, you need to add to your project first.</p><h4>Installing and configuring ExpressJS in your project</h4><p>Once nodejs is installed, you need to create a project. Almost, every nodejs project contains a file called package.json. The directory which contains this file is usually a nodejs project. In order to create this file for our project, we can use npm utility or create one manually. We will use npm to create one for us.</p><p>First of all, create an empty directory for the project.</p><pre><br>mkdir -p ~/node-express-api/ &amp;&amp; cd ~/node-express-api</pre><p><em>(you can create the directory anywhere you want)</em></p><p>Run the following command and answer questions about your project.</p><pre>npm init</pre><p>If you are unsure about a question, leave it empty for now.</p><p>a file named package.json will appear in the current working directory where you ran the npm init similar to the following.</p><pre>{ <br>   “name”: “&lt;name of project&gt;”,<br>   “version”: “&lt;version&gt;”,<br>   “description”: “&lt;description&gt;”,<br>   “author”: “&lt;author&gt;”,<br>   “scripts”: {<br>       …<br>   }<br> }</pre><p>Now we let’s add express to our project.</p><p>In order to install express, run the following command in the directory which contains package.json (project directory).</p><pre>npm install — save express</pre><p>After running this command, the project directory will contain a folder called node_modules in addition to package.json. This folder contains the express framework (and any other dependency express depends upon).</p><p>Create a new file in the same directory named as index.js. This file is the entry point of our API.</p><p>Finally, our directory contents look like the following.</p><pre>node_modules package.json index.js</pre><h4>Routing in express</h4><p>Routing is defining which URL path will map to which code (or execution unit). In other it tells the app what to do when a user access a url of our application. URL path is the part of URL that comes after the domain name. For example in <a href="http://www.example.com/abc/efg/">www.example.com/user/</a>1, /user/1is the path or URI. We can then tell, which URI should execute which part of the application. So user/1, for example, should execute the code which will fetch the user with id 1. but <a href="http://www.example.com/user">www.example.com/user</a>s in which /users is the path, we may run the code which returns the full list of users from the database.</p><p>Express makes the routing task easy for us. To create our first route, we will import express in our index.js file. We will then define our routes and code which will execute when someone requests that route or path. Finally, we start the server so it listens for HTTP requests.</p><p>The following is the content of index.js</p><pre> const express = require(‘express’)<br> const app = express()<br> app.get(‘/’, (req, res) =&gt; {<br>   console.log(‘route was requested’)<br>   res.json({<br>     message: “hello world!”<br>   })<br> })<br> <br> app.listen(3000, () =&gt; {<br>   console.log(`Server is listening at port 3000`)<br> })</pre><p>Open the terminal and run the following command in the project directory.</p><p>node index.js</p><p>In order to test if your server is working, open the following URL <a href="http://localhost:3000`">http://localhost:3000</a> in the browser.</p><p>Congratulations, You have written your first route in express.</p><h3>MongoDB</h3><blockquote>MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need</blockquote><p><a href="https://www.mongodb.com/what-is-mongodb">MongoDB</a> is perfect for rapid development and agile teams who are to change. It is as best for startups (which require flexibility in the schema) as it is for highly demanding businesses which cannot afford downtime.</p><h3>Installing MongoDB</h3><h4>Easy but powerful way to get started with mongo</h4><p>MongoDB installation can be cumbersome for the first time user. In order to avoid the configuration setup, you can use mongo cloud which has a free tier. You can check it out here Cloud <a href="https://mbsy.co/mongodb/42930539">MongoDB Atlas</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jjlmpqyCNsiGDWMz.png" /><figcaption>Create a new cluster in MongoDB Atlas for free</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qQtUZjF-sz8ZBqUT.png" /><figcaption>Creating a cluster in MongoDB Atlas is free and always be!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XHZuMy7rtgjV7fy2.png" /><figcaption>You can give your cluster a descriptive name</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dIWU5_tpQsTXfs5L.png" /><figcaption>When you create one cluster, you get 3 mongo instances running with high availability, failover and load balancing ready.</figcaption></figure><p>If you decide to create a free tier account, you will just need to signup and create a cluster. Once you create a cluster from the web GUI provided by <a href="https://mbsy.co/mongodb/42930539">MongoDB Atlas</a>, you can connect and start using the Database right away in your express application.</p><h4>Advanced users can install mongo on their own machine</h4><p>To install MongoDB on your local machine, download MongoDB from <a href="https://www.mongodb.com/download-center/community">MongoDB</a> website which has a community edition as well. Once you download the compressed MongoDB server for your distribution, you will need to extract the folder and find the bin directory. It contains two important binaries.</p><p>* mongod (MongoDB server)<br>* mongo (MongoDB client)</p><p>For convenience, add the full path of the bin directory in your PATH variable to easily access these utilities via terminal.</p><p>In order to run mongo server, use</p><pre><br>mongod — dbpath &lt; a path to directory where database will be saved&gt; — logpath &lt; a path to directory where database will be saved&gt; — fork </pre><p>on my machine, this command looks like this</p><pre>mongod — dbpath /data/db — logpath /var/logs/mongodb/mongod.log</pre><p>to verify that mongo server is running, use mongo client utility like the following.</p><pre>mongo</pre><p>mongo client will connect to the server and will show a shell. (The client will try to connect to localhost:27017 which is the default server host and port to which the listens, you don’t need to provide any argument to mongo client utility when using default setting). You can exit this shell by typing <em>exit</em>.</p><p>If you face issues when starting or connecting to the server, please follow the <a href="https://docs.mongodb.com/manual/installation/">Mongod Setup Guide</a>.</p><h4><strong>Installing MongoDB driver for nodejs</strong></h4><p>In order to connect to MongoDB via node.js, we will need to install MongoDB driver for nodejs. Let’s do that now.</p><p>Open the terminal and navigate to your project directory. Now run the following command.</p><pre>npm install — save mongodb</pre><p>let’s use MongoDB client driver to connect to our database.<br>I am assuming that you are using <a href="https://mbsy.co/mongodb/42930539">MongoDB Atlas cluster</a>. In order to connect to the MongoDB cluster, copy the connection string from web GUI of the cluster configuration page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*6HeTgKFhytyRt5i8.png" /><figcaption>MongoDB Cluster configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*kLzC_e6LIVYnyYvv.png" /><figcaption>Select connect Your Application</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*o0lDyJRp2EdrQmqq.png" /><figcaption>Copy the connection string. Then click on View your list users to create a password for admin</figcaption></figure><p>You will need to create a password for the admin user or create a new user in the security tab of the cluster.</p><blockquote>In real applications, you should create a user with exactly those roles which he needs and connect using that user. In this demo, we will connect using admin user which is already created.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0qN7G0ciN_VfKNGo.png" /></figure><h3>Creating Crud operations</h3><p>MongoDB uses documents to save data. A Document can be a user record, a product, patient etc. Documents are represented in JSON format. All document is stored in a collection. All collections are contained in a database.</p><p><em>Database &gt; Collection &gt; Document</em></p><p>We don’t need to inform mongo about the shape of our documents before inserting them. It will save any document which is in JSON format. <em>(Unlike most of the relational databases in which a table has a fixed schema.)</em></p><p>We will start by creating a <strong>POST</strong> <strong>HTTP </strong>endpoint in our express application. A user of our application will be able to insert a new document in our database using this endpoint.</p><p>At the end of this section, we will send a <strong>POST</strong> request with <br>some parameters to save it in the database.</p><p>We the product to have atleast the following attributes.</p><pre><br> {<br>   title: “&lt;title&gt;”,<br>   description: “&lt;description&gt;”,<br>   price: “&lt;price&gt;”<br> }</pre><h4>Insertion / Creation — Creating new documents in collections</h4><p>Ok so here is our new <em>index.js</em></p><pre>const express = require(‘express’)<br> const mongo = require(‘mongodb’).MongoClient<br> const app = express()<br> <br> const bodyParser = require(‘body-parser’)<br> // This package is used to parse the HTTP post request body.<br> // It is useful because it auto format the request into son and<br> // make it available for us as req.body<br> <br> app.use(bodyParser.json())<br> const connectionString = “&lt;enter your connection string here&gt;“<br> <br> app.get(‘/’, (req, res) =&gt; {<br>   console.log(‘route was requested’)<br>   res.json({<br>     message: “hello world!”<br>   })<br> })<br> <br> app.post(‘/product’, (req, res) =&gt; {<br>   mongo.connect(connectionString, (err, client) =&gt; {<br>     if (err) return res.json({error: err})<br>     console.log(req.body)<br>     const db = client.db(‘products’)<br>     const newProduct = {<br>       title: req.body.title,<br>       description: req.body.description,<br>       price: req.body.price<br>     }<br>     db.collection(‘product’).insert(newProduct, (err, result) =&gt; {<br>       if (err) return res.json({ errror: err})<br>       res.json({ message: “Product added successfully”, result})<br>     })<br>   })<br> })<br> <br> app.listen(3000, () =&gt; {<br>   console.log(`Server is listening at port 3000`)<br> })</pre><p>Before running the app, look at the code and see the difference. First of all, we are using 2 new packages. <strong>mongodb</strong> package is used to communicate to MongoDB server. <strong>bodyParser</strong> is used to convert our HTTP post data to JSON so we can handle it easily. We have created a new post route which is available at <a href="http://domain:port/product`">http://domain:port/product</a> (in our case <a href="http://localhost:3000/product%60">http://localhost:3000/product</a>). In this route, we first connect to the database and check if the connection is successful using <em>mongo.connect</em>. Next, <em>db.collection</em> gives us a handle to the collection in which we are inserting a new document. Note that the collection and databases are automatically created if none exists.</p><p>Next, We create a new object that is to be inserted and store it in <em>newProduct</em> variable. It will receive the post data that user sends using HTTP POST request.</p><p>Finally, we insert the document using the insert method and return a response using to the user.</p><blockquote>Note that there is no validation in place for the user input. Sending wrong fields or empty fields in post request can crash the application.</blockquote><blockquote>&gt; In production apps, we should check the user input before using it.</blockquote><p>Now run your server with</p><pre>node index.js</pre><p>In order to test our APIs, we use <em>curl</em>.</p><blockquote>curl is a command line tool and library for transferring data with URLs.</blockquote><p>It can send HTTP requests and it has options to communicate with them easily.</p><p>If you run the following command from the terminal</p><pre>curl <a href="http://localhost:3000/product">http://localhost:3000/product</a> -d “{\”title\”: \”Gold Earings\”,<br> \”description\”: \”Large golden earing\”,\”price\”: 2500}”</pre><p>Here, curl will send a post request to the url “<a href="http://localhost:3000/product">http://localhost:3000/product</a>” with title, description and price field. <em>-d</em> flag will add the data to the right and also set HTTP method to post for the request.</p><p>Our server will receive a post request and it will call the method associated with the POST /product route.</p><p>You should get a response similar to the following which indicates that a document is added in the database. (You can confirm this by going to your cluster using web GUI)</p><pre>{“message”:”Product added successfully”,”result”:{“result”:{“ok”:1,”n”:1,”opTime”:{“ts”:”6625541134925955073&quot;,”t”:1}},”ops”:[{“_id”:”5bf2a68f9dccb6df5ade015d”}],”insertedCount”:1,”insertedIds”:{“0”:”5bf2a68f9dccb6df5ade015d”}}}$</pre><h4>Fetching — Retrieving the documents</h4><p>Let create a new route in our <em>index.js</em> which returns all the products we have created. Place this code before <em>app.listen </em>function<em> .</em></p><pre><br> app.get(‘/product’, (req, res) =&gt; {<br>   mongo.connect(connectionString, (err, client) =&gt; {<br>     if (err) return res.json({error: err})<br>     const db = client.db(‘products’)<br>     db.collection(‘product’).find({}).toArray((err, result) =&gt; {<br>       if (err) return res.json({error: err})<br>       res.json(result)<br>     })<br>   })<br> })</pre><p>The code above creates a route with GET HTTP method and <a href="http://localhost:3000/product%60">http://localhost:3000/product</a> URL. It will return the list of all the documents we have in our product collection.</p><p>If your server is already running, press control + c in terminal to close and start it again using</p><pre>node index.js </pre><p>to test this route, run</p><pre>curl <a href="http://localhost:3000/product%60">http://localhost:3000/product</a></pre><p>You can also test routes directly in the browser by navigating to <a href="http://localhost:3000/product%60">http://localhost:3000/product</a> in your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*bI76Oq95EoNvADDE.png" /><figcaption>3 items are showing because I have inserted 3 documents.</figcaption></figure><p>You can see the extra <em>_id </em>field which we did not add. It is created by mongodb by default to identify the document.</p><h4>Updating a document</h4><p>To update a document, mongo will need to know which document we want to update. We use <em>_id </em>field to filter the document we need. Next, we need the updated document fields. Add the following to your <em>index.js</em></p><pre>app.put(‘/product’, (req, res) =&gt; {<br> mongo.connect(connectionString, (err, client) =&gt; {<br>   if (err) return res.json({error: err})<br>   const id = new ObjectId(req.body.id)<br>   const updatedDocument = {<br>     title: req.body.title,<br>     description: req.body.description,<br>     price: req.body.price<br>   }<br>   const db = client.db(‘products’)<br> <br>   db.collection(‘product’)<br>   .update({_id: id }, updatedDocument, (err, result) =&gt; {<br>     if (err) return res.json({error: err})<br>     res.json(result)<br>   })<br>  })<br>})</pre><p>We are using the <em>mongo</em>.<em>update</em> method on the MongoDB database to update the document. <br>The first argument matches which document should be updated. The second argument is the updates in JSON we want to apply on the matched document.</p><p>To test the update route, use following commands in terminal. Change the id to match one in your database. (use get product route we created earlier to list all products in order to find an id)</p><pre>curl -X PUT <a href="http://localhost:3000/product">http://localhost:3000/product</a> -d “{ \”id\”: \”5bf289e5409c2ddbc9307831\”, \”title\”: \”Gold Earings\”, \”description\”: \”Large golden earing\”,\”price\”: 2506}” -H “Content-Type: application/json”</pre><h4>Deleting a document</h4><p>The easiest of all the crud operations and one of my favorite is deleting a document.</p><pre><br> app.delete(‘/product’, (req, res) =&gt; {<br>   mongo.connect(connectionString, (err, client) =&gt; {<br>   const db = client.db(‘products’)<br>   db.collection(‘product’).deleteOne({<br>     _id : new    <br>     ObjectId(req.body.id)<br>    }, (err, result) =&gt; {<br>       if (err) return res.json({error: err})<br>       res.json(result)<br>     })<br>   })<br> })</pre><p>To test the delete route, use the following curl command. Change the id to match one, that exists in your database.</p><pre>curl <a href="http://localhost:3000/product">http://localhost:3000/product</a> -X DELETE -d “{\”id\”:\”5bf2a68f9dccb6df5ade015d\”}” -H “Content-Type: application/json”</pre><p>That completes our tutorial. If you liked it, please share it with others.</p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40edaf0f52b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>