<?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 Luvdeep Katyal on Medium]]></title>
        <description><![CDATA[Stories by Luvdeep Katyal on Medium]]></description>
        <link>https://medium.com/@luvdeepkatyal?source=rss-6d38c09a0d21------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U0p21o1zbeFNbw5wEpglVA@2x.jpeg</url>
            <title>Stories by Luvdeep Katyal on Medium</title>
            <link>https://medium.com/@luvdeepkatyal?source=rss-6d38c09a0d21------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:57:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@luvdeepkatyal/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[Nest.JS over Others]]></title>
            <link>https://luvdeepkatyal.medium.com/nest-js-over-others-49825c35f3a8?source=rss-6d38c09a0d21------2</link>
            <guid isPermaLink="false">https://medium.com/p/49825c35f3a8</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Luvdeep Katyal]]></dc:creator>
            <pubDate>Sun, 21 Aug 2022 19:01:35 GMT</pubDate>
            <atom:updated>2022-08-22T04:29:39.030Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mf0PPf38fJsui_0-.jpeg" /><figcaption>Nest.JS</figcaption></figure><p>If you work on <a href="https://nodejs.org/en/"><strong>Node.JS</strong></a> you must be aware that there are several frameworks that you can use and that leads to a common confusion that which framework one should choose and procced upon</p><p>Now bringing out the elephant in the room, we would below discuss about Nest.JS and it’s rival frameworks</p><p>To begin with the basic question of <strong><em>“What actually is Nest.JS ?”</em></strong></p><p>Nest.JS is one of the <strong>fastest growing</strong> framework for Node.JS,</p><p>It is <strong><em>open-source, extensible, versatile and progressive</em></strong> for building efficient, scalable server-side applications, being progressive here refers to <strong><em>bring JS features and design patterns into the Node</em></strong></p><p>So, it <strong><em>uses progressive JavaScript</em></strong> and <strong><em>fully supports TypeScript</em></strong> and is also a combination of the following three :</p><p><strong><em>1. OOP (Object Oriented Programming)<br>2. FP (Functional Programming)<br>3. FRP (Functional Reactive Programming),</em></strong></p><p>which is <strong>not usually found in other frameworks</strong>,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0vI539izuoApeVJO" /><figcaption>Programming</figcaption></figure><p>Nest makes <strong><em>use of robust HTTP Server frameworks like </em></strong><a href="https://expressjs.com/"><strong>Express </strong></a>because express is widely-used, well-known, and has an enormous set of compatible middleware, which is available to Nest users out-of-the-box and also Nest <strong><em>optionally can be configured to use </em></strong><a href="https://www.fastify.io/"><strong>Fastify</strong> </a>as well, but <strong><em>Nest provides a level of abstraction above these common Node.js frameworks</em></strong> making it advantageous over the available frameworks.</p><p>It also <strong><em>exposes their APIs directly to the developer</em></strong>. This provides the freedom <strong><em>to use the vast number of third-party modules </em></strong>which are available for the platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*GSG1fD9LPyQKS40Wm_dIKA.png" /><figcaption>Angular</figcaption></figure><p>The <strong>architecture of Nest</strong>, is actually inspired by <strong>Angular</strong>, the module, service, controller, pipe, decorators are more syntactical to Angular</p><p><strong><em>Features over other frameworks:</em></strong></p><p>Key features like,</p><ul><li><strong><em>Typescript compatibility</em></strong></li><li><strong><em>Powerful CLI</em></strong></li><li><strong><em>Built in support for micro-services</em></strong></li><li><strong><em>Ready dev-ops support</em></strong></li><li><strong><em>Built in exception filter</em></strong></li><li><strong><em>Framework compatibility</em></strong></li><li><strong><em>Better database interaction</em></strong></li><li><strong><em>Default nested routing</em></strong> (which is not used by other frameworks like Hapi)</li><li><strong><em>Easy unit testing</em></strong><br> <br>makes Nest preferable over other frameworks.</li></ul><p><strong><em>Framework Independence:</em></strong></p><p>One of the core feature of nest that differentiates it with other frameworks is that <strong><em>Nest gets framework independence by implementing a framework adapter</em></strong> whose primary function is to <strong>proxy middleware and handlers</strong> <strong>to appropriate library-specific implementations</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*GkjqRGhDxm4_FOrWYAy6WQ.png" /><figcaption>Node.Js and it’s common frameworks</figcaption></figure><p><strong><em>Performance:</em></strong></p><p>Since Nest.JS integrates with Node.JS and modules like Express and Fastify, it <strong><em>can multiply the productivity and application performance while reducing time</em></strong>.</p><p>It <strong><em>enables database connectivity</em></strong> through APIs and <strong><em>data caching to reduce the payload</em></strong>.</p><p>Nest.JS provides an <strong>architecture </strong>known as the <strong>Controllers-Providers-Modules</strong> that enables to create <strong>applications</strong> that are <strong>easier to test and maintain</strong>.</p><p>Ensuring the application is <strong>scalable, highly testable, and loosely coupled</strong> contrary to other <strong>Node.js frameworks</strong> like <strong>Express or </strong><a href="https://koajs.com/"><strong>Koa</strong> </a>where regarding the <strong>architecture may cost lots in terms of time spent refactoring the codebase later</strong></p><p><strong><em>Summary:</em></strong></p><p><strong>Better </strong>than other <strong>Frameworks</strong>, <strong>Nest.JS</strong> <strong><em>provides a large boost right at the very starting </em></strong>along with it’s easier installation and understanding while <strong>helping developers</strong> take their <strong><em>next steps by defining proper architecture</em></strong>.</p><p><strong><em>References:</em></strong> <br><a href="https://docs.nestjs.com/">https://docs.nestjs.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49825c35f3a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ES2021: Additions to the script!]]></title>
            <link>https://luvdeepkatyal.medium.com/es2021-additions-to-the-script-49f4c82117cd?source=rss-6d38c09a0d21------2</link>
            <guid isPermaLink="false">https://medium.com/p/49f4c82117cd</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Luvdeep Katyal]]></dc:creator>
            <pubDate>Fri, 25 Dec 2020 13:10:55 GMT</pubDate>
            <atom:updated>2020-12-25T13:10:55.708Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wg2KVuuJVoL1M2O0GqgFGw.jpeg" /></figure><p>With the coming year, we also have new additions to our favourite programming script, expected to be released in the coming June.<br>So let us begin with these additions,</p><h3><strong><em>1. String.prototype.replaceAll():</em></strong></h3><p>In our knowledge we already have <strong>string.replace() </strong>method that replaces some or all matches of a pattern(a string or a regular expression) in a given string and returns a new string. To replace all the corresponding matches we need a <strong>‘g’</strong> modifier in the regular expression that performs a global search.<br>Now with the <strong>replaceAll()</strong> method we can just pass in a replacement and get a new string that replaces all matches of a pattern.Note that the original string remains unchanged.<br><em>Let us get this through an example:</em></p><blockquote>const str = “We have additions to the javascript now by the coming es2020, es2020 is also known as es12”;<br>console.log(str.replaceAll(‘es2020’,’es2021’));<br> //“We have additions to the javascript now by the coming es2021, es2021 is also known as es12”</blockquote><h3><strong>2. Private Methods and Accessors:</strong></h3><p>Methods and accessor functions can be accessed only inside a class where they are defined, for this we need to prepend <strong><em>‘#’ </em></strong>to the method and the accessor name.<br><em>Consider the example:</em></p><blockquote>class Main{<br>//private method<br>#privateMethod(){<br>console.log(“This is a private method”)<br>};<br>//public method<br>publicMethod(){<br>this.#private();<br>};<br>// Public Accessor<br>get publicAccessor(){ return “Public Accessor” };<br>set publicAccessor(value);</blockquote><blockquote>// Private Accessor<br>get privateAccessor(){ return “Private Accessor” };<br>set privateAccessor(value);<br>};<br>const obj = new Main();<br>obj.publicMethod(); // “This is a private method”<br>obj.privateMethod(); //TypeError: obj.private is not a function<br>console.log(obj.publicAccessor); //“Public Accessor”<br>console.log(obj.privateAccessor); // undefined</blockquote><h3><strong>3. Promise.any() along with AggregateError:</strong></h3><p><strong>Promise.any() </strong>gets settled when any one the promise gets resolved and in case all of the promises are rejected <strong>Promise.any()</strong> throws an error which is an <strong>AggregateError</strong>, which we can obviously catch to handle it.<br><em>Understand by the following:</em></p><blockquote>try{<br>const p1 = new Promise((resolve, reject) =&gt; resolve(“The first promise”) ) ;<br>const p2 = new Promise((resolve, reject) =&gt; resolve(“The second promise”) ) ;<br>const p3 = new Promise((resolve, reject) =&gt; resolve(“The third promise”) ) ;</blockquote><blockquote>(async () =&gt; {<br>const promises = await Promise.any([p1, p2, p3]);<br>console.log(promises); <br>// [“The first promise”, “The second promise”, “The third promise” ];<br>})();<br>}catch(error){<br>console.error(`Promise rejected, ${error.errors}`);<br>throw error;<br>};</blockquote><blockquote>/* Let’ s try to reject the promise being passed in Promise.any()*/<br>try{<br>const promiseToReject = new Promise((resolve, reject) =&gt; reject());<br>(async () =&gt; {<br>const promises = await Promise.any([promiseToReject]);<br>console.log(promises); <br>})();<br>}catch(error){<br>console.error(`Promise rejected, ${error.errors}`);<br>throw error;<br>};<br>// expected output: “AggregateError: No Promise in Promise.any was resolved”</blockquote><h3><strong>4. Logical Assignment Operator:</strong></h3><p>According to me it is a very efficient feature and also improves the code quality. Logical assignment operator <strong>combines</strong> the <strong>logical operations(&amp;&amp;, ||, ??)</strong> and <strong>assignment(=)</strong>. The <strong>Nullish coalescing operator(??)</strong> was introduced in this year’s ecma script(es2020) and checks if the value is <strong>null</strong> or <strong>undefined</strong>.</p><blockquote>let a;<br>const b = a ??= 10;<br>console.log(“b has the value”, b) // b has the value 10</blockquote><blockquote>similarly for logical <strong>OR </strong>and the <strong>AND Assignment </strong>operation:<br>const d = 5;<br>const e = d ||= 10;<br>console.log(“e has the value”, e) // e has the value 5</blockquote><blockquote>const f = 1;<br>const g = f &amp;&amp;= 10; // since f is a truthy value g gets assigned to the value of 10;<br>console.log(“g has the value”, g) // g has the value 10</blockquote><p>The above can be illustrated as:<br>if(f ){<br>const g = 10;<br>};</p><p>So after reading the above you must be keen on to use these features in your programming, i guess we have to wait until the coming June for that one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J0VBsMLGezdqwX9uBJ7J4A.jpeg" /></figure><p>It is very interesting to get to know about the new features and additions in the, so keep on updating your knowledge.</p><p>Thanks for the read!</p><p>You can also visit my previous article on <strong>es11/es2020:<br></strong><a href="https://medium.com/@luvdeepkatyal/es2020-features-for-a-new-decade-4cf585fa2039"><strong>ES2020: Features for a new decade</strong></a><strong>!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49f4c82117cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[deno and oak with mongoDB and Redis]]></title>
            <link>https://luvdeepkatyal.medium.com/deno-and-oak-with-mongodb-and-redis-f0b47d3eecfa?source=rss-6d38c09a0d21------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0b47d3eecfa</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[deno]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Luvdeep Katyal]]></dc:creator>
            <pubDate>Sun, 21 Jun 2020 15:57:42 GMT</pubDate>
            <atom:updated>2020-06-21T16:27:04.504Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*IALiKY6dWDsjLpCQiaEQmQ.jpeg" /></figure><p>Now there is a lot of speculations in the world of <strong>backend</strong> that either <strong>deno</strong> is going to replace <strong>Node.JS</strong> , well after my research and study the conclusion that i have reached is clearly <strong><em>‘NOT FOR NOW’</em></strong>.</p><p><strong>deno</strong> is definately the future but for now it is not going to murder everyone’s favourite <strong>Node.JS</strong>.<br>It is just a new toy in the town for developers and programmers, so just have fun while playing with it.</p><p>Jumping on to the introduction about <strong>deno </strong>which is a secure runtime for <strong>JavaScript</strong> and as well as <strong>TypeScript</strong>.<br>It has been built on <strong>V8</strong> engine just as <strong>Node.js </strong>and in addition <strong>Rust</strong>, and <strong>Tokio</strong>.<br>- deno is by default secure as it doesn’t provide access for files, environment or network unless enabled.<br>- One of the promising advantage for deno is all the scripts can be bundled into a single JS file and it is browser compatible.</p><p><strong>Comparing deno with Node.JS:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*BfctKgExFwdV74Tt-sj8BA.jpeg" /></figure><p>- deno has <strong>no modules</strong>, it doesn’t need the use for <strong>npm</strong> and <strong>package.json</strong> as well, so does it restricts the use of third parties and modules, no it doesn’t, it uses <strong>modules referenced as URLs or file paths</strong>, just simply import these in your code and get ready for their use.<br>- deno provides different API’s from Node.JS as all of the <strong>async</strong> actions <strong>return</strong> a <strong>promise</strong>.<br>- deno <strong>dropped</strong> the use of <strong>require()</strong> and only <strong>imports</strong> are <strong>allowed</strong>.<br>- An advantageous one deno allows you to use the <strong>top-level-await</strong>, which can run directly without an <strong>asynchronous function</strong>.</p><p><strong>Installation:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*go9OhutYcmSkjeMBsKCFTw.jpeg" /></figure><p>deno works on macOS, Linux, and Windows and it has no external dependencies.</p><p><strong>Using Shell (macOS and Linux):</strong></p><pre>$curl -fsSL https://deno.land/x/install/install.sh | sh</pre><p><strong>Using PowerShell (Windows):</strong></p><pre>$iwr https://deno.land/x/install/install.ps1 -useb | iex </pre><p>You can also use <strong>Scoop</strong> and <strong>Chocolatey</strong> for <strong>Windows</strong> or even <strong>Cargo</strong> which can also work for <strong>Linux</strong> and <strong>macOS</strong>.<br>Once installed, run <strong>deno --version</strong>, if it prints version which is currently 1.1.0 your installation is successfull.<br>You can also go for a <strong>repl </strong>with deno just as in Node.JS.</p><p>For starting with implementation i am going to use <strong>oak, </strong>which is a <strong>middleware framework for deno’s http server</strong>, including a <strong>router middleware</strong>.<br>This <strong>middleware framework</strong> is inspired by <strong>Koa</strong> and <strong>middleware router</strong> inspired by @<strong>koa/router.<br> </strong>You can also use another server framework for your implementation like <strong>Pogo</strong> which is an easy-to-use, safe, and expressive framework for writing web servers and applications. It is <strong>inspired by hapi.</strong></p><p>You will be getting these third-party modules from <a href="https://deno.land/x"><strong><em>https://deno.land/x</em></strong></a><em> , </em>for <strong>mongodb</strong> i am using <strong>deno_mongo </strong>which is a <strong>MongoDB database driver developed for deno, based on rust’s official </strong><strong>mongodb library package,</strong> which includes only a few mongodb queries and not all, these are <strong>insertOne, insertMany, find, findOne, updateOne, count, updateMany, deleteOne </strong>and<strong> deleteMany </strong>along with <strong>aggregate.</strong> With the use of these i am going to perform basic <strong>CRUD </strong>operations on <strong>MongoDb</strong> with <strong>oak</strong> and also storing the data in our <strong>Redis</strong> , for redis i am using <strong>deno-redis.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*w1-gcqG0hrP444V_78Jm4w.png" /><figcaption>Structure</figcaption></figure><p>I am using a simple structure for implementation, a server file, a router file to include all of my routes, a redis service file which implies my port and host to be used for redis, a database file for connectivity with my database(mongodb), a constant file that contains constant messages and values to be defined and a controller file that contains all of the buisness logic to be executed.</p><p>Here it goes in my server file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*289lbSi965GG9BFSbtmwAQ.png" /><figcaption>server.ts</figcaption></figure><p>I simply import Application from<strong> deno oak</strong>,</p><p>the Application class is used for wrapping the serve() function from the http package.</p><p>- The Application class has two methods namely <strong>.use()</strong> and <strong>.listen()</strong></p><p>- Our <strong>middleware</strong> is added from the <strong>.use()</strong> method and the <strong>.listen()</strong> method will start the server and start processing requests <br>with the registered middleware. Whenever our middleware is called, it is passed as a <strong>context</strong>.<br>- <strong>context.request</strong> contains information about the request and similarly the <strong>context.response</strong> contains information about the response which is sent to our client.</p><p>Similarly <strong>import</strong> the <strong>Router</strong> from<a href="https://deno.land/x/oak"><strong><em> “https://deno.land/x/oak/mod.ts&quot;</em></strong></a>, into the router file which produces middleware which can be used with an Application to enable routing based on the pathname of the request.</p><p><strong><em>Start your server using: <br></em></strong>deno run --allow-read --allow-env --allow-write --unstable --allow-net <br>--allow-plugin server.ts</p><p>Because the plug-in API of Deno is still in an unstable state, the <strong>unstable </strong>flag needs to be used. Rest of the flags are to allow read ,write and network and use allow env if you are using the .env file for your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*GZKyGAeJ1en0XYf_bYH8OQ.png" /></figure><p>Now after my server file is ready just make a connection to my MongoDb, import the <strong>MongoClient</strong>, create a client and with the help of <strong>connectWithUri</strong> method which takes in your connection url create your database and a collection on which you want to perform your operations.<br>You must use the dotenv for your implementation and can keep your connection string into your .env file for specific reasons and by importing dotenv/load.ts from deno and using <strong>“Deno.env.get(anyVariable)”</strong> can use the value of the variable declared into your <strong>.env</strong> file, here i am just using my localhost so currently i am not following this process.</p><p>Now import connect from<strong> deno-redis </strong>and declare your <strong>hostname</strong> and <strong>port</strong> for your <strong>redis connection</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*09yXMxz5a311rxg6KohWog.png" /></figure><blockquote>In case you do not have redis installed or if you are a newbie to redis get it downloaded from <a href="https://redis.io/download">redis.io</a> and install it using the command<em> sudo apt install redis-server.</em></blockquote><p>coming to creating your routes in the router file import Router from oak instanciate a new router and start creating your routes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*F0Mp6HFZ15eX3C-EoxvgsQ.png" /></figure><p>deno oak gives your code cleanliness in creating different routes from your router with simplicity.You can also use the routes into your your server file if you have a very short project.</p><p>With the very first route i insert a user into my collection using the context request and response, i accept the request in a body and destructuremy request body</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*c-J6cNNZo5mZZjjs7vBOkA.png" /><figcaption>Request and body</figcaption></figure><p>in the end after my queries and logic i save my data to the database and set the key value into the redis and give my client the desired response using the context</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LFBJ7tKxiGvGB5k2VaibyA.png" /><figcaption>Storing the data in mono, redis and returing the response</figcaption></figure><p>Using postman for the request and response of my API’s to see the response, view the request and response for the insertOne endpoint</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*u4e7-64amsv95FgkGbr3OA.png" /><figcaption>Request and Response from Postman</figcaption></figure><p>Here the insertOne returns <strong>“$oid” </strong>in case if you are familiar with <strong>“_id”, </strong>they are same it is merely the representation, internally they are stored in the same way for more information visit: <a href="https://docs.mongodb.com/manual/reference/mongodb-extended-json/">https://docs.mongodb.com/manual/reference/mongodb-extended-json/</a></p><p>HTTP Status Code 201 might be a bit confusing for you all but actually it is represents a new resource being <strong>created</strong>, it is all upto you and your understanding, you can still go with the status code of 200.</p><p>Likewise you can proceed with other requests and response i am just sharing more of the requests and responses of my other API’s.</p><p>and of course go ahead with validations in each of the API based on your requirements, just like,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*jJdMd3I6JtSJQIiULBvwGQ.png" /><figcaption>Email to be unique for every document in the collection in insertOneUser Api</figcaption></figure><p>2. Get All Users</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*TikJSzdBNhwl5Gj6TvhNnQ.png" /><figcaption>User Listing</figcaption></figure><p>3. Get One User based on its id</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*c1TTXryUKLHMz2y2FETesA.png" /></figure><p>For these kinds of retrievals prefer data coming from the redis at first and if your data is not present in redis (flushed or redis server is down)<br>You can only then query your database you may use this in the case of the userList API as well, like below i did it for a single user retrieval</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*rN25pRlUw_mtiH_mwnGiyw.png" /><figcaption>Get One User function from the controller</figcaption></figure><p>4. Update a document from the collection</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*PcODo3GLgQ7QRtsZs3xn3g.png" /><figcaption>Update API request and response</figcaption></figure><p>In this API, i really missed <strong>mongoose</strong> and mainly the <strong>findOneAndUpdate()</strong> as for a single key update i had to query the db again for updated values to be overwritten in redis for the same key, i missed the use of <strong>post and pre hooks</strong> that could easily replace the whole updated document in my redis after the query being executed.</p><blockquote>When you try to run your code with <strong>findOneAndUpdate() </strong>it gives you an error of <strong>Property ‘findOneAndUpdate’ does not exist on type.</strong></blockquote><p>Since for now i could not found anything in deno for mongoose schema declaration for our collection i had to bear with it and using primitive ways to set the value of my key in redis.</p><p>5. Delete a single user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*AcTnvbrddqPLK3rmp5mqCQ.png" /><figcaption>Response for delete request</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*BB6aHtyDDE59aXaHDV5YyQ.png" /><figcaption>deleteOneUser function from the controller</figcaption></figure><p>Just update the status and <strong>following the backend rules</strong> <strong>“SOFT” delete </strong>the user and use <strong>del command</strong> to delete the key from <strong>redis</strong></p><p>That’s all folks, that’s the <strong>basics</strong> for <strong>deno </strong>with <strong>oak mongodb and redis<br></strong>I believe you can try yourself for your own base projects with <strong>deno </strong>and enjoy deno just as Node.JS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6c11CScPxHgPVJrg" /><figcaption>Photo by <a href="https://unsplash.com/@slavromanov?utm_source=medium&amp;utm_medium=referral">Svyatoslav Romanov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Keep Learning guys<strong> Life and Programming both are just about Learning<br></strong>Keep growing. Please clap and share if you liked the article Thank you for the read. Explore <a href="https://deno.land/">https://deno.land/</a> for more. Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0b47d3eecfa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WRAPPER OBJECTS: The most unknown thing for a Javascript developer]]></title>
            <link>https://luvdeepkatyal.medium.com/wrapper-objects-the-most-unknown-thing-for-a-javascript-developer-69378a957c4d?source=rss-6d38c09a0d21------2</link>
            <guid isPermaLink="false">https://medium.com/p/69378a957c4d</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Luvdeep Katyal]]></dc:creator>
            <pubDate>Sun, 05 Apr 2020 10:33:50 GMT</pubDate>
            <atom:updated>2020-04-05T10:33:50.437Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*emTLGroP54nRnTZYWP_SGg.jpeg" /></figure><p>The concept of <strong>Wrapper Objects</strong> does exist in <strong>Java </strong>language, let us observe how it actually works in <strong>JavaScript</strong>. So let us begin with some primitives in JavaScript and the most common one is a <strong>String</strong>.</p><p>Let us just begin with a very common example that we all know since our childhood,</p><p><em>const name = “John Doe”;<br></em>and now we want to get the <em>number of characters</em> in the above string, we simply go for,</p><p><em>console.log(name.length);<br></em> and we get the length of the string as 8, alright that is no rocket science, we all do know that very well, but if i ask you that <em>how does that work, if </em><strong><em>String </em></strong><em>is a </em><strong><em>primitive</em></strong><em>, how we are able to use a </em><strong><em>. (dot notation) </em></strong><em>?</em></p><p>Now with the dot notation it does gives an idea that it is an <strong>Object</strong>, now obviously we performed <strong>Object.property</strong>, <em>so is it really a primitive or an object.<br>A bit of confusing isn’t it ?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lTH0ovrI-HemgS_u2QT5Gw.jpeg" /></figure><p>Alright, if you are too confused somewhere, you can also use the <strong>typeof</strong> keyword for a verification, but still i mean if you go for <strong>typeof name</strong> you are going to get it as a <strong>“string”</strong>.</p><p><em>I believe that lead to increasing your confusion level.</em></p><p>Alright so, let me reveal the “<em>elephant in the room”</em> here, <br>how it works is that <strong>JavaScript </strong>has <strong>equivalent objects</strong> for each of the <strong>primitive data types</strong>, like, <strong>String, Number, Boolean and Symbol. <br></strong>So there is an equivalent object too, for a <strong>String primitive</strong>. Now actually when you try to access <strong>name.length</strong> this must actually fail, if name is a primitive, but when you access it’s length what JavaScript does is actually converts it into its equivalent Object and the length property becomes available to it and then it calls the length property of the <strong>Object String</strong> and that is how the length property works on a String primitive.</p><p>Now read carefully what happens when you do <strong>name.length</strong> the string is immediately <strong>wrapped</strong> up into a<strong> <em>“wrapper object”</em></strong> and the length is accessed,<br>this is the concept of the <strong>Wrapper Object, </strong>and coming to the case whrer you try to get the <strong><em>typeof</em></strong><em> name it is still a </em><strong><em>“string”</em></strong>, this is due to the reason when the <strong><em>String primitive</em></strong><em> to an </em><strong><em>equivalent String Object</em></strong> is created it is not assigned to the name variable, it is just a <strong>temporary Object</strong> that is created, the length property is accessed from it and then the <strong><em>Object is actually discarded,</em></strong> like gone after just being created for a fraction of seconds to make the length property be accessed or just to make that operation work.</p><p>I hope now you have a clarity of what actually happens when we are using just a basic operation of <em>String.length, </em>this is how the <strong>Wrapper Objects</strong> come into the play.</p><p><em>So besides the </em><strong><em>String</em></strong><em> primitive there are </em><strong><em>equivalent Objects</em></strong><em> for the </em><strong><em>Number, Boolean</em></strong><em> and the es6 introduced </em><strong><em>Symbol primitive</em></strong><em>.</em></p><p>I hope you liked this unknown concept of <strong>Wrapper Objects In Javascript.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69378a957c4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ES2020: Features for a new decade!]]></title>
            <link>https://luvdeepkatyal.medium.com/es2020-features-for-a-new-decade-4cf585fa2039?source=rss-6d38c09a0d21------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cf585fa2039</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Luvdeep Katyal]]></dc:creator>
            <pubDate>Sat, 11 Jan 2020 23:11:01 GMT</pubDate>
            <atom:updated>2020-01-12T16:53:29.496Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Photo by Markus Spiske on Unsplash" src="https://cdn-images-1.medium.com/max/1024/1*m3Dfu6aruoN7R_ZEp1sz3A.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Markus Spiske</a> on <a href="https://unsplash.com/s/photos/information?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The new version of <strong>ECMAScript</strong> termed as <strong>ES2020</strong> has been released. Now for those who love ECMAScript what is a better way than to start this decade by getting to know about the features of ES2020, there are really some good new features in this version of ECMAScript, as a <em>learner</em> it is very important to know about the new standards and keep up with the new featues that are going on, so let’s get started with some of the features of ES2020 and have their basic knowledge.</p><h4>1. String.prototype.matchAll()</h4><p>There is already <strong>String.prototype.match()</strong> and the method retrieves the result of matching a <strong>string</strong> against a <strong>regular expression</strong> and by the name it must have been clear that <strong>String.prototype.matchAll()</strong> method returns all the results of a matching <strong>string </strong>against a <strong>regular expression</strong> with a minor difference from <strong>String.prototype.match()</strong>, the method retrieves an iterator of all results matching a string against a regular expression, including capturing groups.</p><p>Let’s walk through this by an example:</p><p><em>const regexp = /#\w*/g;<br>const str = ‘</em><a href="http://twitter.com/ecma"><em>#c</em></a><em>ool #</em><a href="http://twitter.com/ecmascript"><em>ecmascript</em></a><em> #</em><a href="http://twitter.com/ecmascript2020"><em>ecmascript2020</em></a><em>’;<br>console.log([…str.matchAll(regexp)];)<br>//output<br>// [Array [“#cool”], Array [“#ecmascript”], Array [“#ecmascript2020”]]</em></p><p><strong>2. Nullish Coalescing Operator (??)<br></strong>Let us consider a very short example where we have an object having some user details like user’s name and the number of children he has:</p><p><em>const user = {<br>“userName”: “John”,<br>“numberOfChildren”: 0<br>};<br>console.log(user.numberOfChildren || 1);<br>//output: 1</em></p><p>now, the above will produce a result of 1, which is not quite correct as 0 is one of the <em>falsy</em> value inside javascript.<br>Now consider the same example as above with using the “nullish coalescing operator” which returns its right-hand side operand when its left-hand side operand is <em>null</em> or <em>undefined</em>, and otherwise returns its left-hand side operand:</p><p><em>const user = {<br>“userName”: “John”,<br>“numberOfChildren”: 0<br>};<br>console.log(user.numberOfChildren ?? 1);<br>//output: 0</em></p><p><strong>3. Optional Chaining(?.)<br></strong>Let us here inherit and extend the above example of a user and add a 3rd property to it of childDetails which is further an object and has optional keys in it like as follows:</p><p><em>const user = {<br>“userName”: “John”,<br>“numberOfChildren”: 1,<br>“childDetails”: {<br>“childName”: “Jane”<br>};<br>};<br></em>now here if i want to access the child name in cleaner way i would attempt something like this in the code:</p><p><em>console.log(user &amp;&amp; user.childDetails &amp;&amp; user.childDetails.childName);<br>//output: “Jane”</em></p><p>in an object with having another property as an object we do have write each and every property to access our final value and by using optional chaining operator we can do it in more precise, readable and easier way, here, i re-write my log using the operator:</p><p><em>console.log(user?.childDetails?.childName);<br>//output: “Jane”</em></p><p>the <strong>?.</strong> operator functions similarly to the <strong>. </strong>chaining operator, except that instead of causing an error if a reference is nullish, the expression returns value of <strong>undefined</strong></p><p><strong>4. Promise.allSettled()</strong></p><p>This is a new function in <strong><em>promises</em></strong>, that allows us to find out all the promises that we want to execute have been <strong><em>settled</em></strong> which means that theses promises have either been fulfilled or rejected.Let us illustrate this through another example:</p><p><em>const p1 = new Promise((resolve,reject)=&gt;resolve(‘p1 has been resolved’));<br>const p2 = new Promise((resolve,reject)=&gt;reject(‘p2 has been rejected’));<br>const p3 = new Promise((resolve,reject)=&gt;resolve(‘p3 has been resolved’));</em></p><p><em>Promise.allSettled([p1,p2,p3])<br>.then(response =&gt;<br> console.log(response)<br>);</em></p><p><em>//output:<br>[{<br> status: &quot;fulfilled&quot;,<br> value: &quot;p1 has been resolved&quot;<br> },{<br> status: &quot;rejected&quot;, <br>reason: &quot;p2 has been rejected&quot;<br> },{<br> status: &quot;fulfilled&quot;,<br> value: &quot;p3 has been resolved&quot;<br> }]</em></p><p><strong>5. BigInt</strong></p><p><strong>BigInt</strong> is a new primitive that provides a way to represent whole numbers larger than <strong>Number.MAX_SAFE_INTEGER</strong> (2 raise to the power 53), which is the largest number <strong>Javascript</strong> can represent with the <strong>Number primitive</strong>.<br>A <strong>BigInt</strong> is created by appending <strong>n</strong> to the end of the integer or by calling the constructor.<br>You can perform the subtract, add , multiply and divide using BigInt.</p><p><em>const hugeNumber = BigInt(50);<br>hugeNumber + hugeNumber; // 100n<br>hugeNumber * hugeNumber; // 2500n</em></p><p><strong>6. Dynamic Import</strong></p><p>With ES2020, you can use a dynamic import can be used from scripts, not just from modules, also since dynamic <strong>import()</strong> returns a promise for the module namespace object of the requested module. Therefore, imports can now be assigned to a variable using <strong>async-await</strong></p><p><em>const numbersArray = [10.5, 12, 5.1, 6.7];<br>const math = ‘../math.js’;<br>const module = await import(math);<br>module.ceil(…numbersArray);</em></p><h3>Conclusion</h3><p>With all of these features and many more Web development is definitely gonna take a new phase, most of the ES2020, lack supporting the old browsers.<br>Well with the conclusion i would like to say keep on learning and keep on JavaScripting.</p><h3><strong>Resources Used</strong></h3><p>MDN, Stage-4, tc39, github.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cf585fa2039" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>