<?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 Jatin Kumar on Medium]]></title>
        <description><![CDATA[Stories by Jatin Kumar on Medium]]></description>
        <link>https://medium.com/@jatin15011999?source=rss-96aac838856a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*po8_iqrzaW7JnYn_losDCQ.jpeg</url>
            <title>Stories by Jatin Kumar on Medium</title>
            <link>https://medium.com/@jatin15011999?source=rss-96aac838856a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 01:10:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jatin15011999/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[How to create Interactive Maps in React.js]]></title>
            <link>https://medium.com/techspace-usict/how-to-create-interactive-maps-in-react-js-ccdfad460fa0?source=rss-96aac838856a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccdfad460fa0</guid>
            <category><![CDATA[cogitans]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[mapbox-gl]]></category>
            <dc:creator><![CDATA[Jatin Kumar]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 23:19:20 GMT</pubDate>
            <atom:updated>2019-08-23T14:40:31.709Z</atom:updated>
            <content:encoded><![CDATA[<h4>Let’s make maps fun</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ahWTERsX76J42qhoE56n0Q.jpeg" /></figure><p>Hi there, I hope that you are having a great day. Let’s try to make it even better. Assuming that you are a web developer, I am very positive that you might have already used maps and visualized data plotted on it on numerous occasions. But in most cases you might have used them exclusively, even if they held some relation between them. But what about mixing them together, what about filtering data plotted on maps just by clicking different bars of bar graphs. Wouldn’t it be awesome. In my opinion, Yeah sure it would be. It would take user experience to a whole new level and would open doors of your app to new consumers who likes to have a good user experience. In other words we are transforming plain boring maps to much engaging ones by adding interactivity to them. As now user would be just a click/touch away to witness desired outputs on the map. You’ll be glad to hear that in today’s blog post we would be devoting our time to achieve just that. We would be creating a web application which would comprise of a map and Bar chart, In which data plotted on map would be controllable by clicking different bars of the bar chart. You can get it’s completed version from <a href="https://github.com/AwesomeChap/Interactive-Maps-In-React">github</a> and have a look at deployed code <a href="http://react-interactive-maps-demo.herokuapp.com/">here</a>. In order to get a better understanding of what we are about to build I would highly recommend you to visit the live URL and play with it till you get a sense of what I mean by adding interactivity to maps. We would be using React for the implementing app and for our maps along with charts I would be using react-map-gl, which is wrapper around Mapbox GL JS. You can find more about it <a href="https://uber.github.io/react-map-gl">here</a>. Now some of you might be curious, that why mapbox ? Why can’t we proceed with simple google maps? We’d be using Mapbox because it’s a hell lot more powerful option in my opinion if you are into customization. If you visit it’s homepage you’ll see for yourself how much features does it offers when compared to google maps. And it’s also useful to use it when you are creating something unique and custom so that your app can outstand among others in the eyes of the user/consumer. I hope by now you might have understood why we’d be using MapBox. Now that’s enough of talking let’s get started with our project setup!</p><h3>Project Setup</h3><p>Before moving ahead please ensure that you have node.js installed in your machine already, If not then please get it installed. You can refer to <a href="https://nodejs.org/">https://nodejs.org</a> for this purpose. After getting node.js installed, Now let’s start by initializing our project by executing commands shown below in your terminal.</p><pre>mkdir react-interactive-maps<br>cd react-interactive-maps<br>touch .babelrc<br>mkdir server<br>cd server &amp;&amp; touch server.js<br>mkdir data &amp;&amp; cd ../<br>mkdir src<br>cd src <br>touch app.js index.js index.html app.scss charts.scss<br>mkdir components<br>cd components<br>touch charts.js chart.js city-info.js city-pin.js map.js</pre><p>After executing these commands let’s install some npm packages, Navigate to root and execute commands shown below.</p><p><em>Note : We’ll be using </em><a href="https://parceljs.org/"><em>Parcel Bundler</em></a><em> to develop our react front-end. In case you are unaware of parcel, then you should know that in a nutshell it’s nothing more than application bundler similar to webpack. We’ll be using parcel as it’s just comparatively easy to setup and work with.</em></p><pre>npm init -y<br>npm i --save axios convert-csv-to-json express express-fileupload react <br>npm i --save react-dom react-map-gl react-vis<br>npm i --save-dev @babel/plugin-proposal-class-properties node-sass</pre><p>Alright that was a lot of setup code, But we had to do it anyway so I preferred to stack them together so that we had least chances of getting our file structure or npm packages different. If everything goes well then you must be having a file structure quite similar to shown below. One more thing, don’t worry if you don’t know about any of the packages that we just installed I’ll discuss them as we’ll utilize them while developing the application.</p><pre><strong>react-interactive-maps/</strong><br>|--<strong>server/</strong><br>|----<strong>data/</strong><br>|----server.js<br>|--<strong>src/</strong><br>|----<strong>components/</strong><br>|------chart.js<br>|------charts.js<br>|------city-info.js<br>|------city-pin.js<br>|------map.js<br>|----app.js<br>|----app.scss<br>|----charts.scss<br>|----index.html<br>|----index.js<br>|--.babelrc<br>|--package.json</pre><p>After doing this let’s edit our .babelrc file. We’ll be using arrow functions in our react app, In addition to that we need to extrude mapbox from transpiling by babel also. So let’s add a few lines to our .babelrc so that parcel knows what special config we require. You may find .babelrc config shown below.</p><pre>{<br> &quot;presets&quot;: [<br>   [<br>     &quot;env&quot;,<br>     {<br>       &quot;targets&quot;: {<br>         &quot;browsers&quot;: &quot;last 2 Firefox versions, last 2 Chrome versions, last 2 Edge versions, last 2 Safari versions&quot;<br>       },<br>       &quot;exclude&quot; : [&quot;/mapbox-gl&quot;]<br>     }<br>   ]<br> ],<br> &quot;plugins&quot;: [<br>   &quot;@babel/plugin-proposal-class-properties&quot;<br> ]<br>}</pre><p>Okay after copy pasting above code, navigate to your package.json and under scripts add couple of scripts shown below.</p><pre>&quot;dev&quot;: &quot;parcel src/index.html&quot;,<br>&quot;start&quot;: &quot;node server/server.js&quot;</pre><p>Okay, Now we are finally done with our project setup, And in case we require anything else, I’ll make you aware. In our next section we’ll kick off by building smaller yet very important portion of our application which is backend.</p><h3><strong>Setting up the backend</strong></h3><p>Open up your server.js file and copy paste code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f22fa17b78a03bb07359fa1fc811f235/href">https://medium.com/media/f22fa17b78a03bb07359fa1fc811f235/href</a></iframe><p>Alright so that’s our server.js file. Apart from some new packages it’s pretty intuitive and that’s for a reason, as it doesn’t provide much services besides providing data to our react based front-end. Express, path doesn’t require any introduction. They are quite popular packages so without wasting any time let’s move our focus to two newly introduced packages. Let’s begin with convert-csv-to-json , as the name implies it converts csv data to json, We needed it because our react front-end can’t work with csv data it’s requires json input. Therefore we parse csv data to corresponding json data using this package. To know more about it visit <a href="https://www.npmjs.com/package/convert-csv-to-json">here</a>. Second package is express-filupload. It makes uploaded file more accessible. When files are uploaded in presence of this package’s middleware,we can access them using req.files object. For more info you may visit <a href="https://www.npmjs.com/package/express-fileupload">here</a>. Okay so after knowing what each package is for, Rest of the code is pretty self explanatory, Anyways let’s discuss the remaining code step by step. We have a couple of route handlers for GET request and one for POST request. POST request is made by our fron-tend whenever user opts to upload his own data-set. Then we save the uploaded file by the name data_set.csv in data directory for future use. GET request is made by our front-end whenever it requires data. GET/api/default is made when user opts for continuing with dummy data and GET/api/data is made when front-end requires to fetch data uploaded by the user. When user opts for using dummy data then our server returns default data-set saved already in data directory. For that purpose I am using data-set provided by Kaggle (you can download it from <a href="https://www.kaggle.com/c/predicting-cab-booking-cancellations/data">here</a>). You can use your own data-set but remember that it’s format and keys should be exactly the same. With that we are done with our server. Up next we’ll start with creating front-end of our application.</p><h3>Quick structure analysis</h3><p>Knowing the structure of any application before building it is always very beneficial. So let’s do it. If you have seen the demo already, then the image shown below might seem quite familiar to you. If you’ve not visited the demo link yet, I’ll highly recommend you to do so. Because it would help you in providing a broader picture of what we are about to build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aom4bxe7ePNynhqw" /><figcaption>Application Structure Overview</figcaption></figure><p>So when you visited, you didn’t really got this page upfront right!. You were first presented with a welcome screen from where you moved ahead with an appropriate choice. And then you must have seen a very similar page as compared to image shown above. So the welcome screen is not really worth talking about as it’s just a presentable wrapper of the functional App that we’ll be building. We’d be building that wrapper as well though, but that’s talk of a later section and let’s leave it here only. So here we have a &lt;App/&gt; component which you can say is the most logical component of the application where all the manipulation of data goes on. It wraps major part of application. Next up we have &lt;Map/&gt; component which is also has some logic but other than that it’s just a simple map loaded with a particular configuration which we can alter depending on situations, You might have already witnessed this phenomenon indeed where you were able to tweak results on map by mere clicking bars of the bar chart. So that’s our &lt;Map/&gt; component for you. It also has some children components like &lt;CityInfo/&gt; and &lt;CityPin/&gt; , in which &lt;CityInfo/&gt; is used to display relevant data whenever user clicks on any marker. In our case for the sake of simplicity I just print CityId, But I’m sure you can be more creative than that. &lt;CityPin/&gt; is the svg we use as marker, nothing more than that!. Now apart from &lt;Map/&gt; we have &lt;Charts/&gt; component as well which you can see pretty distinctly at the bottom of the web page. Now as the name implies we use this component to render various charts and graphs. It also has a child component &lt;Chart/&gt; which we use to render charts. In my case there is only one chart therefore there is only one &lt;Chart/&gt; component, But you can have as many you like. Apart from the components we have some useful buttons as well, which surely deserve their own introduction. At the very top we have button with chart as it’s icon, we use it to toggle charts component. Few pixels below it we have another button whose visibility is conditional, But when it’s visible we use to reset filters and revert back to results to you got when you first visited the application. So, Now that you have understood the structure of the application or at least got the idea what individual component is supposed to do. I think we are good to move ahead and start with our front-end.</p><h3>Let’s create something that looks good to eyes!</h3><p>I think it would be better to move from smaller to bigger components, so let’s start with the smallest of all viz. &lt;CityInfo/&gt;. It’s employed to display info of the place, whose marker you clicked. It can be used to do a lot more than demonstrated, It just depends upon how creative you are and how much time you have. But for the time being let’s use it as it is only. Open your city-info.js in components directory and copy the few lines of code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0510a6acea9f8f3c27e6bbfb4a3546c3/href">https://medium.com/media/0510a6acea9f8f3c27e6bbfb4a3546c3/href</a></iframe><p>Now let’s hop over to second smallest of all viz. &lt;CityPin/&gt; component. It’s essentially just an SVG (viz. rendered as marker on map) with a onClick event attached to it, which does the job of toggling &lt;CityInfo/&gt; component. If you observe this basic stuff also help in improving interactivity of the map. So, to get going open your city-pin.js file in components directory and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d047378175f913f23b4afa63a578538/href">https://medium.com/media/7d047378175f913f23b4afa63a578538/href</a></iframe><p>Now let’s create &lt;Map/&gt; component, in a nutshell a space where majority of fun will take place. Now as I said before, It’s nothing but a Map rendered with a particular configs along with some functions to do very basic tasks, which we’ll discuss in detail. Before going any further, let’s first copy the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecbe40cba35dbc0b8da37d8b6b523491/href">https://medium.com/media/ecbe40cba35dbc0b8da37d8b6b523491/href</a></iframe><p>If you see the code, you can see that it’s a class component having a state and a couple of methods. So let’s discuss all of them one by one. The major part of state is the viewport config, In our code which is used by two react-map-gl components which are &lt;Marker/&gt; and &lt;ReactMapGL/&gt;. You can know more about react-map-gl from <a href="https://uber.github.io/react-map-gl/#/">this page</a>. State also has a popup info property (viz. Initially set to null) which contains vital information about pop-up like it’s latitude, longitude, name, etc, Now again it’s completely customizable you can add more details if you like. Now up next we have a function _updateViewPort which does nothing but updates the viewport config whenever you browser window resizes. After this we have _renderCityMarker function which as the name implies, does the job of rendering the markers in map and &lt;Marker/&gt; component in turn use &lt;CityPin/&gt; we created a few minutes ago, to render as marker. Next function is _renderPopup function which is indeed pretty similar to _renderCityMarker, It also accepts latitude and longitude parameters for positioning of component, And like &lt;Market/&gt;, &lt;Popup/&gt; also uses a child component &lt;CityInfo/&gt;. &lt;CityInfo/&gt; component displays info about the place, whose marker was clicked by the user. Now finally our render function which renders &lt;ReactMapGL/&gt; (imported from react-map-gl) with a certain config. It can accept a range of parameters as it’s config. You can refer to it’s documentation for more info. So in our case we provide it with viewport details, style of map, viewport change handler, mapBocApiToken (you can know how to get one from <a href="https://docs.mapbox.com/help/how-mapbox-works/access-tokens/#creating-and-managing-access-tokens">here</a>) and an array of cities which we ought to render on the map. Apart from this is also has few control buttons as child components, like &lt;FullscreenControl/&gt; to make map full screen and &lt;NavigationControl/&gt; component to provide navigation across map to user. With this we are done with our &lt;Component/&gt;. Now let’s make a step forward to make this boring map interactive by creating &lt;Chart/&gt; component.</p><p>Alright let’s move to chart.js file and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eec2c51305cbcdcab49852b16ebc3810/href">https://medium.com/media/eec2c51305cbcdcab49852b16ebc3810/href</a></iframe><p>So, as you can see it’s the component that we use to display our Bar Chart. We take help of components imported from react-vis to visualize data. You can know more about react-vis from <a href="https://uber.github.io/react-vis/">here</a>. To plot Bar Chart we use &lt;VerticalReactSeries/&gt; component. The data that we feed to the component is coming from &lt;App/&gt; component, so we’ll discuss structure of data when we reach there. Other than &lt;VerticalReactSeries/&gt; component we have &lt;LabelSeries/&gt; component as well which we use to print label at the top of every bar. Apart from the components we have function by the name of handleValueClick as well whose roots go till &lt;App/&gt; component. It’s sole duty is to inform react app about which bar was clicked by the user, depending on which our &lt;App/&gt; component filters data and passes those filtered cities to map component. Hence, we witness a filtered output. This is basically how we are transforming plain boring maps to much more fun to work with interactive maps. Alright so that’s pretty much for our chart.js, let’s begin creating chart.js up next.</p><p>Navigate to charts.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23cbc28fc7ce81e412ebcc1467c69d64/href">https://medium.com/media/23cbc28fc7ce81e412ebcc1467c69d64/href</a></iframe><p>Assuming that you have worked with react, Charts.js might be one of the components that you would have understood on your first glance only. Because It doesn’t do much other than toggling the charts. It comes with a couple of buttons , one of which is undo button which renders conditionally, it renders only when some filter is applied and other button is show/hide charts button which is rendered irrespective of any condition. I think the code is pretty much self explanatory so without any time let’s move on to app.js.</p><p>Open your app.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abfbfef89df69c86f23c1e76bb421b59/href">https://medium.com/media/abfbfef89df69c86f23c1e76bb421b59/href</a></iframe><p>Now this probably might be the most important component of the entire application, So let’s study it nicely. Let’s start with state. It’s state contains various things like loading (loading status), data (unfiltered data) , filtered_data (filtered data), booking_time_data (It is array which stores count of bookings made in every hour) , timee_filter (filter). Out of all of them Filtered Data is only used when some filter is applied. handleFiltering function is the one which filters data depending upon time it received as filter from &lt;Chart/&gt; component. handleResetFilter function is used to reset time_filter, it is triggered whenever user clicks undo button. Now here comes componentDidMount where quite some manipulation is taking place. So As you already know, there are two possible ways to proceed when you enter the application. One is supply your own data and second is to use default data. So depending on user choice we need to decide which server endpoint do we have to hit. After successfully getting result we check data for NULL values and store all the valid values in another array validData. One thing to note is that here we don’t store all the values, only those that we require and we customize some values as well as per need like in this case time_hour has been retrieved from booking_created. Now in the next few lines, we try to store count of bookings made round the clock in an array time_occur, Next we map over time_occur array and create new array of objects namely btd. This is very important data as it is the data would be fed to &lt;Chart/&gt; to visualize data. After all this is carried we set loading -&gt; false, data -&gt; validData and booking_time_data -&gt; btd. Now in render function when app is loaded we just render the &lt;Map/&gt; and &lt;Charts/&gt; components with relevant data. So that’s all for our app.js. Now let’s get &lt;Wrapper/&gt; component done.</p><p>Open your wrapper.js file and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c6563e00b8b416a8c0e2ac7be8c4d41/href">https://medium.com/media/9c6563e00b8b416a8c0e2ac7be8c4d41/href</a></iframe><p>So that’s how our wrapper.js looks like. In a nutshell it’s main task is to upload csv document to server, Nothing other than that. It also has form in render function to achieve exactly that, Depending on what did user chose, &lt;App/&gt; is rendered with their choice as prop and what happens after that you should be knowing by now already. So now we’re just left with styling.</p><p>You may download <a href="https://gist.github.com/AwesomeChap/e48a79d4039ac0c7cc809bc93ff480cd">app.scss</a> and <a href="https://gist.github.com/AwesomeChap/22eaf8344231ed098815c15228af8079">charts.scss</a>. Before running dev server.</p><p>Okay now that you have written all the code. Let’s check how it’s working. To run project locally we need to run two npm scripts across separate terminals.</p><pre>npm run dev <br>npm run start-dev</pre><p>Now you may visit <a href="http://localhost:3000/">http://localhost:3000</a> to see all the stuff we made moments ago, live in action. In case something did go wrong please cross verify your code with it’s completed version at github.</p><p><a href="https://github.com/AwesomeChap/Interactive-Maps-In-React">AwesomeChap/Interactive-Maps-In-React</a></p><p>I hope that you liked this tutorial, and if you enjoyed this post, I’d be very grateful if you’d help me spread it by sharing it to a friend, via Twitter or Facebook. And as always please do let me know in the comments how did you find this tutorial. That’s all I have for today’s tutorial, Let’s meet sometime again with some other insightful blog. Thank you for your precious time!.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccdfad460fa0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/techspace-usict/how-to-create-interactive-maps-in-react-js-ccdfad460fa0">How to create Interactive Maps in React.js</a> was originally published in <a href="https://medium.com/techspace-usict">Techspace</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fullstack CRUD application using Fastify, React, Redux & MongoDB Part-2]]></title>
            <link>https://medium.com/techspace-usict/fullstack-crud-application-using-fastify-react-redux-mongodb-part-2-cc37ea4187ff?source=rss-96aac838856a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc37ea4187ff</guid>
            <category><![CDATA[cogitans]]></category>
            <category><![CDATA[fastify]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Jatin Kumar]]></dc:creator>
            <pubDate>Mon, 27 May 2019 22:17:08 GMT</pubDate>
            <atom:updated>2019-08-30T14:07:58.829Z</atom:updated>
            <content:encoded><![CDATA[<h4>Let’s create something interesting</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TI11C91gChmUyO4vC9gTUQ.jpeg" /></figure><p>Hi there, This tutorial is the final installment of the my two part tutorial series, in which we are building a <strong>Fullstack Application</strong> using <a href="https://www.fastify.io/"><strong>Fastify</strong></a>, <a href="https://reactjs.org/"><strong>React</strong></a>, <a href="https://redux.js.org/"><strong>Redux</strong></a> and <a href="https://mongoosejs.com/docs/"><strong>MongoDB</strong></a>, which would support all <strong>CRUD </strong>functionalities. In case you didn’t read the first part, I’ll highly recommend you to do that before you move any forward because this tutorial would be the continuation of Part 1 and in order to understand what’s going on you are expected to have at least some basic understanding of our frontend that we made in Part 1. You don’t need to know meaning of every single line we wrote there. You just need to know about how the data is flowing across the app and what event handlers are making things as they are. A quick skim of the blog will do the job. File structure was discussed early on in the Part 1 blog, So you just need to create clone of that file structure and copy the respective codes in the their corresponding files and you are good to go. You can read Part-1 from <a href="https://medium.com/@jatin15011999/fullstack-crud-application-using-fastify-react-redux-mongodb-part-1-9e8df39c6fff">here</a>.</p><p><a href="https://medium.com/@jatin15011999/fullstack-crud-application-using-fastify-react-redux-mongodb-part-1-9e8df39c6fff">Fullstack CRUD application using Fastify, React, Redux &amp; MongoDB Part-1</a></p><p>So, now that you have skimmed the blog and have the code of React Redux app that we built in Part 1. I expect you to have some basic understanding of the current code base. So, if you played with the incomplete version of the app that we built in part 1, you may have realized that it lacks persistence to changes. Our redux store is wiped out every time we reload the application. So, in this Part of tutorial series we’ll be making our application persistent to changes. As a bonus section I’ll also guide you over deployment process. So without wasting any time, Let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*dos4T4mVKwuatfWOloI4FA.gif" /></figure><h3>Project Setup for Server</h3><p>If you remember from Part 1, we already have a project setup. We just need to fill up our vacant server directory with some server related files. so let’s get this done. <br>Navigate to server/ &gt; Open your terminal &gt; execute the commands shown below.</p><pre>touch controller.js routes.js server.js<br>mkdir models<br>cd models &amp;&amp; touch menuItems.js <br>cd ../../ &amp;&amp; touch .env</pre><p>Open .env and paste couple of lines given below</p><pre>NODE_ENV=development<br>MONGO_ATLAS_PW=&lt;USER_PASSWORD&gt;</pre><p>Now you must be having your file structure inside server directory quite similar to as shown below</p><pre>|<strong>server<br></strong>|--<strong>models<br></strong>|----menuItems.js          // contains schema<br>|--controller.js           // contains controllers<br>|--routes.js               // contains routes<br>|--server.js               // contains fastify server<br>|.env                      // contains user defined env variables</pre><p>Now let’s install some node modules that we’ll require for this part of the tutorial</p><pre>npm i --save axios dotenv fastify fastify-static mongoose</pre><p>After getting required modules installed we are ready to write some code. We’ll start by building backend api using fastify + MongoDB and then in later half of the tutorial we’ll spending time in connecting our fastify backend api to our react redux frontend.</p><h3>Backend API</h3><p>In this section We’ll create Mongoose Schemas, controllers, routes, and then finally our fastify.js server. Let’s kick off with building our mongoose schema.</p><p><strong>Step 1:</strong> Open server/models/menuItems.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/127d486aaef5c2fecc39f26e31e52c28/href">https://medium.com/media/127d486aaef5c2fecc39f26e31e52c28/href</a></iframe><p>So that’s how our mongoose schema looks like. Here we are having an id property which stores the id that we create with the help of uuid.v4() in our &lt;Menu/&gt; component. We also have name and price which would store name and price of the item respectively. After creating schema we create a model which is then exported so that other files like controller.js could make use of it. Next up we’ll create controllers.</p><p><strong>Step 2:</strong> Open server/controller.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3815e31af2aaf2a63c81a297f2a11ee/href">https://medium.com/media/c3815e31af2aaf2a63c81a297f2a11ee/href</a></iframe><p>So that’s our controllers. Controllers are basically not so different from event handlers that we use in react. It’s just that their way of getting triggered is different. Each controller defined above would be attached to a route and whenever that particular route will be requested, the responsible controller will get invoked. Here we are avoiding chaining of promises by making use of async and await. In case you never heard these terms before, you can visit <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function">here</a> to know more about them. Now let’s discuss all the controllers one by one.</p><ul><li>fetchItems : As name implies it’s used to fetch all the items present in database. It takes benefit of find() API provided by mongoose. Here we don’t pass any argument to it, that’s why it returns every single item present in database.</li><li>addItem: It’s used to add a new Item to database. Here we first create a new Item by creating a new instance of MenuItem model. Content for new item is received via req.body. After creating new item, we add it to database using save() API provided by mongoose.</li><li>updateItem: It’s used to update item. Here we use findOneAndUpdate() API provided by mongoose to find item with the id = req.params.id and update it’s content, which we receive via req.body.</li><li>deleteItem: It’s used to delete a certain item whose id matches with id that it receives as argument. It takes help of findOneAndUpdate() API provided by mongoose.</li></ul><p><strong>Note :</strong> In case you are curious that why we are not using findByIdAndUpdate() and findByIdAndDelete() as we are doing of all manipulations in data using id, then you should know that they only work with _id(which mongoose generates automatically every time an item is created). And the id that we are using is not equal to _id . The id that we are using comes from the React frontend and it get’s generated using uuid.v4() whenever we add item to our redux store. We are using it because along with MongoDB Database we are also managing a redux store. And when we save items to database we don’t fetch the created item simultaneously, instead we save them locally as well in redux store and work with that copy. We do this to provide better user experience and It’s a very popular practice among react developers in which we’re updating the client locally before waiting to hear from the server. It’s also commonly referred to as <strong>optimistic updating</strong>. So basically our react frontend at the time of creating items is unaware of _id property till it fetches the item from database which only happens when we load or reload our application. So if we use _id instead of id then apparently our redux functionality would break. And I don’t think that requesting data from database every time we make changes in your application would be performance efficient under slow connections. So that’s why apparently we are managing two ids _id and id and why we are using findByIdAndUpdate() and findByIdAndDelete(). If all that’s confusing to you forget about it and return here after finishing this tutorial, then you’ll understand what I am trying to say exactly.</p><p>So that’s all for our controller.js, Next up we’ll setup routes and make these controllers useful by attaching them to appropriate ones.</p><p><strong>Step 3:</strong> Open server/routes.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c9caf36547aeed0bafa019cc43aecc7/href">https://medium.com/media/2c9caf36547aeed0bafa019cc43aecc7/href</a></iframe><p>So that’s what our routes.js looks like, In this notation we are specifying a method , url, and handler for every individual router. Here we are assigning a appropriate controller to every route as a handler. Whenever we request any route, the corresponding controller get’s invoked i.e. when we request GET &lt;domain_name&gt;/api/menuItems , fetchItems get’s invoked immediately and returns result. Next up we’ll be wrapping up with our backend API by creating our fastify server.</p><p><strong>Step 4:</strong> Open server/server.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f9580a7cc972226956351664c782886/href">https://medium.com/media/7f9580a7cc972226956351664c782886/href</a></iframe><p>So that’s our fastify server. Now before we go any further, we don’t have any database yet. so let’s get this done quickly. For the time being we’ll be using MongoDB Atlas. In case you are new to MongoDB Atlas, please visit there <a href="https://docs.atlas.mongodb.com/getting-started/">getting started guide</a> to setup the project (and while doing setup don’t load any sample data, we don’t require it). After successfully setting up the project click on connect button and then select connect your application and copy the connection string. Now open your server.js file and locate mongoose.connect. After finding it replace old connection string with the new one that you just copied in your server.js. Okay so, if you followed the getting started guide correctly you must have added a user. Now, open .env file and replace the &lt;USER_PASSWORD&gt; with your actual user password. Now I think we have the required setup to go ahead.<br>Now if everything goes right you must be seeing the two log statements shown below in your console when you run node server/server.js.</p><pre>server running at 3000<br>MongoDB connected</pre><p>And if you navigate to <a href="http://localhost:3000/">http://localhost:3000</a>. You must be seeing {msg : hello, world!} in your browser as output.</p><p>Now let’s discuss our server in detail. So first off we connect to our database. And then we’ve placed a dummy route which currently does nothing special than printing {msg : hello, world!} but later on it would play an important role as it will be serving our react application. In next instruction we iterate over all of the imported routes (that we created inroutes.js) and register them with fastify (which in a nutshell means that we’re making fastify aware of routes that we’ve declared elsewhere). After doing it we bind our server to a port using fastify.listen()</p><p>So that’s all for our backend API. Now let’s test our API and best tool to do it is <a href="https://www.getpostman.com/">Postman</a>. We will be sending our data as raw objects in the body of the request and as parameters. <strong>Don’t forget to run server before testing API</strong>.</p><p><strong>Saving Item to Database</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LduB4iTjFHeWNzQ6WFQsrA.png" /></figure><p><strong>Reading all the items</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NT9BDMideMHDHQD2wLE_eA.png" /></figure><p><strong>Updating item</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-UL6sN7DeD8r4Dj9GmK1A.png" /></figure><p><strong>Deleting Item</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jR_aeAf8vzT7q3z3rvXp7Q.png" /></figure><p>We now have a fully functional API — but what about the React Frontend? Let’s wire up them together up next! I assure you it would be fun.</p><h3>Wiring up React with Fastify</h3><p><strong>Step 1:</strong> Serve react app using fastify server</p><p>If you see your project directory you’ll notice that there is folder named dist (provided that you have built react frontend at least once) that we didn’t create. It actually contains compiled form of our react app and it get’s created automatically every time we build our react app using parcel. So in order to host our react application we just need setup the dist directory as default lookup folder for our server. So that if we’re required to send index.html from any of our route handler, we can just send index.html and our server will by default always send index.html present in dist. All this can be accomplished using fastify-static module. Add the code shown below in your server/server.js to see it in action yourselves.</p><pre>const DistPath = path.join(__dirname, &#39;..&#39;, &#39;dist&#39;)</pre><pre>fastify.register(require(&#39;fastify-static&#39;), {<br>  root: DistPath,<br>})</pre><p>Now let’s get rid of {msg : hello, world!} and host our react app on / route instead. It can be done very easily. We just need to replace<br>return {msg: hello, world! with reply.sendFile(&#39;index.html&#39;)</p><p>Now run your app using node server/server.js and if everything goes well you would see your react application up and running on <a href="http://localhost:3000/">http://localhost:3000</a> like shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*P9S_f6WVRNTv0J3V_q1www.png" /></figure><p>Ok so we finally have something meaningful to see when our server starts but the problem of volatile changes still exists. Well, Now that’s because we have not yet updated our frontend, to make it interact with fastify server and take benefit of the database. In order to achieve that we just need to modify three files namely actions.js , reducer.js and menu.js . So let’s start by our actions file.</p><p><strong>Step 2: </strong>Modify src/redux/actions/actions.js</p><p>In Here we’d be modifying readItems action creator to make it capable of fetching data from the database. Currently this action creator does nothing special than returning an object with type : READ we would be modifying it to return a function instead which would in return also dispatch some action creators but conditionally. But we know that normally an action creator can only return objects, So in order to override this traditional behaviour we would be using redux-thunk module. You have installed it already in Part 1 so no need to install it again. Until now it’s need didn’t arise so we didn’t use it but we will now. In case you never heard this module before, you can know about redux-thunk in great detail <a href="https://www.npmjs.com/package/redux-thunk">here</a>. But in a nutshell it’s just a module which let’s us write action creators which can return functions (which in turn also dispatches actions creators but conditionally) instead of an conventional action. As we discussed few lines above the returned function would also be dispatching some action creators So, let us first see what these extra action creators actually are -</p><pre>export const FETCH_ITEMS_BEGIN = &quot;begin fetching items&quot;;<br>export const FETCH_ITEMS_SUCCESS = &quot;Items fetched successfully&quot;;<br>export const FETCH_ITEMS_FAILURE = &quot;Failed to fetch items&quot;;</pre><pre>export const fetchItemsBegin = () =&gt; ({<br>    type: FETCH_ITEMS_BEGIN<br>})</pre><pre>export const fetchItemsSuccess = items =&gt; ({<br>    type: FETCH_ITEMS_SUCCESS,<br>    payload: { items }<br>})</pre><pre>export const fetchItemsFailure = errors =&gt; ({<br>    type: FETCH_ITEMS_FAILURE,<br>    payload: { errors }<br>})</pre><p>So what do we have here, we have three new action creators let’s study their functionality one by one.</p><ul><li>fetchItemsBegin dispatches when we initiate fetching/loading data from database.</li><li>fetchItemsSucces dispatches when we have successfully fetched the data. And it is dispatched with a payload property which contains the items that were fetched.</li><li>fetchItemsFailure dispatches when any sort of failure occurs while fetching data from database. It also has a payload property which contains the errors.</li></ul><p>These action creators have no importance on there own. They are not used independently rather they all are wrapped inside a function which dispatches them conditionally so let us discuss this function.</p><pre>export const readItems = () =&gt; {<br>  return (dispatch) =&gt; {                     // function starts<br>    dispatch(fetchItemsBegin());             // fetching begins<br>    return axios.get(&#39;/api/menuItems&#39;)       // req data from server<br>      .then(({data}) =&gt; {                    // if data is found<br>        dispatch(fetchItemsSuccess(data));   // success <br>      })<br>      .catch(error =&gt; dispatch(fetchItemsFailure(error))); //errors<br>  }<br>}</pre><p>So here is our modified readItems action creator, which returns function as opposed to action object. The function in turn dispatches fetchItemsBegin in order to indicating that fetching has started, then we request data from server and depending on result dispatch either fetchItemsSuccess or fetchItemsFailure. If data is fetched successfully fetchItemsSuccess is dispatched (with fetched data as argument) or in case some failure occurs fetchItemsFailure is dispatched (with failures that occurred as argument). So that pretty much sums up what our modified readItems action creator does and looks like. You may find the complete actions.js <a href="https://github.com/AwesomeChap/Fastify-React-E-Menu/blob/master/src/redux/actions/actions.js">here</a>.<br>Now let’s modify reducer to handle the new action creators we just created.</p><p><strong>Step 3:</strong> Modify src/redux/reducers/reducer.js</p><p>Let’s first import new action types which we need to handle.</p><pre>import { FETCH_ITEMS_BEGIN, FETCH_ITEMS_SUCCESS, FETCH_ITEMS_FAILURE } from &#39;../actions/actions&#39;;</pre><p>Now how are we gonna handle them ? Okay so I’ll explain point wise how every action is going to be handled and then we’ll see all that in code. So here we go.</p><ul><li>FETCH_ITEMS_BEGIN : nothing would change except loading would be set to true.</li><li>FETCH_ITEMS_SUCCESS : loading would be set to false and menuItems array would get filled with data received from server.</li><li>FETCH_ITEMS_FAILURE : loading would be set to false , menuItems array would be truncated and errors would be set to errors found.</li></ul><p>Now let’s see how we implement all this via code.</p><pre>case FETCH_ITEMS_BEGIN: return {<br>  ...state,<br>  loading: true,<br>  errors: null<br>}</pre><pre>case FETCH_ITEMS_SUCCESS: return {<br>  ...state,<br>  loading: false,<br>  menuItems: action.payload.items<br>}</pre><pre>FETCH_ITEMS_FAILURE: return {<br>  ...state,<br>  loading: false,<br>  errors: action.payload.errors,<br>  menuItems : []<br>}</pre><p>Okay so by now, you must have understood how the the newly created actions are handled by the reducer both conceptually and by means of code. You may find the final version of reducer <a href="https://github.com/AwesomeChap/Fastify-React-E-Menu/blob/master/src/redux/reducers/reducer.js">here</a>.</p><p>Now we are only left with triggering of appropriate server endpoints by making appropriate HTTP requests from client side when we do one of the following Create data, Fetch data, Update data, Delete data. This can be accomplished with the help of a HTTP Client. So let’s get this done next up.</p><p><strong>Step 4: </strong>Modify src/menu.js</p><p>HTTP client that we’ll use in this tutorial is <a href="https://www.npmjs.com/package/axios">axios</a> (feel free to use fetch or any other HTTP client that you like, it hardly makes any difference). Now let’s import it at the top.</p><pre>import axios from &#39;axios&#39;; </pre><p>In order to read data from database, we just need to call the readItems action creator and nothing more. i.e. we don’t need to make any HTTP request,readItems does all by itself internally. We need to call readItems as soon as app loads or reloads, or in other words when component mounts so that our redux store get’s filled with data automatically as soon as app loads or reloads. Therefore we’ve placed it in componentDidMount life cycle method . Code for this is shown below.</p><pre>componentDidMount() {<br>  <strong>this.props.readItems();</strong><br>}</pre><p>In order to add data, we need to make HTTP POST request at /api/menuItems with data of new Item to be created and it sends response in form of added Item details. It is placed in handleAddItem handler, so that Item gets added to database as soon as person clicks Add button, let’s see code for this.</p><pre>handleAddItem = ({ name, price }) =&gt; {<br>...       <br>...<br>  <strong>axios.post(&#39;/api/menuItems&#39;,{...newItem}).then(({data:{name}})=&gt;{ <br>    console.log(`Item - ${name} added successfully`);   <br>  }).catch(e =&gt; console.log(&quot;Addition failed , Error &quot;, e));</strong><br>...<br>...         <br>}</pre><p>In order to modify a particular item having id equals to id,we need to make a HTTP PUT request at /api/menuItems/:id with the data needs to be corrected. In response server sends the copy of updated item. It is placed in handleUpdateItem handler, Code for this is shown below.</p><pre>handleUpdateItem = (item) =&gt; {<br>...<br>...<br>  <strong>axios.put(`/api/menuItems/${item.id}`,{item}).then(({data})=&gt;{<br>    console.log(`Item - ${data.name} updated successfully`);<br>  }).catch(e =&gt; console.log(&#39;Updation failed, Error &#39;,e));</strong><br>...<br>...<br>}</pre><p>In order to delete a particular item having id equals to id. We just need to make a HTTP DELETE request at /api/menuItems/:id . In response it sends data of deleted Item back. It is placed in handleDeleteItem. Code is shown below.</p><pre>handleDeleteItem = (id) =&gt; {<br>...<br>...<br>  <strong>axios.delete(`/api/menuItems/${id}`).then(({data:{name}}) =&gt; {<br>    console.log(`Item - ${name} deleted successfully`);<br>  }).catch(e =&gt; console.log(&quot;Deletion failed, Error &quot;,e));<br></strong>...<br>...<br>}</pre><p>That’s all that for our menu.js. You may find the final code of menu.js <a href="https://github.com/AwesomeChap/Fastify-React-E-Menu/blob/master/src/menu.js">here</a>.<br>We are pretty much done with interconnecting our front to backend. And if you run your application now you’ll see that data is persistent and it stays even after application is reloaded. Don’t forget to build you react app before serving it. You may use parcel build src/index.html to build your react app. <br>In case you experience some errors please refer to final code of this app present on <a href="https://github.com/AwesomeChap/Fastify-React-E-Menu">GITHUB</a>.<br>Okay, so now we are only left with Deployment process. If you want see how you can deploy any application having stack similar to this ,then please follow along.</p><h3>Let’s make it Live</h3><p>I’ll be using <a href="https://heroku.com/">Heroku</a> to deploy our application. In order to deploy any node app to heroku please follow these steps shown below.</p><ol><li>In your fastify/node server, ensure that your port is declared like this port = process.env.PORT || 3000 . If you are not using process.env.PORT then your application is likely not detect dynamic ports and would crash very often in dyanmic environments like heroku.</li><li>Ensure that Git is added to the project. If not just execute git init and create a .gitignore file as well to ignore the data we don’t want to add to git. which in this case are /node_modules , package-lock.json , .cache</li><li>Now in order to stage all the files run git add . and in order to commit run git commit -m &quot;any message&quot;.</li><li>I expect you to have heroku cli, if you don’t then please insall it before proceeding. After you have installed heroku cli execute the commands shown below.</li></ol><pre>heroku create &lt;Application_name&gt;<br>git push heroku master<br>heroku open</pre><p>Note : In case of some error, you can run heroku logs --tails. To what went wrong.</p><p>Now if all things went good, within few minutes you will be able to see your application live on web.</p><p>So that’all folks, I hope that you liked the two part tutorial series in which we built a Fullstack Fastify React Application completely from scratch, Through out this tutorial we covered various concepts like Optimistic updating, React Redux concepts, etc. I hope that you learnt some new things from the tutorial and I wish you luck for the future</p><p><em>If you liked this post,</em> <em>I’d be very grateful if you’d help it spread by sharing it to a friend, via Twitter or Facebook. And as always please let me know in comments how did you find this tutorial. Thank you!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc37ea4187ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/techspace-usict/fullstack-crud-application-using-fastify-react-redux-mongodb-part-2-cc37ea4187ff">Fullstack CRUD application using Fastify, React, Redux &amp; MongoDB Part-2</a> was originally published in <a href="https://medium.com/techspace-usict">Techspace</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fullstack CRUD application using Fastify, React, Redux & MongoDB Part-1]]></title>
            <link>https://medium.com/swlh/fullstack-crud-application-using-fastify-react-redux-mongodb-part-1-9e8df39c6fff?source=rss-96aac838856a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e8df39c6fff</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[mongodb-atlas]]></category>
            <category><![CDATA[fastify]]></category>
            <dc:creator><![CDATA[Jatin Kumar]]></dc:creator>
            <pubDate>Sat, 25 May 2019 10:21:17 GMT</pubDate>
            <atom:updated>2020-02-21T15:51:38.947Z</atom:updated>
            <content:encoded><![CDATA[<h4>Let’s create something interesting</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MPEAKGH5rureF4oONvpYDA.jpeg" /></figure><p>Hi, there. I hope that you are having a good time. Now let’s make it even better. In today’s tutorial we’ll be building a <strong>Fullstack Application</strong> using <strong>Fastify</strong>, <strong>React</strong>, <strong>Redux</strong> and <strong>MongoDB</strong>, which would support all <strong>CRUD</strong> functionalities. The application that we are about to build is a simple menu app that lists all the menu items currently present in the database, In this application, you would be able to create menu items, which could hold details like item-name and item-price. You could also modify them or even delete them. If you want to see all these features live in action, feel free to check out it’s completed version live <a href="https://e-menu-v1.herokuapp.com/">here</a> and play with it, till you are able to get a high-level grasp of what you’ll be building throughout the rest of this tutorial. The final source code of the application is available <a href="https://github.com/AwesomeChap/Fastify-React-E-Menu">here</a>. This tutorial would be a two-part series, In its first installment we would be building a static implementation of Web App using React and Redux, And in our second installment we’ll be wrapping up with app by adding a Fastify.js backend and MongoDB database. <br>Seeing the popularity of React, Redux, Fastify, and MongoDB. It would be pretty interesting to find out how they all aces work in conjunction. So lets without wasting any time dive right in!</p><h3>Things to know before getting started</h3><p>This tutorial is for anyone who is interested in learning new things and has some basic knowledge of <strong>React</strong>, <strong>Redux</strong>, <strong>MongoDB, </strong>and <strong>RestAPIs </strong>in general. React developers who haven’t coded for a while yet, can also follow along in order to get back in their old form. Though I would be giving my best to explain each piece of code as we build the app. But it would be of great help if you have you have some basic understanding of core concepts already. In addition, we’ll be using quite some ES6 syntax, so it would be pretty good if you know some of them already like arrow functions and spread operator.</p><p>So, Enough of talking, let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*25iRddDjlHXlA8mY1ofHWg.gif" /></figure><h3>Project Setup</h3><p>Before moving on please ensure that you have <strong>node.js</strong> installed in your machine, If not then please get it installed before heading forward. You can install node.js from its official site <a href="https://nodejs.org/">https://nodejs.org</a></p><p>After getting node.js installed, Now let’s start by initializing our project by executing commands shown below in your terminal.</p><pre>mkdir fastify-react-crud<br>cd fastify-react-crud<br>touch .babelrc<br>mkdir server                     <br>mkdir src &amp;&amp; cd src<br>touch index.html index.js menu.js menu.css<br>mkdir components &amp;&amp; cd components<br>touch form.js menuItem.js<br>cd ..<br>mkdir redux/actions<br>mkdir redux/reducers<br>mkdir redux/store<br>cd redux/actions &amp;&amp; touch actions.js &amp;&amp; cd ../../<br>cd redux/reducers &amp;&amp; touch reducer.js &amp;&amp; cd ../../<br>cd redux/store &amp;&amp; touch store.js cd ../../../../</pre><p>Alright!, So that was a lot of setup code. But we were going to do it anyway, so I preferred to keep them stacked together so that we have the least chances of getting differences in our file structure. <br><strong><em>Note:</em></strong><em> In case you are on windows and are using windows Powershell, Please shift to git bash/cmd because concatenation of commands using </em><em>&amp;&amp; operator doesn’t go well with windows PowerShell.</em> <br>Now let’s install some npm packages to get going. We’ll start by building our View Layer. So let’s install some packages required to build our React frontend.</p><p><em>Note: We’ll be using </em><a href="https://parceljs.org/"><strong><em>Parcel Bundler</em></strong></a><em> to develop our react frontend. In case you are unaware of the parcel, then you should know that in a nutshell, it’s nothing more than an application bundler similar to webpack. We’ll be using the parcel as it’s just comparatively easy to set up and work with.</em></p><p>Now if you had executed the shell commands right, you must already be in the project root. But in case for any reason you are not, please navigate to your project root and execute commands shown below.</p><pre>npm init -y<br>npm i --save react react-dom redux react-redux redux-thunk uuid <br>npm i --save redux-devtools-extension<br>npm i --save-dev parcel-bundler <br>npm i --save-dev @babel/plugin-proposal-class-properties</pre><p>open package.json and add dev script shown below</p><pre>&quot;scripts&quot;: {<br>   &quot;dev&quot;: &quot;parcel src/index.html&quot;<br>}</pre><p>Now, open .babelrc and copy-paste the line shown below. So that we can use arrow functions in our React components.</p><pre>{ <br>   &quot;plugins&quot;: [ &quot;@babel/plugin-proposal-class-properties&quot; ]<br>}</pre><p>After having all the commands executed successfully, you must be having your project file structure quite similar to like this.</p><pre><strong>fastify-react-crud</strong><br>|--<strong>node_modules</strong>        // contains node modules<br>|--<strong>server</strong>              // will contain server related files<br>|--<strong>src</strong>                 // will contain cleint side related files<br>|----<strong>components        </strong>// will contain child components of menu.js<br>|------form.js         // form component for Addition &amp; Updation<br>|------menuItem.js     // component to display menu item<br>|----<strong>redux             </strong>// contains redux related files &amp; folders<br>|------<strong>actions         </strong><br>|--------actions.js    // contains redux actions<br>|------<strong>reducers</strong><br>|--------reducer.js    // contains redux reducer<br>|------<strong>store</strong><br>|--------store.js      // here we create redux store<br>|----menu.css          // will contain css code <br>|----menu.js           // will contain react code<br>|----index.html        // will contain html template<br>|----index.js          // will contain react code<br>|--package.json<br>|--.babelrc            // babel plugin config</pre><h3>Let’s start building our React-Redux Frontend!</h3><h4>Quick Structure Analysis</h4><p>If you have seen the demo already, then the image shown below might seem quite familiar to you. If you’ve not visited the demo link yet, I’ll highly recommend you to visit. Because it would give you a broader picture of the project that we are about to make.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z2e1MQEpzToJcMxAjPYI8Q.jpeg" /><figcaption>Application component structure</figcaption></figure><p>Now after you have seen the demo, You can easily interpret by seeing the above image, that our App consists of &lt;Menu/&gt; component, which wraps major functionality of our application. Later as we start coding you’ll get to know that it’s also kinda powerhouse of our application because this is the only component in our application that would be communicating with the redux store. As we go one layer deep &lt;MenuItem/&gt; component comes to our notice, It displays the data in really nice formatted fashion and besides that, it also provides us with the ability to Modify and delete data using their respective buttons. When you click on the Edit button or Create New Item Button, you would unlock another component which is &lt;Form/&gt; component. It is a very important component because this single component is used in two different situations i.e. Addition of Items and Modification of items. It also has his own set of functional buttons using which we can either submit our data or cancel the request which can be either of addition or update. So, Now that you have understood what individual component actually does or at least what it’s supposed to do. I think we are ready to get our hands dirty with some code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*odVyZKENlx1o0Pzmbp-Vtg.gif" /></figure><p>Let’s start by Redux first, So that later on when we build components we know what’s happening under the hood and how is it happening</p><h4>Enter Redux!</h4><p>Okay, Now In case you are confused about some basics of <strong>redux</strong>, like what does what or what is the relationship between them, then the image shown below might clear some mist around it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*deN7yEHpE8LGw9ayO8dLOg.png" /></figure><p><strong>Step 1:</strong> Lets start by defining some action, Open src/redux/actions/actions and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c197d4102c2e6b55ae61908e6674ed39/href">https://medium.com/media/c197d4102c2e6b55ae61908e6674ed39/href</a></iframe><p>Now in case you are wondering what action is ? then you should know that in a nutshell, it’s job is only to trigger some piece of code defined in reducer, which would, in turn, update the store depending on the type of action and that’s it, nothing more! You might have already observed a pattern from code above, that an action creator always returns an action object. The action object that’s to be sent by action creator essentially expects two properties namely type and payload. Of both type is mandatory to be specified no matter what. for eg. readItem action creator doesn’t require a payload but would not work without type property. Now in case you are wondering what a payload actually is? then Basically it’s just a piece of data that is sent from our view layer to reducer for a variety of purposes, for eg. Create, Update, Delete. Now coming back to our actions file, here we have</p><ul><li>createItem : It accepts item to be created as it’s payload and it’s dispatched when we want to add a new item</li><li>updateItem : It also accepts item to be updated as it’s payload and it’s dispatched when we need to update any item.</li><li>deleteItem : It accepts id of the element to be removed as it’s payload and it’s dispatched when we need to delete any item.</li><li>readItems : It is dispatched to read items from redux-store. It doesn’t have any payload yet. But in the next part of the tutorial, it would play an important role, as it would be used to fetch items from the database.</li></ul><p>Now I think actions are all clear, let’s try to clear our next hurdle i.e. reducers</p><p><strong>Step 2</strong>: Open src/redux/reducers/reducer.js and copy code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ada8ac60f8be40fa52ac0411c504d92f/href">https://medium.com/media/ada8ac60f8be40fa52ac0411c504d92f/href</a></iframe><p>So, that’s what our reducer looks like, like all ordinary reducers we have</p><ol><li>An initial state for store represented by initialState variable</li><li>we have reducer function which expects two arguments namely, state and action.</li></ol><p>Whenever we dispatch an action creator it sends an action object to reducer (You should be nodding right now). That object has a mandatory property type . And that’s mandatory because we require type in order to identify an action distinctly from others, you can think of it as an id for the action. Depending on the type of action, Our reducer decides whether to Create items, Read items, Modify items or Delete items. But whatever it decides it has done it by not mutating the original state. Because in case you mutate state, the store’s state may get updated but react will not detect it and you would not be able to witness changes in your react app. FYI 90% of errors in any redux app happens due to a mutated state. So, always be careful to not accidentally mutate the state while working with the redux app.</p><p>In order to work with immutability, we need to create a copy of the original state. There are generally 2–3 ways to do it. I have used the latest and easiest of all, which is by using the spread operator. If it’s new to you, feel free to visit docs <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax">here</a>. I can not discuss more about “immutability” right now, because it’s a topic which demands it’s own tutorial, so we’ll leave it here only. For now, you only need to know that [...array] is a copy of and array and {...object} is a copy of an object. Now, Let’s get back to our reducer.</p><ul><li>In our state, we have a menuItems property which is of type array.</li><li>On action type CREATE we add an item to menuItems array and send a new state back to our view.</li><li>In case of action type READ we simply return the stored state.</li><li>In case of UPDATE we map over the copy of the menuItems and send the state after updating the content of the desired item. One important thing to notice here is that here we don’t need to make a copy of menuItems it because when we use map to iterate of elements, a new copy of the array is automatically created and returned. But I have done it just for double safety (Ya that’s the fear of mutating the state xD).</li><li>Now in case of DELETE we simply return the filtered array by ignoring the item which has id similar to what was passed in the payload.</li></ul><p>That’s It for our reducer. I hope, that you were able to understand the reducer. Let’s bind up with the redux section by creating store.</p><p><strong>Step 3</strong>: Open src/redux/store/store.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eda8ca5d34bc9bd51eaff0e6d7da4236/href">https://medium.com/media/eda8ca5d34bc9bd51eaff0e6d7da4236/href</a></iframe><p>So, now that’s the shortest piece of code in the whole project. Well, it imports quite some things. Let’s discuss all in brief quickly. createStore is used to create a redux store, applyMiddleware is used to add middlewares (middleware provides a third-party extension point between dispatching an action, and the moment it reaches the reducer). Next up is thunk. It allows us to write action creators that return a function instead of action (It would come handy when we will be fetching data from the server, but not now ;)). It also imports reducer which I don’t think requires any explanation. Now last import is composeWithDevTools which we use in order to take advantage of redux dev tools along with custom middlewares. After importing we create a middlewares array and add thunk to it. Now as a final step we create a store using createStore and export it. We’ll be importing it in index.js later in this tutorial. So that’s all for the <strong>redux</strong> but to see the functionality we build, we require View Layer so let’s get this one done quickly using React!</p><h4>Let’s create something presentable!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*-iea6ASvz6qQTmOMY_o8LQ.gif" /></figure><p><strong>Step 1:</strong> let’s start with index.html, Open index.html and copy the code shown below.</p><p>This code above is all self-explanatory we just have a link tag for font awesome icons, which we use in buttons. It’s completely optional you can write texts in buttons instead if you desire. Besides the link, we have also a script tag to import index.js.</p><p><strong>Step 2</strong>: Now, navigate to src/index.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11479abeae7724ed39916991018a9f41/href">https://medium.com/media/11479abeae7724ed39916991018a9f41/href</a></iframe><p>This is the outermost wrapper component of our react app, It was skipped during structure discussion. Actually It doesn’t do much besides making the store available to our Menu component. Other than that rest must be self-explanatory. Now next up we’ll be building &lt;Form/&gt; component, It would be going to be quite interesting at least as compared to the first two steps xD.</p><p><strong>Step 3</strong>: Now, Open src/components/form.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c6ac4992da136a58e1eb8557ee56403/href">https://medium.com/media/0c6ac4992da136a58e1eb8557ee56403/href</a></iframe><p>So that’s what our &lt;Form/&gt; component looks like, If you read the code once, You would realize that it’s nothing more than an ordinary form having two input fields and two buttons that are used to submit and close the form. When we press submit button handleSubmit function gets invoked and on pressing, cancel button handleCancel function gets invoked. They both make further calls to respective functions in the parent component. For time being just forget about these parent component’s functions. Just remember that handleSubmit sends the form data to the parent component and handleCancel closes the form and that’s it. We’ll learn about these parent component’s functions in detail later, till the time you should just know that what they do.<br>All right now let’s talk about its state, you can see that we are not taking it empty by default rather we check for props and initialize state with values passed in props in case they were. That’s because our &lt;Form/&gt; component is a <strong>multipurpose component</strong>, It is used as Create Item Form as well as Edit Item Form, so when it’s used as Create Item Form no props are passed so the state remains empty and the user sees empty fields as they should. But when it’s used as Edit Item Form, props are passed and input fields get filled with values passed in props thus the user is able to see the value that he/she is about to edit.<br>Now next up is our handleChange function, It basically changes the state of name and price whenever values in input fields are changed. It’s able to do so because it’s attached to both of the input field’s onChange events and get’s triggered whenever the value in input is changed. Inside the function we use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">object destructuring</a> to extract name and price from state. and change the relevant state property which is decided by the value of e.target.name (It only works when input field has name attribute).So that was our &lt;Form/&gt; component for you, next up we’ll write code for menuItem.js</p><p><strong>Step 4</strong>: Now let’s build&lt;MenuItem/&gt; . You may open src/components/menuItem and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbe4aba9966ba76713d2855c30b5bd37/href">https://medium.com/media/dbe4aba9966ba76713d2855c30b5bd37/href</a></iframe><p>Now It may have a few more lines of code as compared to &lt;Form/&gt; component discussed above a while ago. But it is quite simpler compared to it in terms of functionality. Similar to &lt;Form/&gt; we also have a state which we initialize with the values passed by the parent component. But in this scenario, we opt for a different technique to do it rather than initializing directly in the constructor which is sometimes not recommended though. In &lt;MenuItem/&gt; we use componentDidMount lifecycle method to update the state with the props whenever component mounts. Apart from name, price we also have openEditForm property in our state which is component-specific and it has nothing to do with its parent component. openEditForm is basically used to toggle Edit Item Form. It doesn’t have any more applications. Similar to &lt;Form/&gt; It also has a pair of buttons, but their functionality is quite different. Two Buttons are Edit and Delete. When Edit button is pressed handleEditClick function is invoked which sets openEditForm to true which in turn opens the form to edit items and whereas when the Delete button is pressed handleDelete is invoked. In addition, there is also handleUpdate function which gets invoked whenever a user submits after editing i.e. sends update request. Both handleDelete &amp; handleUpdate make further calls to functions defined in &lt;Menu/&gt; component in order to actually delete and update the item from storage. We will look at these functions in menu.js next up in great detail. So that’ all for &lt;MenuItem/&gt;, let’s see up next what &lt;Menu/&gt; has us to offer.<br>Note: when handleUpadte is invoked it also sets openEditForm back to false which toggles form and lets us see the saved content of that item.</p><p><strong>Step 5:</strong> Now let’s open src/menu.js and copy the code shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9ff2db5109a229ca700364e1132f152/href">https://medium.com/media/f9ff2db5109a229ca700364e1132f152/href</a></iframe><p>Alright Now that’s quite a lot of code compared to the first 2 entries. But that’s just because it handles a lot of functionality. All our create, update, deletion in the store are initiated from this component only. I have commented on every useful block of code and I am confident that if you go through it once on your own, you would get a good percentage of code in your first attempt only. Because it’s just lengthy otherwise it’s easy to understand. So give it a try, go through whole code once and return here, I promise it would prove beneficial and you would thank me after this.</p><p>Alright, So how did it go? I am positive that you would have been able to get at least some piece of code if not all. Well, that’s Okay. Also, you should be proud of yourself even if you got even some piece of it because it’s never easy to read someone else’s code xD. Alright so now let’s get serious and get the job done. Now I’ll be going through the above code, follow along and Let’s check how much of it you got right! Well, by merely seeing the imports one can recognize that this component communicates with the redux store, uses &lt;MenuItem/&gt; and &lt;Form/&gt; components (we’ve discussed them above already), imports css and we also import some action creators that we created in action.js a while back. <br>Now let’s talk about its internal state. Well, It’s internal state doesn’t have much to offer except an openAddForm property whose job, in a nutshell, is just to toggle the display of creating item form, well that’s expected behavior when your app uses redux as then our major state resides in our redux store. Next, we have a fair amount of handlers here, Remember when I said that Menu.js is the powerhouse of our application. You can say that these handlers our the ones which provides it with power.</p><ul><li>First handler to encounter is handleAddClick , Now it’s very similar to handleEditClick discussed while creating &lt;MenuItem/&gt; component. It’s also used to setopenAddForm to true which in turn toggles the Add Form Component.</li><li>Now next up is handleAddItem function which is used to add item to redux store. It receives data when the Add Form (same &lt;Form/&gt; component used in MenuItem, but rendered with empty fields) is submitted. It checks for falsy values and in case it founds one it replaces them with default value. After verification of values createItem action creator is invoked with new item as argument and rest is all taken care by redux.</li><li>Now next event handler is handleDeleteItem which is used to remove item from redux store. It is invoked by &lt;MenuItem/&gt; with id of item to be deleted. In turn handleDeleteItem in turn invokes deleteItem action creator with id of item to be deleted as argument.</li><li>Next event handler that we come across is handleUpdateItem which is used to update item in redux store. Like in previous handler, It’s also invoked by &lt;MenuItem/&gt; but with full item object not just id. in turn handleUpdateItem dispatches updateItem action creator with item object as argument.</li><li>Now last event handler to encounter is handleCancel which is quite similar to one defined in &lt;MenuItem/&gt; , so you already know what it does.</li></ul><p>Majority of the code is commented so the rest of the code may not require any additional explanation. Other than that we have defined mapStateToProps function in order to subscribe to redux store state updates. Here we subscribed for updates for menuItems property. As a last step we connect our &lt;Menu/&gt; component to redux store using connect, After connecting to store we get menuItems as prop to &lt;Menu/&gt; component. So that’ all folks for the menu.js. Now we just need to run it and see what we built so far.</p><p>Hey don’t you think, we are forgetting something? Yes, we are. Our menu.css is still empty. And if you run your app now, It could well be a nightmare. If you want you can use the css that I wrote for this app and not waste time on writing your own. You can download css from <a href="https://raw.githubusercontent.com/AwesomeChap/Fastify-React-E-Menu/master/src/menu.css">here</a>.</p><p>Now navigate to a terminal and execute npm run dev and navigate to <a href="http://localhost:1234/"><strong>http://localhost:1234/</strong></a> and you might be seeing the application up and running very similar to shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyjWDvrgU0fcBa-_DVRKrw.gif" /></figure><h3>What’s next?</h3><p>Alright, folks! We’re done with our first leg of the two-part tutorial. Till now we’ve successfully created a fully functional React Redux CRUD application. But it still has one problem that needs to be fixed, which is that the changes are not persistent and it disappears whenever the app is reloaded. So, In the next part we’ll be making changes persistent, for which we’ll be using fastify and MongoDB Atlas. It would be quite interesting to see how these all techs work in conjunction. So let’s meet in its second part where we’ll add Fastify and MongoDB Atlas to our current application.</p><p><a href="https://medium.com/@jatin15011999/fullstack-crud-application-using-fastify-react-redux-mongodb-part-2-cc37ea4187ff">Fullstack CRUD application using Fastify, React, Redux &amp; MongoDB Part-2</a></p><p><em>If you enjoyed this post, I’d be very grateful if you’d help it spread by sharing it with a friend, via Twitter or Facebook. And as always please let me know in comments how did you find this tutorial. Thank you!.</em></p><p>Wanna read more? You may like this as well -</p><p><a href="https://medium.com/@jatin15011999/how-to-create-interactive-maps-in-react-js-ccdfad460fa0">How to create Interactive Maps in React.js</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e8df39c6fff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/fullstack-crud-application-using-fastify-react-redux-mongodb-part-1-9e8df39c6fff">Fullstack CRUD application using Fastify, React, Redux &amp; MongoDB Part-1</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memorable 24 hours at HackNSUT!]]></title>
            <link>https://jatin15011999.medium.com/memorable-24-hours-at-hacknsut-7be441b1dc1?source=rss-96aac838856a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7be441b1dc1</guid>
            <category><![CDATA[achievement]]></category>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[competition]]></category>
            <category><![CDATA[fitness]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Jatin Kumar]]></dc:creator>
            <pubDate>Fri, 17 May 2019 23:09:35 GMT</pubDate>
            <atom:updated>2026-05-26T09:18:23.128Z</atom:updated>
            <content:encoded><![CDATA[<h4>An experience beyond comprehension</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x31urZJhzT9aoCvkLnLAAg.jpeg" /></figure><p>It has been more than a month since we did what no one would have ever imagined when we first stepped out of our homes — not even us! Remembering the evening of 30 March 2019 still sends shivers down my spine. It was the final of the prestigious HackNSUT hackathon, organised by NSUT.</p><p>The competition was tough. Teams came from all over North India to participate in the overnight hackathon, their eyes full of dreams, belief, and the hope of winning. We were among them, but we always knew it was not going to be easy for any of us. Many teams, despite having brilliant and potential-filled ideas, unfortunately, did not make it to the Top 10.</p><p>When the selected teams gathered for the results, the environment was so tense and the competition so fierce that by the time the winners were announced, probably no one in our team had any fingernails left. This is a story of turning a dream into reality; it is the story of achieving something great in just 24 hours.</p><p>This is the story of Team Enigma — Winners of HackNSUT’19.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wj3xEHNzxagnwQTbUg0Uug.jpeg" /><figcaption>Team Enigma — Sejal Bhatia, Sarthak Sadh, Jatin Kumar, Ashish Aggarwal</figcaption></figure><h3>A Dramatic Beginning</h3><p>To date, we have attended many hackathons in various colleges throughout Delhi. But if I am being honest, the start we had at HackNSUT might be one of the worst we have ever experienced. Like any other team, we came prepared with two ideas: a main idea and a backup idea. We found our primary idea quite innovative and were really excited about it. However, as we started to implement it, we began to uncover loop-holes that had apparently gone unnoticed during our research phase prior to the hackathon.</p><p>Initially, we thought we had ample time and could fix them comfortably. But as we dug deeper, the number of loop-holes increased significantly, and the project started to make less sense overall. By this point, we all knew we had completely messed it up and that the idea needed to be replaced.</p><p>Sadly, by the time we realised this, we had already wasted a few precious hours, and the first evaluation was just a mere few minutes away. At that instant, we were nothing more than a bunch of helpless participants looking at each other with nothing to say. After a few minutes of awkward staring, however, we realised we were not done yet. We still had something to offer.</p><h3>The Backup Idea — Our Saviour</h3><p>Our backup idea was decent, but the problem was that we had not done any prior research on it. We were completely unsure whether it could be implemented within the remaining timeframe. In a hackathon, the implementation of an idea carries immense weight. It does not matter how awesome your concept is if its practical feasibility is in doubt.</p><h4>Alright, so what was the idea?</h4><p>The idea was to build an easily accessible application with the potential to transform an outdoor environment into a gym alternative. In a nutshell, we aimed to bring an artificial gym trainer into your mobile phone, so that users could experience a gym workout even when they were away from home or unable to visit a commercial gym.</p><p>Due to the shortage of time, we could only train the application for a single exercise, as training machine learning models takes time. While we aim to expand the app further in the future, for the time being, it remains a <a href="https://expro-v1.herokuapp.com/">prototype</a>.</p><h4><strong>Problems it solves:</strong></h4><ul><li><strong>Hectic Lifestyles:</strong> Busy people tend to lead hectic lifestyles and often lack a fixed routine for exercise. Consequently, they frequently skip working out, which can lead to health-related problems like obesity. This app helps solve the issue by giving them the flexibility to exercise anytime they want, completely at their own convenience.</li><li><strong>Disrupted Routines:</strong> When a regular gym-goer is unable to go to the gym due to unavoidable circumstances like business trips or weddings, their exercise routine breaks, which is never ideal. With our app, they have nothing to worry about. They just need to find a small window of time, open the app, and take advantage of the personal gym trainer feature. Problem solved!</li><li><strong>Gym Anxiety:</strong> Some people who might feel shy or unsafe going to a commercial gym can perform the exact same exercises in the comfort and safety of their own homes using our application.</li><li>Potentially many more …</li></ul><p>This app has endless use cases, and its integration with other platforms could expand its horizons even further. If I kept talking about all the problems it can solve, we would not have time to discuss anything else — which I certainly do not want!</p><h3><strong>How does it work ?</strong></h3><p>Let’s explore how it works via a diagrammatic representation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-b6MOFMzyOivEJm_5BF9KQ.jpeg" /></figure><p>Our application first analyses the user’s position along with their height and calibrates accordingly. In the next step, the application tracks your exercise movements via the camera and updates the rep counter upon every successful completion of a movement. Then, depending on your performance, the app provides valuable real-time feedback. An optional advanced feature also tracks and displays individual performances within a group setting.</p><h3>What Actually Happened at the First Evaluation?</h3><p>The application we have been talking about was not even 10% ready by the first round of evaluation; all of this was still just a concept in our minds. A few minutes before the evaluation, some mentors came by to speak with us. The mentors there were incredibly helpful and guided us exceptionally well throughout the hackathon. In fact, some of the functionality the application ended up having was directly inspired by their suggestions.</p><p>The mentors were impressed by our backup idea and motivated us to pursue it. When the first evaluation took place, we pitched this backup concept, explained our technical approach, and highlighted a few practical use cases. During the session, the evaluators were kind enough to provide valuable insights and tips to improve it further. Ultimately, the first evaluation went much better than expected, considering we had been helplessly staring at each other just moments prior.</p><h3>A Sleepless Night of Relentless Coding</h3><p>After that first evaluation, our team’s mindset was crystal clear. We knew exactly what our goals were and how to achieve them. Now, we just needed to give our absolute best to the code to turn the concept into a reality.</p><p>That is exactly what we did — we did not sleep the entire night. We were simply too excited. Knowing from our friendly interactions with the mentors that the idea had serious winning potential (provided we finished it in time) kept us going. Finally, at 07:00 in the morning, we were ready with 90% of our target application. If I am being honest, it came together much faster than I anticipated. That is the power of sheer determination for you!</p><h3>Making the Top 10</h3><p>Next came the second evaluation to get into the Top 10. This round was completely different from the first; the environment was incomparably tense. We pitched our project directly to a panel of mentors. We gave it our all but remained anxious because there were many talented teams whose ideas seemed equally promising. It was a tough period of waiting to endure, as no one wants to see their sleepless hard work go to waste in a matter of minutes.</p><p>Finally, after a brief wait, the results were announced — and fortunately, our name was on the list! The moment they said “Enigma”, the whole team lit up. It felt incredible to finally have something to celebrate.</p><h3>An Unforgettable Final</h3><p>In the final round, the top 10 teams pitched their ideas. While watching the presentations, I noticed that the concepts of two or three teams were phenomenal — they targeted crucial, urgent real-world problems. Unfortunately, they lacked a robust implementation, which prevented them from making it into the top three.</p><p>Finally, the long-awaited moment arrived, and the announcer called out the final positions. Our team, Enigma, was declared the Overall Winner of HackNSUT! It was the exact moment our collective, sleepless efforts paid off, and we achieved something we truly never thought possible when the weekend began.</p><p>Through this hackathon, we learned some incredibly important life lessons that simply are not taught in a classroom. I highly encourage you, the reader, to participate in hackathons as much as possible. When you put yourself out there, you always bring something back with you — whether it is new friends, new technical skills, or, you never know, even the first-place prize.</p><p>Competitions like these test your personality and resilience far more than your raw coding skills. If you are hardworking and determined, you can perform exceptionally well, even if you feel you lack advanced technical expertise. Coding skills can always be acquired, but determination is something you build within your character.</p><p>I always believe that :</p><blockquote>Everything seems impossible until it is achieved</blockquote><p>So, the next time you go to a hackathon and hit a dead end, just remember this line. It works for me, and there is no reason it won’t work for you.</p><p>I hope you enjoyed the story. Please let me know your thoughts in the comments below! I will be back with another post very soon.</p><p>Bye until next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7be441b1dc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to host more than one website using one domain ?]]></title>
            <link>https://jatin15011999.medium.com/can-i-host-more-than-one-website-using-one-domain-9cb1621aef93?source=rss-96aac838856a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cb1621aef93</guid>
            <category><![CDATA[domain-names]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[website]]></category>
            <category><![CDATA[cname-record]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Jatin Kumar]]></dc:creator>
            <pubDate>Tue, 07 May 2019 23:10:38 GMT</pubDate>
            <atom:updated>2019-05-09T09:16:05.814Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to host more than one website using one domain ?</h3><h4>Power of CNAME records</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*fbZBPRmzn7ow8-bR--FuBw.jpeg" /></figure><p>Yes It is possible to host multiple websites with different <em>sub domains</em> using one <em>root domain</em>. So first of all what is a <em>root domain</em> and <em>sub domain</em>?<br>Let’s consider a web address<em> </em><a href="http://www.example.com,/"><em>http://www.example.com</em>,</a> so, here <em>example.com</em> is referred to as <strong>root domain</strong> and <em>www</em> is referred to as <strong>sub domain</strong>. Figure shown below diagrammatically shows different parts of a web address</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*0NEpSpprpeSK6cyaf32oXQ.png" /><figcaption>Sub parts of a web address</figcaption></figure><p>Sub domain can be of many other types also for eg. imap, pop, webmail, etc. (If curious, you can see more of them in CNAME records of your domain) Actually we can define our own custom sub domain for special reasons and we’re gonna do this later in this tutorial indeed.</p><h3>What you may want to achieve ?</h3><p>Image shown below, portrays exactly what we’ll be trying to achieve during rest of the tutorial. Feel free to discontinue reading if it’s not the result that you desired. But I would highly recommend you to read it till end, because information discussed below is good to be aware of, at least from the web developers point of view. And most importantly …</p><blockquote>Knowledge never goes wasted.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hh_JwgtB3Ze49yu7J_vLxA.jpeg" /></figure><h3><strong>Why people may do this ?</strong></h3><p>People mostly tend to host multiple websites using one root domain. When they have set of websites which has content related to each other. Let’s say a person has a Portfolio website and Blog. Now suppose domain name is <em>person.com</em>. As both the web pages are related to same person. It would not make much difference if they share root domain and Also it would be even better for the person to have both things located under one domain in an organised manner rather than having separate ones for both. As a result now possible web address for Portfolio and Blog could be <a href="http://www.person.com/"><em>http://www.person.com</em></a> and <a href="http://blog.person.com/"><em>http://blog.person.com</em></a> respectively. In this scenario people save a significant amount of money too. So It’s a win win situation.<br>In coming section we would be getting started with process of hosting multiple Websites under single root domain.</p><h3>Let’s get started</h3><p>Before getting started I assume that you have two Dynamic websites, which have been already deployed using Heroku, or any any other free hosting service of your choice. Basically We only need the DNS that they provide.</p><p><strong>Generate DNS</strong> : In Heroku in order to generate DNS, you need to add your registered domain along with a sub domain (www, blog, me, etc) to your project by going into settings, After entering Domain in the <em>Domain Name Field</em> and press <em>Save Changes, </em>Now heroku would automatically generate DNS related to that domain just entered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*ItpLPpcE9UuITc45GTFwtg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g8kF52YhWfs3ttaY7mV8mQ.png" /></figure><p><strong>Create a CNAME record : </strong>Now go to you control panel of domain and open the DNS Manager. Now click on CNAME records. Here you might get overwhelmed by seeing at amount of different sub domains. Don’t worry we would not be staying here for too long. Now we simple need to Add a CNAME record. For that click on<em> Add CNAME Record. </em>Now a Add CNAME section should open and look similar to figure below. Now<em> </em>fill the sub domain for which you generated DNS in <em>Host Name Field </em>and<em> </em>paste full DNS associated with the mentioned sub domain in <em>Value Field</em>. In above example we used blog as a sub domain. FYI you just created your first sub domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*jY2jA-A2ywSswmkuES3Qfw.png" /></figure><p>Repeat the above two steps for other website also, And keep in mind to have a different sub domain than before. After you are done with both, You need to wait until number of seconds given in TTL expires (You cannot witness live changes until Time given in TTL expires, if possible assign 0 to TTL, so that you can witness live DNS record changes ) . After TTL is expired you can now be able to access two different websites (differing in sub domains) using one root domain only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*kRJ3buv6d1vvGRI74Dw9RQ.gif" /></figure><p><em>I Hope that you liked the Tutorial, I would like to know in comments How you found it. If you wish, you can follow me on </em><a href="https://www.facebook.com/J4TINKUMAR"><em>facebook</em></a><em> and </em><a href="https://twitter.com/jatink99"><em>twitter</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cb1621aef93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 Awesome ReactJS Frameworks you probably didn’t know existed]]></title>
            <link>https://jatin15011999.medium.com/3-awesome-reactjs-frameworks-you-probably-didnt-knew-9287c6549b2a?source=rss-96aac838856a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9287c6549b2a</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[vr]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Jatin Kumar]]></dc:creator>
            <pubDate>Tue, 07 May 2019 15:20:59 GMT</pubDate>
            <atom:updated>2019-05-11T18:59:45.253Z</atom:updated>
            <content:encoded><![CDATA[<h4>Nowadays, there is nothing that you can’t do using React.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*G4SYaoZbNrOg4GAUUKz-Cw.png" /></figure><p>React.js has been around for quite a while now. It was released back in 2013 and later in 2015 React Native was released, A mobile implementation of React.js library. Both of them had a notable impact on communities the very time they were released. If you are a React or even a Javascript Developer, You might be familiar with both of them already. The component based approach that react provides and it’s stress on using plain javascript is just phenomenal. So enough of background details!. Lets get started with the fun part.</p><p>Okay you already know that we can develop really good robust and dynamic Web and Mobile Applications using React. What if I tell you that you can do even more using it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*TPPFGSeAqCgDMzEB4WYmGw.gif" /></figure><p>Ya, That’s right, That same elegant component based approach along with the plain javascript can be employed to do even more spectacular stuff apart from traditional Web App and Mobile App Development. Now question may arise, that what are those damn things ? So, the answer of your question lies a few scrolls away. I would be briefly describing each one of those one by one. So here we go!</p><h3>React 360</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-J3zMoLT_3Wm0veh4oz9w.jpeg" /></figure><p>React 360 is a framework for the creation of interactive 360 experiences created by facebook. It very elegantly pairs declarative power of React with modern API’s like WebGL and WebVR. Much like every React Framework it promises cross platform support. Therefore, If you know React you can develop cross platform 360 experiences pretty easily and quickly. To know more about React360, you can visit it’s <a href="https://facebook.github.io/react-360/">getting started</a> page.</p><h3>Proton Native</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*pLj6Xfe7aFDUEMlWK3fQcw.jpeg" /></figure><p>Well, till now we could create mobile and Web based applications, But after the arrival of Proton Native, We can now build highly reactive cross platform desktop application using our much beloved react syntax. It also supports Redux, So state management would not be a problem. So for your next desktop project, giving a shot to proton native might prove beneficial to you. Curious readers can get more information about the framework on <a href="https://proton-native.js.org/">this page</a>.</p><h3>React Game Kit</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q6eCGb7cfNossh7CPb8XVQ.png" /></figure><p>React Game Kit is a React Component Library for Game Development. Well, It’s not exactly standalone framework, but a rather handy Component library which could be incorporated with React-dom and React Native Application to develop really nice Games. Well you cannot develop complex games using react but for hobby and fun projects it may prove handy. Hot reloading in react game kit ensures fast paced development and in case you require physics engine, then React Game kit contains physics helpers provided by matter.js. To get more out of it you may visit it’s <a href="https://github.com/FormidableLabs/react-game-kit/issues">github page</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*kRJ3buv6d1vvGRI74Dw9RQ.gif" /></figure><p><em>That’s all for today and I am positive that you would be excited to learn even more about the libraries / frameworks briefly discussed above. I hope that you enjoyed the post, please let me know in comments how you found it or in case you too have some awesome React Framework, type that in comments too. If you wish you can follow me at </em><a href="https://twitter.com/jatink99"><em>twitter</em></a><em> and </em><a href="https://www.facebook.com/J4TINKUMAR"><em>facebook</em></a><em>.</em></p><p><em>Thanks for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9287c6549b2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>