<?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 Ankit Aabad on Medium]]></title>
        <description><![CDATA[Stories by Ankit Aabad on Medium]]></description>
        <link>https://medium.com/@ankit-aabad?source=rss-52e8b0da4fba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pLM25Hn4dxmn9llRKdQ_rA.jpeg</url>
            <title>Stories by Ankit Aabad on Medium</title>
            <link>https://medium.com/@ankit-aabad?source=rss-52e8b0da4fba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:15:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ankit-aabad/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 Respect Rate Limits With Bottleneck]]></title>
            <link>https://ankit-aabad.medium.com/how-to-respect-rate-limits-with-bottleneck-28c4dfc3685c?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/28c4dfc3685c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Sat, 28 Jun 2025 03:20:33 GMT</pubDate>
            <atom:updated>2026-04-20T06:49:56.265Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d8qaavQWeNNqBg1XGBb4wQ.jpeg" /><figcaption>Respect Rate Limits in NodeJS</figcaption></figure><p>Modern systems often rely on APIs or services that enforce strict limits on how frequently and how many requests can be made — whether due to scalability, fairness, resource protection or your subscription plan.</p><p>You might be working with:</p><ul><li>An internal rate-limited service</li><li>An async job runner that must avoid resource contention</li><li>A background task that syncs data without overwhelming a target system</li></ul><p>In these cases, trying to “pace” requests with custom code typically leads to:</p><ul><li>Fragile setTimeout() logic</li><li>Inconsistent behavior under load</li><li>Queues that are difficult to debug or scale</li></ul><p>That’s where Bottleneck comes in — a lightweight, production-ready scheduling library for Node.js that brings powerful, composable rate-limiting primitives to your async workflows.</p><h3>🧩 The 3 Core Flags and What They Solve</h3><h3>1. ⏱️ minTime: Space Out Requests (RPS)</h3><p><strong>Problem</strong>:</p><blockquote><em>“My API only allows 10 requests per second.”</em></blockquote><pre>const limiter = new Bottleneck({ minTime: 100 }); // 100ms = 10 RPS<br>const fetchData = limiter.wrap(async (input) =&gt; {<br>  return fetch(`https://example.com/api?q=${input}`);<br>});<br>// Queue up 200 requests<br>const inputs = Array.from({ length: 200 }, (_, i) =&gt; ({ id: i }));<br><br>Promise.all(<br>  inputs.map((input) =&gt; fetchData(input))<br>).then((results) =&gt; {<br>  console.log(&quot;All requests completed!&quot;);<br>});</pre><p>Ensures <strong>100ms spacing</strong> between job starts — giving you consistent pacing.</p><h3>2. 🔄 maxConcurrent: Limit Parallel Jobs</h3><p><strong>Problem</strong>:</p><blockquote><em>“I don’t want more than 3 jobs running at once.”</em></blockquote><pre>const limiter = new Bottleneck({ maxConcurrent: 3 });<br>const processFile = limiter.wrap(async (file) =&gt; {<br>  return compress(file);<br>});</pre><p>No matter how many jobs are queued, only <strong>3 run at the same time</strong>.</p><h3>3. 🪣 reservoir: Enforce Request Quotas</h3><p><strong>Problem</strong>:</p><blockquote><em>“The API allows only 1000 requests per hour.”</em></blockquote><pre>const limiter = new Bottleneck({<br>  reservoir: 1000,<br>  reservoirRefreshInterval: 60 * 60 * 1000, // 1 hour<br>  reservoirRefreshAmount: 1000,<br>});<br>const sendEmail = limiter.wrap(async (email) =&gt; {<br>  return smtpClient.send(email);<br>});</pre><p>Prevents more than 1000 jobs in a given hour. When the bucket is empty, jobs wait for refill.</p><h3>🔁 How They Work Together</h3><p>Bottleneck applies <strong>all constraints</strong> together:</p><ul><li>minTime → controls <strong>how fast</strong> jobs start</li><li>maxConcurrent → limits <strong>how many run at once</strong></li><li>reservoir → caps <strong>total jobs over time</strong></li></ul><h3>✅ Example</h3><p>Here is a Sample code to test with Bottleneck, Just change the delay timer.</p><blockquote><em>“I want to send 10 requests per second, at most 3 in parallel, and not exceed 1000 requests per hour.”</em></blockquote><pre>import Bottleneck from &quot;bottleneck&quot;;<br><br>const limiter = new Bottleneck({<br>    minTime: 100, // 10 requests per second<br>    maxConcurrent: 3,<br>    reservoir: 1000,<br>    reservoirRefreshInterval: 3600000, // 1 hour<br>    reservoirRefreshAmount: 1000,<br>});<br>function delay(ms) {<br>    return new Promise((resolve) =&gt; setTimeout(resolve, ms));<br>}<br>const callAPI = limiter.wrap(async (payload) =&gt; {<br>    await delay(500);<br>    console.log(&quot;finished request for payload:&quot;, payload.id);<br>});<br><br>// Queue 100 requests<br>const inputs = Array.from({ length: 100 }, (_, i) =&gt; ({ id: i }));<br><br>Promise.all(inputs.map((payload) =&gt; callAPI(payload))).then((results) =&gt; {<br>    console.log(&quot;All requests completed!&quot;);<br>});</pre><h3>🧪 Quick Flag Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zJqpUss0wzV9G3TyP4sTHA.png" /></figure><h3>🧘 Final Thoughts</h3><p>The next time you hit a 429 Too Many Requests or crash a service with async overload - don&#39;t use hacks. Use Bottleneck.</p><p>✅ Declarative.</p><p>✅ Predictable.</p><p>✅ Powerful.</p><p><em>Originally published at </em><a href="https://dev.to/ankit_aabad_be198a64a0520/how-to-respect-rate-limits-without-losing-your-sanity-56ch"><em>https://dev.to</em></a><em> on June 28, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28c4dfc3685c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Single Function Lambdas is a terrible choice for Serverless development.]]></title>
            <link>https://ankit-aabad.medium.com/why-single-function-lambdas-is-a-terrible-choice-for-serverless-development-1c9e264d02ce?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c9e264d02ce</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[serverless-architecture]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Sun, 06 Apr 2025 08:28:49 GMT</pubDate>
            <atom:updated>2026-04-20T07:07:23.966Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Lambdaliths" src="https://cdn-images-1.medium.com/max/1024/1*0aMTnsQyqs77OCb-PA1P0g.jpeg" /></figure><blockquote>Single function lambdas for every endpoint is really bad on every possible front, be it developer experience, debugging experience, deployment efficiency, cost or performance.</blockquote><p>One common best practice that’s often pushed by serverless advocates is to create a separate Lambda function for every single endpoint. I think that’s a terrible idea. In this post we will examine the arguments from the other side and see why the arguments lack merit, consistency, or real-world practicality.</p><p>This push for extreme separation reminds me of Golang. I never really liked the language itself, but I’ve always appreciated one of its core design philosophies: <a href="https://commandcenter.blogspot.com/2012/06/less-is-exponentially-more.html">Less is exponentially more.</a> Interestingly, while I don’t think that idea works well in the context of programming language design, it makes a lot of sense when applied to Serverless infrastructure. When building serverless systems, <strong>a few cohesive, well-structured Lambdas</strong> often result in simpler, more maintainable architectures than a maze of single-function lambdas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*nApkCy6zCyjkhkLA0zcMxw.png" /><figcaption>Less is Exponentially More.</figcaption></figure><h3>Architect Around Work, Not Routes</h3><p><strong>HTTP paths are not architectural boundaries</strong> <strong>— workloads are</strong>. Lambdas should be shaped by what they actually do and the dependencies they need to run efficiently.</p><p>For example, you might have a Lambda that powers your entire web server. Another for data crunching using an npm package that ships with a rust binary (<a href="https://www.npmjs.com/package/nodejs-polars">node polars</a>) leveraging multiple vCpus. A third might handle image processing with <a href="https://sharp.pixelplumbing.com/">sharp</a>, triggered by S3 uploads. And maybe another is dedicated to web scraping where you bundle a headless browser like <a href="https://developer.chrome.com/docs/puppeteer/">Puppeteer</a> as Layer to Lambda.</p><p>Each of these functions serves a <strong>real, functional purpose</strong>. They have unique performance characteristics, dependency trees, and compute or configuration needs. This is what meaningful separation looks like — it’s <strong>intentional</strong>, based on real boundaries, and grounded in how the system actually works.</p><p>But carving out a separate Lambda just because one endpoint is /user/login and the other is /user/logout? That’s not applying the Single Responsibility Principle — that’s <strong>butchering it in broad daylight</strong>.</p><p>And if you’re worried about routing flexibility, API Gateway invokes the most specific match. That means you can serve <em>all</em> your generic routes through a single Lambda while still routing specific paths to their own dedicated function. You get targeted isolation where it actually matters — without blowing up your architecture into a hundred micro-lambdas.</p><h3>The Myth of Fine-Grained Access Control and Blast Radius</h3><p>One of the most frequently cited justifications for having a separate Lambda for every endpoint is “fine-grained access control” or reducing the “blast radius.” It sounds reasonable at first — give each function the minimum permissions it needs, so if it’s compromised or misbehaves, the damage is limited. But if you take this logic to its natural conclusion, it quickly becomes absurd.</p><p>If this principle were applied consistently, you’d also be creating a <strong>separate Docker container for every HTTP endpoint</strong> in a traditional service. But nobody does that — because it’s obviously overkill and stupid.</p><p>The same goes for databases. Serverless advocates often promote <strong>single-table design</strong> ( with DynamoDB). But hang on — doesn’t that violate “fine-grained access control”? If a createUser Lambda has PutItem access on the whole table, what’s stopping it from writing into an unrelated orders record? Should we now split the table into one-per-entity to reduce the blast radius even further? because Logic is the same. Where do we stop?</p><blockquote>This isn’t architectural discipline — it’s <strong>paranoia masquerading as best practice</strong>. Security and isolation are important — but <strong>so is pragmatism</strong>. The goal is to <strong>build systems that are secure, maintainable, and efficient</strong> — not to pass a theoretical purity test.</blockquote><p>Don’t believe me. Arc codes is a serverless framework that creates a single IAM role and shares it across all functions. check <a href="https://arc.codes/docs/en/get-started/why-architect#:~:text=All%20resources%20defined%20in%20the%20manifest%20share%20one%20IAM%20Role%20with%20least%20privilege%20access%20to%20only%20the%20resources%20defined%20in%20the%20same%20stack.">here</a> and in the <a href="https://arc.codes/playground">playground</a>. Serverless framework is another one that uses single IAM role. <a href="https://www.serverless.com/framework/docs/providers/aws/guide/iam#iam-permissions-for-functions:~:text=By%20default%2C%20one%20IAM%20Role%20is%20shared%20by%20all%20the%20Lambda%20functions%20in%20your%20service.%20Also%20by%20default%2C">check here</a>.</p><h3>Bundle Size &amp; Cold Starts</h3><p>One common argument against combining endpoints into a single Lambda (a <em>lambdalith</em>) is that it results in a larger bundle size, which supposedly increases cold start latency. But this concern is often overstated and disconnected from real-world usage patterns.</p><p>The truth is: <strong>most of your endpoints share the same core dependencies. </strong>Your db libraries like node-postgres, drizzle or dynamodb toolbox, zod or arktype for validation all remain the same. Moreover the relation between bundle size and cold start is not linear. The typescript ecosystem is amazing and you have great tree shakeable and optimized libraries. You have honojs for web server, you have zero abstraction ORMs like zapatos.</p><p>With a <strong>Lambdalith</strong>, you unlock powerful reuse: secrets from Parameter Store, database connections, and shared libraries are all initialized once and reused across requests. Since one Lambda handles multiple routes, it receives steady traffic and stays warm, reducing cold starts and latency. But there’s more — even if a Lambda stays warm for 5–6 minutes, <strong>DynamoDB’s keep-alive is only ~90 seconds</strong>. (personal experience not official number) So if a function isn’t hit frequently, you’ll pay a hidden penalty: a warm Lambda but a cold DB connection. That’s a <strong>cold start inside a warm start</strong>. Split your app into dozens of tiny Lambdas and you multiply this pain.</p><h3>The Developer Experience, Debugging Experiece and Deployment Efficiency: Lambdaliths Keep You in Flow</h3><p>When you’re following the “one Lambda per endpoint” pattern, <strong>every new endpoint means deploying a new function</strong> — along with its own permissions, logging config, and event source mappings. It’s ceremony without substance. With Lambdalith you can just sam sync instead of sam deploy which is way faster.</p><p>And then there’s IAM: ever added PutItem permissions for DynamoDB and realized you now need BatchWriteItem for DynamoDB? Guess what — time to redeploy.</p><p>With single function lambdas you get burried under a maze of log groups. With multiple developers and all running their personal stacks this gets amplified. keep searching your logs in the awful AWS UI.</p><p>You can btw have a single log group for all your lambdas but no one practices that and it comes with some dope benefits but that is for some other day.</p><blockquote>Developer Experience makes you agile not scrum ceremonies or over engineering.</blockquote><h3>Event Warming and Provisioned Concurrency</h3><p>When it comes to <strong>event warming</strong> or <strong>provisioned concurrency</strong>, Lambdaliths shine. Why? Because you’re keeping <strong>one Lambda warm</strong> that serves many routes — that’s <strong>maximum ROI</strong> on your warm instance. A provisioned concurrency of 50 costs $108 per month. If you want to have that for 20 different micro lambdas that is $2160 And many of those might barely get any traffic.</p><h3><strong>Over-Engineering Is Good Business (For Them)</strong></h3><p>Not every “best practice” is about what’s best for your app — sometimes, it’s about what’s best for someone’s business model.</p><p>Some third-party vendors charge <strong>per Lambda function</strong> or <strong>CloudFormation stack</strong>, so the more you split things up, the more they profit. Even AWS with <strong>AWS Inspector</strong> charge <strong>$0.30 per function per month</strong>, and with dozens of Lambdas, that adds up fast. More functions also mean more surface area for observability, monitoring, and security tools — all of which feed into paid services.</p><p>Even worse, some vendors charge <strong>per user</strong>, and managing a highly fragmented setup often demands <strong>bigger teams</strong>. That’s great for them — more seats, more subscriptions — but not for you.</p><p>And let’s not forget the gatekeepers who define “proper serverless” in ways that conveniently align with their consulting gigs.</p><p>What looks like architectural purity is often just someone else’s <strong>revenue stream</strong> in disguise.</p><p>The “one Lambda per endpoint” mantra may sound clean in theory, but in practice, it creates unnecessary complexity, inflates costs, bloats your infrastructure, and hurts developer experience. Lambdas should be shaped by functional boundaries, not URL patterns. Lambdaliths give you better cold start performance, resource reuse, simpler deployments, saves you on developer cost all without sacrificing maintainability.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c9e264d02ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DynamoDB Data Browser]]></title>
            <link>https://ankit-aabad.medium.com/dynamodb-data-browser-cb7c1e94e731?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb7c1e94e731</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[dynamodb]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Sat, 30 Nov 2024 10:22:00 GMT</pubDate>
            <atom:updated>2024-12-01T02:04:28.553Z</atom:updated>
            <content:encoded><![CDATA[<p>Early sneak peek into an alternative GUI client for DDB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qvL_dduLijDNPP3KEQcrkg.png" /></figure><p>If you’ve ever felt frustrated with the default DynamoDB UI in the AWS Console (or nosql workbench UI), you’re not alone. I wanted a better way to browse my DynamoDB data, so I decided to create an alternative GUI client — specifically designed for locally running DynamoDB. While it’s still in the early stages, I thought it would be fun to share it with the public and get some feedback.</p><h3>Key Features So Far</h3><p>Here’s what the DynamoDB Data Browser can do right now:</p><p>🚀 <strong>Quick JSON View</strong>: Easily view your DynamoDB data in a readable JSON format.</p><p>🚀 <strong>Copy to Clipboard</strong>: Copy individual attributes or entire rows from context menu.</p><p>🚀 <strong>Filter Data</strong>: Apply filters to quickly find the data you need.</p><p>🚀 <strong>Automatic Data Re-fetch</strong>: The data reloads automatically whenever the tab becomes active again.</p><h3>Upcoming Features</h3><p>⏭ <strong>Watch Mode</strong>: Track real-time changes to your DynamoDB data.</p><p>⏭ <strong>Table Stats</strong>: View metrics and stats related to your DynamoDB table items.</p><p>⏭ <strong>Checkpoint Reset</strong>: Reset your table to last checkpoint.</p><h3>How to Use the DynamoDB Data Browser</h3><p>To get started with the DynamoDB Data Browser, follow these steps:</p><ol><li><strong>Run DynamoDB Locally</strong> First, you’ll need to run DynamoDB locally. You can do this by using the following command:</li></ol><blockquote>java -Djava.library.path=./dynamoLocal/DynamoDBLocal_lib -jar ./dynamoLocal/DynamoDBLocal.jar -port 8000 -cors “<a href="https://ankit-ddb.netlify.app/">https://ankit-ddb.netlify.app/</a>&quot; -sharedDb</blockquote><p><strong>2. Access the Data Browser</strong> Once DynamoDB is running locally, head over to <a href="https://ankit-ddb.netlify.app/">https://ankit-ddb.netlify.app/</a>. We need to add connection to browse data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*iT8iOluFyr8iIPXkrf6UqQ.gif" /></figure><p><strong>3. Add Your DynamoDB Settings</strong> In the Data Browser, add the settings for your locally running DynamoDB instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*N8I8aJlLItHNKit0l6EFLQ.png" /></figure><p><strong>4. Browse Your Data</strong> Navigate to the “Browser” tab, where you’ll be able to view and interact with all the data in your DynamoDB tables. Here’s a quick screen-cast showing off some of the features with some random data.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2FnxW6tEP7KHI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fwatch%3Fv%3DnxW6tEP7KHI&amp;image=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttps%2Fi.ytimg.com%2Fvi%2FnxW6tEP7KHI%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d1a7b6d671d4da714143eb797a2c583/href">https://medium.com/media/9d1a7b6d671d4da714143eb797a2c583/href</a></iframe><p><strong>Project Roadmap: </strong>A bare minimum project management is done through a Todo file. You can check it <a href="https://github.com/ankitaabad/DynamoDataBrowser/blob/master/TODO">here</a>. Current status 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2gTKJaZhcy7MZDdFVqIAzQ.png" /></figure><p>Currently it only supports locally running DynamoDB as its features depends on Table Scans. I will add support for AWS hosted version as well but should be used for your Dev tables only where data is not huge.</p><p>This is a work in progress, and there’s still a lot of development to be done. I’d love to hear your feedback! If you have any feature requests or want to report bugs, feel free to raise them on GitHub.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb7c1e94e731" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Picking the Right Tools for Postgres and Node.js]]></title>
            <link>https://ankit-aabad.medium.com/picking-the-right-tools-for-postgres-and-node-js-6b2a82693c8a?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b2a82693c8a</guid>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Wed, 12 Jun 2024 05:43:07 GMT</pubDate>
            <atom:updated>2024-06-13T03:22:11.055Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zxp7SncPPCzwBsKvq7FOoQ.png" /></figure><blockquote>Choosing database abstractions that prioritize easy switching tomorrow over efficient use today is like buying a car because it’s easy to sell. In both cases, you’re setting yourself up for a bumpy ride.</blockquote><p>When working with Postgres and Node.js, choosing the right tools can make a significant difference in your development experience and the maintainability of your codebase. Previously, I used Prisma ORM but found it lacking and bloated in certain areas, leading me to explore alternatives.</p><p>Among the plethora of options available, <a href="https://salsita.github.io/node-pg-migrate/"><strong>node-pg-migrate</strong></a> and <a href="https://jawj.github.io/zapatos/"><strong>Zapatos</strong></a> stand out as excellent choices for managing database migrations and building type-safe queries, respectively. Both of them are postgres centric.</p><blockquote><em>Why only Postgres?</em> — By writing this migration tool specifically for postgres instead of accommodating many databases, we can actually provide a full featured tool that is much simpler to use and maintain. I was tired of using crippled database tools just in case one day we switch our database.: <strong><em>node-pg-migrate</em></strong></blockquote><p><strong>Node-pg-migrate</strong> is a powerful tool for managing Postgres database migrations in Node.js. It helps you evolve your database schema over time in a controlled and consistent manner.</p><p>This is how the code looks like for migrations, for detailed instructions head over to their <a href="https://salsita.github.io/node-pg-migrate/">documentation</a>.</p><pre>exports.up = (pgm) =&gt; {<br>  pgm.createTable(&#39;users&#39;, {<br>    id: &#39;id&#39;,<br>    name: { type: &#39;varchar(1000)&#39;, notNull: true },<br>    createdAt: {<br>      type: &#39;timestamp&#39;,<br>      notNull: true,<br>      default: pgm.func(&#39;current_timestamp&#39;),<br>    },<br>  });<br>  pgm.createTable(&#39;posts&#39;, {<br>    id: &#39;id&#39;,<br>    userId: {<br>      type: &#39;integer&#39;,<br>      notNull: true,<br>      references: &#39;&quot;users&quot;&#39;,<br>      onDelete: &#39;cascade&#39;,<br>    },<br>    body: { type: &#39;text&#39;, notNull: true },<br>    createdAt: {<br>      type: &#39;timestamp&#39;,<br>      notNull: true,<br>      default: pgm.func(&#39;current_timestamp&#39;),<br>    },<br>  });<br>  pgm.createIndex(&#39;posts&#39;, &#39;userId&#39;);<br>};</pre><p><strong>Zapatos</strong> is a zero-boilerplate, high-performance, fully type-safe SQL query builder for Postgres. It leverages TypeScript’s type system to ensure that your database queries are type-safe, reducing runtime errors and improving code maintainability.</p><p><strong><em>Code Samples</em></strong></p><pre>const <br>  // insert one<br>  steve = await db.insert(&#39;authors&#39;, { <br>    name: &#39;Steven Hawking&#39;, <br>    isLiving: false,<br>  }).run(pool),<br><br>  // insert many<br>  [time, me] = await db.insert(&#39;books&#39;, [{ <br>    authorId: steve.id, <br>    title: &#39;A Brief History of Time&#39;,<br>    createdAt: db.sql`now()`,<br>  }, { <br>    authorId: steve.id, <br>    title: &#39;My Brief History&#39;,<br>    createdAt: db.sql`now()`,<br>  }]).run(pool),<br><br>  tags = await db.insert(&#39;tags&#39;, [<br>    { bookId: time.id, tag: &#39;physics&#39; },<br>    { bookId: me.id, tag: &#39;physicist&#39; },<br>    { bookId: me.id, tag: &#39;autobiography&#39; },<br>  ]).run(pool),<br><br>  // insert with custom return values<br>  nutshell = await db.insert(&#39;books&#39;, { <br>    authorId: steve.id, <br>    title: &#39;The Universe in a Nutshell&#39;,<br>    createdAt: db.sql`now()`,<br>  }, {<br>    returning: [&#39;id&#39;],<br>    extras: { <br>      aliasedTitle: &quot;title&quot;,<br>      upperTitle: db.sql&lt;s.books.SQL, string | null&gt;`upper(${&quot;title&quot;})`,<br>    },<br>  }).run(pool);</pre><pre>const bookAuthorTags = await db.select(&#39;books&#39;, db.all, {<br>  lateral: {<br>    author: db.selectExactlyOne(&#39;authors&#39;, { id: db.parent(&#39;authorId&#39;) }),<br>    tags: db.select(&#39;tags&#39;, { bookId: db.parent(&#39;id&#39;) }),<br>  }<br>}).run(pool);</pre><pre>type bookAuthorSQL = s.books.SQL | s.authors.SQL | &quot;author&quot;;<br>type bookAuthorSelectable = s.books.Selectable &amp; { author: s.authors.Selectable };<br><br>const query = db.sql&lt;bookAuthorSQL, bookAuthorSelectable[]&gt;`<br>  SELECT ${&quot;books&quot;}.*, to_jsonb(${&quot;authors&quot;}.*) as ${&quot;author&quot;}<br>  FROM ${&quot;books&quot;} JOIN ${&quot;authors&quot;} <br>  ON ${&quot;books&quot;}.${&quot;authorId&quot;} = ${&quot;authors&quot;}.${&quot;id&quot;}`;<br><br>const bookAuthors = await query.run(pool);</pre><p>Head over to the zapatos’ official <a href="https://jawj.github.io/zapatos/">documentation</a> for detailed user guide.</p><p>Using specialized tools rather than general ones can be a game-changer. It is rare to switch from one relational database to another, so investing in tools that are specifically designed for your current setup is a smart move. Happy coding!</p><p><a href="https://enlear.academy/asynchronously-invoking-lambda-function-from-another-lambda-c469d27625ca">Asynchronously Invoking Lambda Function from Another Lambda</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b2a82693c8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript Productivity with Lodash]]></title>
            <link>https://ankit-aabad.medium.com/javascript-productivity-with-lodash-7ab39750101e?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ab39750101e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[lodash]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 16:07:28 GMT</pubDate>
            <atom:updated>2022-04-25T16:07:28.568Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Improve Javascript Productivity With Lodash</h3><h4>Useful Utilities of Lodash</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gxh-8Xq9yb8nBpDdw0XBLQ.png" /></figure><blockquote>You cannot make your days longer, so strive to make them better.</blockquote><p>I heavily rely on external libraries to get things done quicker and better. Javascript Ecosystem is huge and we can use it to save our time and headaches. One of the very useful libraries that I use every day is <a href="https://lodash.com/docs/4.17.15"><strong>Lodash</strong></a><strong>.</strong></p><p>I recently created a video to cover some of the very useful utilities Lodash provides.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2FK3kZ09iSzXw%3Fstart%3D407%26feature%3Doembed%26start%3D407&amp;display_name=YouTube&amp;url=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fwatch%3Fv%3DK3kZ09iSzXw&amp;image=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttps%2Fi.ytimg.com%2Fvi%2FK3kZ09iSzXw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dac108da3a9c29b6aa03cfec6b19b67c/href">https://medium.com/media/dac108da3a9c29b6aa03cfec6b19b67c/href</a></iframe><p>In this article, I will cover 4 equally useful utilities that I didn’t cover as part of my video. Let’s Begin.</p><h3>over</h3><p>This one is really cool. If you want to run multiple functions on the same dataset then you can use ‘over’. Let me give you an example. Let&#39;s say you want to calculate the minimum, maximum, and mean of numbers. You can use ‘over’ to combine all three functions and reuse them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uVzW9FcwwM_O-bppvg2vdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*INnrdmLfT-UbYn5YwdApAg.png" /><figcaption>Output</figcaption></figure><p>Here we use over to create a new function which is a combination of 3 functions: min, max, and mean. The newly created function ‘minMaxMean’ can now be used to calculate all 3 values in one go.</p><h3>partial</h3><p>Let&#39;s take an example to understand partial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrkYpsvIur4fVWV88hwp2A.png" /><figcaption>partial</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jd-X-9cctTySfIkrOaE5uQ.png" /><figcaption>Output</figcaption></figure><p>We have a function ‘response’ which takes two arguments: ‘status’ and ‘data’ and returns a stringified object.</p><p>Now we apply the partial function to “response” function by fixing the status to 200 and 400 to create two more functions “okResponse” and “badRequest”.<br>Now we can directly call the functions and we need not provide the status argument. This is useful to generate more specific functions from general functions.</p><h3>cloneDeep</h3><p>Cloning a deeply nested object is non-trivial. If you try to do it from scratch, there are good chances that you will burn yourself. so Instead, rely on the time tested cloneDeep utility from lodash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GL-gtJUOp8KfhSAzWtRpbw.png" /><figcaption>cloneDeep</figcaption></figure><p>Now any changes done to ‘clonedObj’ will not affect the original ‘obj’ and vice-versa.</p><h3>intersection:</h3><p>This function takes two arrays as arguments and returns the common elements in the two arrays.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qQa1obXkB60CeQUFyOjJlw.png" /><figcaption>intersection</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*LKUWg_PKmat-HlVXM7240Q.png" /><figcaption>output</figcaption></figure><p>The number 1 and 5 appear in both the arrays so the intersection function returns [1,5] when we run intersection on the two arrays.</p><p>I hope you liked the article and learned something new from it. Do check out my <a href="https://www.youtube.com/watch?v=K3kZ09iSzXw&amp;t=75s&amp;ab_channel=AnkitAabad">tutorial on lodash</a> and subscribe to my channel.</p><p><a href="https://www.youtube.com/channel/UCYSdp0b4fwfVZ36H4dsg1NQ">Ankit Aabad</a></p><h3>Learn More</h3><ul><li><a href="https://enlear.academy/quick-react-productivity-hack-c92ea7facc2b">Quick Hack to Increase React Productivity</a></li><li><a href="https://enlear.academy/frontend-developer-resources-82a75bdc957c">Frontend Developer Resources</a></li><li><a href="https://enlear.academy/hoisting-in-javascript-23901c63ac19">What Is Hoisting in JavaScript</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ab39750101e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asynchronously Invoking Lambda Function from Another Lambda]]></title>
            <link>https://ankit-aabad.medium.com/asynchronously-invoking-lambda-function-from-another-lambda-c469d27625ca?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/c469d27625ca</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Fri, 14 Jan 2022 13:50:54 GMT</pubDate>
            <atom:updated>2022-01-14T13:50:54.502Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JhQGnGnaYgDNiaImXyPMZQ.jpeg" /></figure><p>It&#39;s good to know what you can do with the AWS services, but it&#39;s equally important, if not more, to know what you cannot do. A good solution architect knows the limitations of the different AWS services like Lambda, API Gateway, DynanoDB, etc.</p><p>AWS Lambda has a timeout of 15mins and API Gateway has a timeout of just 30 seconds. If you trigger a lambda from API Gateway, the lambda will also time out in 30 seconds. If you want to perform some time-consuming tasks in lambda invoked from APIGateway, how do we circumvent this problem. Since the lambda triggered by the API Gateway will timeout in 30 seconds, we don&#39;t have much choice but to invoke another lambda. There are multiple ways in which we can do this.</p><ul><li>Using SQS</li><li>Step Functions</li><li>Async Lambda Invocations</li></ul><p>Async lambda invocation is the simplest and straightforward way to go about this problem. Async invocation means that the lambda that invokes the other lambda does not wait for the second lambda to finish and immediately returns.<br>There are 2 lambdas. We will call them lambda-one and lambda-two. Lambda-one is invoked using APIGateway, and then lambda-one invokes the lambda-two asynchronously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*qf6ewuR2JarokODDr2F6EA.png" /></figure><p>Required things to invoke lambda:</p><ol><li><strong>Name of the function we want to invoke</strong>: Serverless, while creating the lambda, constructs the function name by appending the service name and stage name to the function name. If the service name is &#39;experiment&#39; and stage is &#39;dev,&#39; then our second lambda&#39;s function name becomes &#39;experiment-dev-lambda-two.&#39; so we pass the FUNCTION_PREFIX ( which consists of service name and stage ) into env in serverless.yml file.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5bfb42d1f44992ee2873dcc1ed449c7/href">https://medium.com/media/c5bfb42d1f44992ee2873dcc1ed449c7/href</a></iframe><p>and we construct the function name using the function prefix that we receive from the environment.</p><pre><em>const FunctionName = `${process.env.FUNCTION_PREFIX}-${function_name}`;</em></pre><p>2. <strong>Permissions:</strong> We also need to give permission to invoke the other lambda. so we allow for &quot;lambda:InvokeFunction&quot; and &quot;lambda:InvokeAsync&quot; in the &quot;iamRoleStatements&quot; in &quot;serverless.yml&quot;.</p><p>3. <strong>Payload:</strong> for payload, we use the &quot;casual&quot; npm package to generate some fake data. We use &quot;casual.card_data&quot; to generate some card data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5783b78c123d1c6830cb41b3287014a0/href">https://medium.com/media/5783b78c123d1c6830cb41b3287014a0/href</a></iframe><p>We need to stringify the data that we send as payload to the lambda-two, and lambda-two receives a parsed version of the payload in the event.</p><p>4.<strong> InvocationType:</strong> By default, the invocation is done synchronously. To invoke lambda asynchronously, we need to set &quot;InvocationType&quot; as &quot;Event&quot; in the invoke method of the lambda.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca084d23d0bd3bfdb2c9014c4f1a7e6c/href">https://medium.com/media/ca084d23d0bd3bfdb2c9014c4f1a7e6c/href</a></iframe><p>In &quot;lambda-two,&quot; we will just print the payload. Remember, we don&#39;t need to parse it. What we receive is a JSON object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74de99a56ec034132124f6ad74336395/href">https://medium.com/media/74de99a56ec034132124f6ad74336395/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1aF4sOE1X8uyddv9_JrYMw.png" /><figcaption>Cloudwatch logs</figcaption></figure><blockquote>You can have a look at the complete code here <a href="https://github.com/ankitaabad/Async-Lambda-Invoke">Async-Lambda-Invoke🔗</a>.</blockquote><p>I hope you enjoyed reading the post as much as I enjoyed writing it.🥰</p><p><a href="https://www.linkedin.com/in/ankit-aabad/">Ankit Aabad ♠ Serverless ♠ Javascript Everywhere - Member Of Technical Staff 1 - AntStack | LinkedIn</a></p><h3>Learn More</h3><ul><li><a href="https://enlear.academy/how-to-avoid-lambda-cold-starts-917437434c95">How to Avoid Lambda Cold Starts</a></li><li><a href="https://enlear.academy/sharing-code-among-lambdas-using-lambda-layers-ca097c8cd500">Sharing Code among Lambdas using Lambda Layers</a></li><li><a href="https://enlear.academy/lambda-layers-tips-tricks-3f1a4343a434">Lambda Layers — Tips &amp; Tricks</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c469d27625ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Speed up file Uploading to AWS S3]]></title>
            <link>https://ankit-aabad.medium.com/how-to-speed-up-file-uploading-to-aws-s3-29f0fbdceaf6?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/29f0fbdceaf6</guid>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Thu, 13 Jan 2022 17:03:00 GMT</pubDate>
            <atom:updated>2022-01-13T17:03:00.209Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jf4Gg7ZK-OfqT8SS-hefRw.jpeg" /></figure><p>If you are reading this article then there are good chances that you have uploaded some files to AWS S3. In this article, we will look at different ways to speed up our S3 uploads.</p><h3>Experiment:</h3><p>I created a small <strong><em>s</em></strong><a href="https://github.com/ankitaabad/S3-UPLOAD-OPTIMIZATION"><strong><em>erverless project</em></strong></a> with 3 different endpoints using 3 different strategies. Each request will create an approx 200 MB fake file and try a different strategy to upload the fake file to S3. In the end, we will compare the execution time of the different strategies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5df4b0c4d9c5d4886f3773debce4cdee/href">https://medium.com/media/5df4b0c4d9c5d4886f3773debce4cdee/href</a></iframe><p><strong>Single part upload:</strong> This is the standard way to upload the files to s3. Provide the Bucket, key, and Body and use the &quot;putObject&quot; method to upload the file in a single part.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65339490ef0868e31af7115b6d24c91c/href">https://medium.com/media/65339490ef0868e31af7115b6d24c91c/href</a></iframe><p><strong>Multipart upload: </strong>If you are old enough, you might remember using download managers like Internet Download Manager (IDM) to increase download speed. These download managers break down your download into multiple parts and then download them parallel. What if I tell you something similar is possible when you upload files to S3. Instead of &quot;putObject&quot; we have to use the upload method of s3. and we can optionally provide the number of parts in which we want to divide our file and upload in parallel. &quot;queueSize&quot; is set in the second parameter of the upload parameter to set the number of parts you want to upload in parallel. It&#39;s an optional parameter and defaults to 4. we can also provide a per partSize.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b2a25c29e0e0b64a3e31748f80218a2/href">https://medium.com/media/2b2a25c29e0e0b64a3e31748f80218a2/href</a></iframe><p><strong>Using stream to upload</strong>: Stream simply means that we are continuously receiving/sending the data. Instead of waiting for the whole data to receive, we can also upload it to s3 using a stream. So, when we receive the data, it will get uploaded to the S3, so we provide a stream instead of buffer to the Body parameter of the S3 upload method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b23953b88d00ab833603960d1499862/href">https://medium.com/media/1b23953b88d00ab833603960d1499862/href</a></iframe><h3>Results:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hTtxooHzKlYX8jwl-BsbhA.png" /><figcaption>33% Drop in upload time to AWS- S3</figcaption></figure><p>Multipart with stream strategy took 33% less time than the single part strategy. Using Streams can be more useful when we receive data more slowly, but here we are streaming from local storage, which is very fast, so we might not see much of a difference in multipart and multipart with stream strategy.</p><p>Anyways the next time, whenever you want to upload a huge file to S3, try the &quot;multipart&quot; upload strategy ( combine streams if required) to save cost on your AWS bills and a faster execution time.</p><p>I hope you enjoyed the article. Let me know in the comments.</p><p><a href="https://www.linkedin.com/in/ankit-aabad/">Ankit Aabad ♠ Serverless ♠ Javascript Everywhere - Member Of Technical Staff 1 - AntStack | LinkedIn</a></p><h3>Learn More</h3><ul><li><a href="https://enlear.academy/my-aws-solutions-architect-professional-exam-experience-98e691d93e6f">My AWS Solutions Architect Professional Exam Experience</a></li><li><a href="https://enlear.academy/aws-s3-pre-signed-urls-51b1cdfe737a">What is AWS S3 Pre-Signed URL</a></li><li><a href="https://enlear.academy/aws-ebs-vs-efs-vs-s3-75bd5f3ce94d">AWS EBS vs EFS vs S3</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29f0fbdceaf6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Write Better JavaScript Code with “forEach” and “reduce”]]></title>
            <link>https://ankit-aabad.medium.com/how-to-write-better-javascript-code-with-foreach-and-reduce-415a1d58195?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/415a1d58195</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Tue, 28 Sep 2021 19:02:43 GMT</pubDate>
            <atom:updated>2021-09-29T02:17:25.014Z</atom:updated>
            <content:encoded><![CDATA[<h4>Leverage the language to write better code.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9v2QV4mN4By5LphJjXr9OQ.jpeg" /></figure><p>In this article, we will take a small problem and try to write some elegant javascript to solve that problem. The idea is to write small reusable functions and leverage language constructs like <strong>forEach</strong> and <strong>reduce</strong> to solve problems.</p><h4>Problem Statement:</h4><p>We have an array of objects. Every object represents a person with his income and expenditures, and we want to find the person with the highest savings.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b403715e4e134f19fc2ef491d512d41a/href">https://medium.com/media/b403715e4e134f19fc2ef491d512d41a/href</a></iframe><p>In the above example, Alice has an income of 50000, and her expenditure is equal to (8000 + 2000 + 4500 ) = 14500. so her savings is equal to 35500.</p><p>Bob has an income of 45000, and his expenditure equals ( 7000 + 3000 ) =10000. so his savings is equal to 35000. This means that Alice saves more than Bob, and our program should output <strong>Alice</strong> as the answer.</p><h4>A function to find the total expenditure</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*H3unBtipTPEiQZPkeuRphA.png" /><figcaption>Alice and Bob&#39;s Expenditure</figcaption></figure><p>expenditure is an object and can have multiple and different values. Here Alice has three different expenditures, and Bob has only two expenditures. We want to write a function to sum the values of the expenditure object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89677d94ff26155bccec7094934c9d99/href">https://medium.com/media/89677d94ff26155bccec7094934c9d99/href</a></iframe><p>Object.values(obj) returns an array of values in expenditure object.</p><p>for Alice it returns [8000,2000,4500]<br>for Bob, it returns [7000,3000]</p><p>then we chain a reduce function to this expenditure array and find the sum of all expenditures.<br>for Alice total_expenditure function will return 14500, and for Bob, it will return 10000</p><h4>A function to find the savings</h4><p>Now we write another function “find_savings”, which subtracts expenditure from the income of the person. It takes the person as input and returns the savings of that person.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4aeb09bf8852ca40153ddd75c86a2131/href">https://medium.com/media/4aeb09bf8852ca40153ddd75c86a2131/href</a></iframe><p>for Alice it returns 50000 -14500 = 35500 and for Bob it returns 45000 -10000 = 35000.</p><h4><strong>Finding the person with the most savings</strong></h4><p>Now we want to compare and find the person with the most savings. So we start with our answer as {savings: -1}. And then, we use a forEach loop to iterate through all persons, and if someone has higher savings than what we encountered previously, we update the savings and name of that person in our answer object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2dfbbd8e02849ef0e8f4a019f82deb8/href">https://medium.com/media/b2dfbbd8e02849ef0e8f4a019f82deb8/href</a></iframe><p>and finally, we print answer.name as our solution.✌️</p><p><strong>What you learned from the example </strong>:</p><blockquote>Using the Bottom up approach to solve problems</blockquote><p>We broke the problem using the bottom-up approach. We wanted to find the person with the highest savings. For that, we need to find the savings of each person, and for finding the savings we need to find the total expenditure. so we started with finding total expenditure, then finding the person&#39;s savings, and then comparing the savings.</p><blockquote>Use higher Order functions like <strong>forEach</strong> and <strong>reduce</strong>.</blockquote><p>There are two benefits of using higher-order functions like map, reduce, forEach etc. First, we don&#39;t need to worry about our array index going out of bounds. Second, they are more readable. When you are using <strong>reduce, </strong>for example, the reader will know your intention. But if you use vanilla for loop, it is not very readable.</p><p>I hope you enjoyed reading this article. For more Tips and Tricks, follow me so that you are notified whenever I write a new post. 🥰</p><h3>Learn More</h3><ul><li><a href="https://enlear.academy/recipe-for-a-new-web-developer-137780bfb131">Recipe for: A New Web developer</a></li><li><a href="https://enlear.academy/the-saga-of-async-javascript-callbacks-6f56b3490f4d">The Saga Of Async JavaScript: Callbacks</a></li><li><a href="https://enlear.academy/axios-vs-fetch-for-http-requests-f11f98e719c1">Axios Vs. Fetch for HTTP Requests</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=415a1d58195" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to automate Request Trimming in Express ??]]></title>
            <link>https://ankit-aabad.medium.com/how-to-automate-request-trimming-in-express-ee11f84d2ce0?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee11f84d2ce0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Fri, 24 Sep 2021 15:19:40 GMT</pubDate>
            <atom:updated>2021-09-24T15:19:40.367Z</atom:updated>
            <content:encoded><![CDATA[<h4>Remove extra spaces from your requests like a pro</h4><figure><img alt="automate request trimming" src="https://cdn-images-1.medium.com/max/552/1*i6Hk8FMCcxrifYGmogWGdA.png" /><figcaption>Automate Request Trimming</figcaption></figure><p>Recently I came across a bug 🐞, in which the user sent some information with extra white spaces in the end. In the backend, I forgot to trim that data. But why should I trim every string that I receive every time? so I created an NPM package that can trim all the requests and I can live a worry-free life.</p><p>You can install the package with the following command</p><pre>npm i request_trimmer</pre><p>Let&#39;s see it in action first:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89d4f76f17e281b3fa54df0029dea654/href">https://medium.com/media/89d4f76f17e281b3fa54df0029dea654/href</a></iframe><p>Here we are just trimming the request body (and request query) and sending the request body back to the user.</p><figure><img alt="Deeply Nested request body getting trimmed automatically." src="https://cdn-images-1.medium.com/max/1024/1*LQ6ECwVmHjtMActoka8UeQ.gif" /><figcaption>Deeply Nested request body getting trimmed automatically.</figcaption></figure><blockquote>💪 Trimming is done recursively. so It doesn’t matter how deep is your request body or any other object.</blockquote><p>This package provides 4 express middlewares and 1 utility function.</p><ul><li><strong>trim_all</strong>: This middleware trims the request body and request query. How to use it:</li></ul><pre>app.use(trim_all);</pre><ul><li><strong>trim_params</strong>: This middleware trims the request params. Remember that params are only available after route match. How to use it:</li></ul><pre>app.post(&quot;\posts\:id&quot;,trim_params,(req,res) =&gt; {...});</pre><ul><li><strong>trim_body</strong>: This middleware trims the request body.</li><li><strong>trim_query</strong>: This middleware trims the request query.</li><li><strong>trim_util</strong>: This function can trim any object. You can use this when you receive data from third-party API or you are converting your excel to JSON and then you want to trim your whole excel data.</li></ul><blockquote>One thing you have to remember is, You have to use express.json() middleware before using these trimming middleware as express.json() middleware only add body and query fields to request object.</blockquote><p>I hope you find this post and this package useful. 😍</p><p><a href="https://www.linkedin.com/in/ankit-aabad/">Ankit Aabad ♠ Serverless ♠ Javascript Everywhere - Member Of Technical Staff 1 - AntStack | LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee11f84d2ce0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[‍♀️ Why I love  this keyboard ‍♂️]]></title>
            <link>https://ankit-aabad.medium.com/%EF%B8%8F-why-i-love-this-keyboard-%EF%B8%8F-3b0d6d6d4b08?source=rss-52e8b0da4fba------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b0d6d6d4b08</guid>
            <category><![CDATA[typing]]></category>
            <category><![CDATA[best-mechanical-keyboards]]></category>
            <category><![CDATA[mechanical-keyboards]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[keyboard]]></category>
            <dc:creator><![CDATA[Ankit Aabad]]></dc:creator>
            <pubDate>Fri, 24 Sep 2021 10:29:03 GMT</pubDate>
            <atom:updated>2021-09-27T08:55:52.177Z</atom:updated>
            <content:encoded><![CDATA[<h4>The TVS Gold Keyboard</h4><figure><img alt="TVS Gold Keyboard" src="https://cdn-images-1.medium.com/max/1024/1*HQ8A8TBNkkg5nobbmIz2pA.jpeg" /><figcaption>TVS Gold Keyboard</figcaption></figure><h4><strong>Looks can be deceiving.</strong></h4><p>They say the first impression is the last impression. They cannot be more wrong. My Friend when first recommended it, I was like what’s there to like about it. Just a giant keyboard. No RGB 🌈 lighting, nothing fancy about it. I was wrong. With every day I appreciate the simplicity and the thought process that went behind in the development of such a nice keyboard.</p><h4>I’m inclined to it 😍</h4><figure><img alt="TVS Gold Keyboard" src="https://cdn-images-1.medium.com/max/1024/1*GAMbRNcEnD25p19tUbnwYA.jpeg" /><figcaption>TVS Gold Keyboard</figcaption></figure><p>The keys are not laid out flat but they are inclined. so it is easier and very natural to reach the keys. Once you get used to this there is no going back to flat keyboards.</p><p><strong>Mechanical Switches</strong></p><p>This keyboard comes with “Long Hua“ blue switches. These switches are cheap Chinese clones of the famous blue Cherry MX switches. when I say cheap I mean in price and not in quality. If you are using a mechanical keyboard for the first time, it will be difficult for you to tell the difference between the two. If you are coming from membrane keyboards or scissor-style keyboards you will definitely like, how easy it is to type on mechanical keyboards. The actuation force for these keyboards is very low and so it requires comparatively less force to type on this keyboard.</p><figure><img alt="TVS Gold Keyboard" src="https://cdn-images-1.medium.com/max/1024/1*dGwvJOOa7lLnlHI-2_a0EA.png" /><figcaption>TVS Gold Keyboard</figcaption></figure><h4>Durable</h4><p>This keyboard is sturdy💪. It will last a long time. I am using it for the last year and it works the way it worked on the very first day. You can even use it as a weapon in a fight with your siblings 👊. I know few guys who are using it for more than 5 years and it works like a charm till now.</p><h4><strong>Value for Money</strong></h4><p>If you ask me, it is the best bang for bucks keyboard available in the market. It costed me around Rs 2000 (roughly $27 ). It is not fancy but functional🔥. If you want a good typing experience without being expensive 💰 then this is what I recommend.</p><p>I hope you enjoyed reading this post as much as I enjoyed writing it. Let me know your thoughts in the comments.</p><p><a href="https://www.linkedin.com/in/ankit-aabad/">Ankit Aabad ♠ Serverless ♠ Javascript Everywhere - Member Of Technical Staff 1 - AntStack | LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b0d6d6d4b08" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>