<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Juan P. Lima</title>
    <description>The latest articles on DEV Community by Juan P. Lima (@juanpireslima).</description>
    <link>https://dev.to/juanpireslima</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F842115%2Fa504b31c-afbd-425b-81aa-444b2866a283.png</url>
      <title>DEV Community: Juan P. Lima</title>
      <link>https://dev.to/juanpireslima</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/juanpireslima"/>
    <language>en</language>
    <item>
      <title>Automatically deploy your NestJS API to AWS Elastic Beanstalk using GitHub Actions</title>
      <dc:creator>Juan P. Lima</dc:creator>
      <pubDate>Wed, 10 Jan 2024 10:36:42 +0000</pubDate>
      <link>https://dev.to/juanpireslima/automatically-deploy-your-nestjs-api-to-aws-elastic-beanstalk-using-github-actions-21l6</link>
      <guid>https://dev.to/juanpireslima/automatically-deploy-your-nestjs-api-to-aws-elastic-beanstalk-using-github-actions-21l6</guid>
      <description>&lt;p&gt;After last week's post about deploying your NestJS API to AWS Elastic Beanstalk(&lt;a href="https://dev.to/juanpireslima/deploy-your-nestjs-api-on-aws-elastic-beanstalk-1on1"&gt;https://dev.to/juanpireslima/deploy-your-nestjs-api-on-aws-elastic-beanstalk-1on1&lt;/a&gt;), in this post, I'm going to help you make this process automatic by using GitHub Actions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We're going to start this post from where we stopped on the last one,&lt;/strong&gt; which we:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Created an AWS Elastic Beanstalk Application from scratch&lt;/li&gt;
&lt;li&gt;Deployed our NestJS API manually to AWS Elastic Beanstalk&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have already created your Elastic Beanstalk Application and are all set up to automate the deployment process, you can keep reading without any problem, either way, I highly recommend that you &lt;strong&gt;read the previous post before this one&lt;/strong&gt; if you haven't yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up GitHub Actions 👷
&lt;/h2&gt;

&lt;p&gt;The first thing we're going to do is set up our GitHub Actions, for that, we can go to our repository page, click on actions, and then click on "set up a workflow yourself":&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--81pn6Cs2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8strhbc85m1twzalkzc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--81pn6Cs2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8strhbc85m1twzalkzc.png" alt="GitHub Actions start page" width="800" height="393"&gt;&lt;/a&gt;&lt;br&gt;
After doing so, it's going to open a page for you to write the actions file, on the actions file, we need to set a name for our action, which I'm going to call "deploy", set up a trigger, which on my case it's going to run on every push to the main branch, and then we'll be setting up our jobs, the only job we're going to have is the one called "build-and-deploy", this job is going to run on ubuntu and it's going to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install dependencies&lt;/li&gt;
&lt;li&gt;Build our project&lt;/li&gt;
&lt;li&gt;Compress files(since we need to send a .zip to Elastic Beanstalk)&lt;/li&gt;
&lt;li&gt;Configure AWS Credentials&lt;/li&gt;
&lt;li&gt;Install Elastic Beanstalk CLI&lt;/li&gt;
&lt;li&gt;Deploy our project to Elastic Beanstalk&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--76ykQj4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zt1kz0emgsma1sevlmth.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--76ykQj4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zt1kz0emgsma1sevlmth.png" alt="Workflow file" width="800" height="708"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To correctly set up our AWS, we'll need to add some variables on our GitHub settings, you can do so by going to settings -&amp;gt; Secrets and variables -&amp;gt; Actions; there you'll be able to set up both variables and secrets, in our actions example, our AWS access key and region is a variable, while the secret is a secret, you should be creating them on the "Repository variables" section(I won't be covering the creation of AWS access credentials on this post):&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9chCCiV0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ownir7tjamuerupx5txx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9chCCiV0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ownir7tjamuerupx5txx.png" alt="Managing GitHub Actions Variables" width="800" height="531"&gt;&lt;/a&gt;&lt;br&gt;
One more thing you might've noticed is that on the deployment step, we're sending a label to Elastic Beanstalk, Elastic Beanstalk uses labels to version our project, so we must send a different label for each version of our API, that's why I'm using "github.event.repository.pushed_at" at the end, so I can get the timestamp of the last time something have been pushed to the repository, therefore making my label unique for each iteration on my code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PS:&lt;/strong&gt; &lt;em&gt;The word "test" after "eb deploy" is &lt;strong&gt;the name of the environment&lt;/strong&gt; I'm deploying to, while "my-api" after "eb init" is the &lt;strong&gt;name of my Elastic Beanstalk Application.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up Elastic Beanstalk config 🔧
&lt;/h2&gt;

&lt;p&gt;Before running our newly created action, we must create a config file for Elastic Beanstalk so it knows our deployment artifact will be called "my-api.zip", for that, we need to create a folder called ".elasticbeanstalk" at the root of our project, and there we'll have a file named "config.yml", there we'll be saying to Elastic Beanstalk that it should be deploying the artifact "my-api.zip":&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fFxTtgA_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ti8ju4pvdggd8d4ci1vp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFxTtgA_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ti8ju4pvdggd8d4ci1vp.png" alt="Elastic Beanstalk config file" width="271" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Bonus: Changing the script Elastic Beanstalk will be running 💡
&lt;/h1&gt;

&lt;p&gt;As said in the previous post about Elastic Beanstalk, it runs "npm run start" by default, but we can change that by creating a file called "Procfile" on the root of our project and changing the command that's going to run:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CmzFxAb7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5mdmtkg5nc72asfek95.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CmzFxAb7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5mdmtkg5nc72asfek95.png" alt="Procfile" width="287" height="79"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Run your GitHub actions 👌
&lt;/h2&gt;

&lt;p&gt;Once you've followed all the steps, you can commit all your changes, once the trigger is actioned, your action is going to run, as you can see, my actions ran without any problems:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8oYSfOPT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ejktv7284hhwassk2ua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8oYSfOPT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ejktv7284hhwassk2ua.png" alt="Successful GitHub Actions" width="800" height="340"&gt;&lt;/a&gt;&lt;br&gt;
Here's my API working:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pRKKIQEp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ps6affl8wo1whsax4uq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pRKKIQEp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ps6affl8wo1whsax4uq.png" alt="API Working" width="800" height="289"&gt;&lt;/a&gt;&lt;br&gt;
Hope I was able to help you guys automate the deployment of your NestJS API to AWS Elastic Beanstalk, &lt;strong&gt;you can find my code at:&lt;/strong&gt; &lt;a href="https://github.com/juanpireslima/nestjs-elastic-beanstalk"&gt;https://github.com/juanpireslima/nestjs-elastic-beanstalk&lt;/a&gt;&lt;br&gt;
If you haven't yet, I highly recommend you read my previous article about Deploying a NestJS API to Elastic Beanstalk, there, I wrote about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating an AWS Elastic Beanstalk Application - from scratch
Manually deploying a NestJS API to AWS Elastic Beanstalk&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find it at: &lt;a href="https://dev.to/juanpireslima/deploy-your-nestjs-api-on-aws-elastic-beanstalk-1on1"&gt;https://dev.to/juanpireslima/deploy-your-nestjs-api-on-aws-elastic-beanstalk-1on1&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Deploy your NestJS API on AWS Elastic Beanstalk</title>
      <dc:creator>Juan P. Lima</dc:creator>
      <pubDate>Wed, 03 Jan 2024 10:36:18 +0000</pubDate>
      <link>https://dev.to/juanpireslima/deploy-your-nestjs-api-on-aws-elastic-beanstalk-1on1</link>
      <guid>https://dev.to/juanpireslima/deploy-your-nestjs-api-on-aws-elastic-beanstalk-1on1</guid>
      <description>&lt;p&gt;Have you ever wondered how you can deploy your NestJS API on AWS Elastic Beanstalk? Wonder no more, in this article, we'll be deploying a NestJS API from scratch.&lt;/p&gt;

&lt;h1&gt;
  
  
  Pre-requisites 📔
&lt;/h1&gt;

&lt;p&gt;To follow this tutorial, you'll need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS Account&lt;/li&gt;
&lt;li&gt;NestJS project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Neither of these will be covered in this post, only the deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating your Elastic Beanstalk Application 👷
&lt;/h2&gt;

&lt;p&gt;Let's start by creating our Elastic Beanstalk application, to do so, you'll need to go to the Elastic Beanstalk service page, you'll see a button called "create application", you can click on that button to start the creation process:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gQswZIFw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64g1yoso15ekmttjucy2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gQswZIFw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64g1yoso15ekmttjucy2.png" alt="Elastic Beanstalk start page" width="800" height="373"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;PS: Make sure you're in the right region.&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
In the first creation step, we'll have to select the environment tier we want to create, for our API, we must use the "Web server environment" tier for our API, and then we can choose the name for our application, and environment information(you can't change this info later on) such as name and domain our API will be running:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hD61CPnA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbirvfxlfcecdx0skebd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hD61CPnA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbirvfxlfcecdx0skebd.png" alt="First Step" width="800" height="701"&gt;&lt;/a&gt;&lt;br&gt;
Next, we must choose the platform we're going to run, in our case, Node.js, I'll be using version 18 in this example, and then we can select to start our Elastic Beanstalk with a sample application(we'll be uploading our code later on), and we must choose which configuration preset we want to help us choose the right server configuration, I'll be going with a simple single instance:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y5InqDA3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3cik3skuwn7nfnmmfb4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y5InqDA3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3cik3skuwn7nfnmmfb4.png" alt="First step" width="770" height="831"&gt;&lt;/a&gt;&lt;br&gt;
Going to the next step, you'll have to set a role for the Elastic Beanstalk application(you can create one at that moment as well), an EC2 key pair(you can generate the SSH key on the EC2 service page by clicking on "Key pairs" on the left menu), and an instance profile for the EC2 instances that the Beanstalk is going to create(you can create this on IAM):&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2Wn1RS-n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pox86vgacxl8bppc3xxo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2Wn1RS-n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pox86vgacxl8bppc3xxo.png" alt="Second Step" width="800" height="483"&gt;&lt;/a&gt;&lt;br&gt;
On the next(optional) step, you can set up networking, database, and tags; there you can select if you're going to use a VPC, select if your instance is going to be publicly accessible and the subnets, I'll be setting up a VPC and setting my instance public and choosing two subnets:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fojlS_Tq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xh5e1yiczr0hwa9kd36q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fojlS_Tq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xh5e1yiczr0hwa9kd36q.png" alt="Third Step" width="800" height="754"&gt;&lt;/a&gt;&lt;br&gt;
You can also integrate an RDS SQL database with your environment(we won't be covering this step config in this post):&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--znbvBvWb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o05z84dn7gpg9atyt2g3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--znbvBvWb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o05z84dn7gpg9atyt2g3.png" alt="Third Step" width="765" height="824"&gt;&lt;/a&gt;&lt;br&gt;
On the 4th step(optional), you can set up info for your EC2 instances that will be created by Elastic Beanstalk, you can select the security group, and the root volume, and also set up the auto-scaling, you can choose if you want a single instance environment or a load balanced one, as well as the minimum and maximum amount of instances you want to have(if load balanced), you can also choose the instance types that Elastic Beanstalk will be creating:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EfSwYVKw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/brjksk9fzm2rzqhk6jjf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EfSwYVKw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/brjksk9fzm2rzqhk6jjf.png" alt="Fourth Step" width="660" height="830"&gt;&lt;/a&gt;&lt;br&gt;
On the 5th(also optional) step, you can set up updates, monitoring, and logging; &lt;strong&gt;we won't be covering this 5th step in this post.&lt;/strong&gt;&lt;br&gt;
In the &lt;strong&gt;last step&lt;/strong&gt;, we'll be reviewing everything we have chosen and then submit our application creation:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2BEeWEXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xe40og7ydig9tn35ex3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2BEeWEXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xe40og7ydig9tn35ex3.png" alt="Last Step" width="800" height="752"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing your sample Elastic Beanstalk Application 🚀
&lt;/h2&gt;

&lt;p&gt;After submitting your application creation, you can access the domain link that you have chosen in the creation process, you can see it in the "Environment overview" section:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1vd002gi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2u2l6u3zu96mru91i7av.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1vd002gi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2u2l6u3zu96mru91i7av.png" alt="Environment Page" width="800" height="384"&gt;&lt;/a&gt;&lt;br&gt;
By accessing it, you are going to see this page:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NjAEp3Jj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rijg9oe2gw2etamfibvr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NjAEp3Jj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rijg9oe2gw2etamfibvr.png" alt="Sample Page" width="800" height="384"&gt;&lt;/a&gt;&lt;br&gt;
That page means your application has been successfully created 👏&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying your NestJS API 🙌
&lt;/h2&gt;

&lt;p&gt;Now it's time to deploy our NestJS API, first, we'll need to check which port our NestJS App is running, Elastic Beanstalk uses port 8080 by default, you should either set that as your API port or check for the environment variable called "PORT", so you can run the project on the right port:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5i6QzKAm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwlxhrdg3qxkcfyo2k2l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5i6QzKAm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwlxhrdg3qxkcfyo2k2l.png" alt="Checking PORT variable" width="575" height="229"&gt;&lt;/a&gt;&lt;br&gt;
Then, you must make a change on your start script since that's the one Elastic Beanstalk will be running by default, you must make it &lt;strong&gt;execute the main file from the build:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VF4GD4ip--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgj7x9b22tg73cu2s0qx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VF4GD4ip--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgj7x9b22tg73cu2s0qx.png" alt="Updated starting script" width="756" height="473"&gt;&lt;/a&gt;&lt;br&gt;
now you can build your NestJS App, then we'll be compressing all local files(no need to send the node_modules, Elastic Beanstalk will be installing it for you):&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rwDtLyIr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/97x3xjaq4tlwlrzdgcno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rwDtLyIr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/97x3xjaq4tlwlrzdgcno.png" alt="Zip file from compression" width="800" height="164"&gt;&lt;/a&gt;&lt;br&gt;
Once you have compressed your project, you can go to Elastic Beanstalk, and click on "Upload and deploy":&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RgKiuWHY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikjdw0hvkz1bgch6kxez.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RgKiuWHY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikjdw0hvkz1bgch6kxez.png" alt="Environment page" width="800" height="196"&gt;&lt;/a&gt;&lt;br&gt;
and then choose your zip file, as well as write a label for your version being deployed:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V_DY1tI0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ysy9onyjtchj9tzpd50c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V_DY1tI0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ysy9onyjtchj9tzpd50c.png" alt="Deployment modal" width="673" height="475"&gt;&lt;/a&gt;&lt;br&gt;
Now you can click on "Deploy" and wait for your project to be deployed, once it's deployed, you can go to the domain you have chosen and there it is:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lKZ8suhG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zt1iyxgla2u4d4lm7kr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lKZ8suhG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zt1iyxgla2u4d4lm7kr.png" alt="Elastic Beanstalk page with our API working" width="800" height="188"&gt;&lt;/a&gt;&lt;br&gt;
Hope I was able to help you guys deploy your NestJS project on AWS Elastic Beanstalk, have a good one 😉&lt;/p&gt;

</description>
      <category>node</category>
      <category>nestjs</category>
      <category>aws</category>
      <category>programming</category>
    </item>
    <item>
      <title>Improving your App's Performance: Solving the N+1 Problem</title>
      <dc:creator>Juan P. Lima</dc:creator>
      <pubDate>Sun, 11 Jun 2023 10:41:13 +0000</pubDate>
      <link>https://dev.to/juanpireslima/improving-your-apps-performance-solving-the-n1-problem-3lge</link>
      <guid>https://dev.to/juanpireslima/improving-your-apps-performance-solving-the-n1-problem-3lge</guid>
      <description>&lt;p&gt;In this article, we'll be using a simple NodeJS API and a Postgres DataBase, the DB will have the following model:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q-q-rt6---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jp77pln4i1nhwvbrardf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q-q-rt6---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jp77pln4i1nhwvbrardf.png" alt="DB Model" width="623" height="194"&gt;&lt;/a&gt;&lt;br&gt;
We'll have the category table and the item table, and there can be many items associated with one category.&lt;br&gt;
On our NodeJS API, we'll have a function that will get all categories and their following items:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WmidRHPv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ruuq6hxfyt242bbkijov.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WmidRHPv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ruuq6hxfyt242bbkijov.png" alt="The function that will be getting the categories" width="446" height="262"&gt;&lt;/a&gt;&lt;br&gt;
And we'll have a function that will be getting items by category:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3Nf2CrCV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1urb7rd5llltnibedd8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3Nf2CrCV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1urb7rd5llltnibedd8.png" alt="The function that will be getting the items by category" width="442" height="204"&gt;&lt;/a&gt;&lt;br&gt;
for this article, we'll have: &lt;br&gt;
Category A with the items: Item 1, and Item 2&lt;br&gt;
Category B with Item 3&lt;/p&gt;

&lt;p&gt;The return from our getCategories function will be an array of categories, each one having a property called "items" that will be an array of items associated with that particular category:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yCAUEoKU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlgsy79cxkle8hiqcqek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yCAUEoKU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlgsy79cxkle8hiqcqek.png" alt="The return from our getCategories function" width="459" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;So, have you noticed any particular performance issue with the way we're getting our categories and their items? No? So let me explain…&lt;/p&gt;

&lt;h3&gt;
  
  
  The N+1 Problem
&lt;/h3&gt;

&lt;p&gt;Have you ever heard about the N+1 problem? That's when we execute N queries when we could've executed just 1, executing more queries will not only decrease the performance but will also consume more resources, and that's something we don't want in our apps.&lt;br&gt;
Going back to our example, we're executing 1 query statement to get all the categories, then we're executing another query for each category so we can get its items, in our case, we're running 3 queries, but as the amount of categories increases, so do our number of requests on the items table, making it a Big O(N).&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing our code
&lt;/h2&gt;

&lt;p&gt;Now that we know where the problem is, let's get started with our fix, first things first, we no longer need to loop through all our categories, since the items property will be coming from our query, we can also return directly the rows returned from our query, and then we can start using the "LEFT JOIN" statement in our query to fetch all items from that category.&lt;/p&gt;

&lt;p&gt;Our query would look something like this:SELECT * FROM category c LEFT JOIN item i ON i.category_id = c.id; , the problem with this query, is that it won't be returning the data in the format we're expecting, see an example from executing this query on DBeaver:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uKvAXf76--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8tb2uycfy22eansskxj7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uKvAXf76--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8tb2uycfy22eansskxj7.png" alt="The data returned from DBeaver" width="644" height="72"&gt;&lt;/a&gt;&lt;br&gt;
It would be repeating the category on every item it has, that's not what we want, so we need to make one last change in our query, that is, selecting all category's properties, aggregate the values coming from the item table, and add a "Group By" clause with the id of our category on it, that would be our final query: SELECT c.*, json_agg(i) items FROM category c LEFT JOIN item i ON i.category_id = c.id GROUP BY c.id; , see how the result looks on DBeaver:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OT9xXQC2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8v5kfnwp66cfdamkvs74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OT9xXQC2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8v5kfnwp66cfdamkvs74.png" alt="The data returned from DBeaver" width="800" height="40"&gt;&lt;/a&gt;&lt;br&gt;
Now going back to our code and making all the necessary changes, we'd end up with the following code:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ztX3mRJr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fj6c4l6f4pab1pou8i29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ztX3mRJr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fj6c4l6f4pab1pou8i29.png" alt="The improved getCategories function" width="490" height="418"&gt;&lt;/a&gt;&lt;br&gt;
by making a request, we'd get the following result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CvVB8OgV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mn5774xbnsqlr6ondlbz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CvVB8OgV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mn5774xbnsqlr6ondlbz.png" alt="The return from our getCategories function" width="503" height="512"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, it's the exact same result we had with our underperforming code, but using a way better approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;p&gt;There are numerous benefits now that we are free from our N+1 problem, some of them are:&lt;br&gt;
Improved performance: Now that we're no longer running multiple queries, the additional network latency plus the database processing that came with these other queries, will no longer exist.&lt;br&gt;
Reduced network traffic: As mentioned above, we're running fewer queries, therefore, we won't be using as much traffic.&lt;br&gt;
Scalability: By running fewer queries, we won't be overloading our database with multiple requests, so we can achieve more with fewer resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;Hope you people could learn a little more about how to improve the performance of your APPs, both suggestions and corrections are welcome!&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>node</category>
      <category>database</category>
      <category>performance</category>
    </item>
    <item>
      <title>Deploying your NestJS API on AWS Lambda</title>
      <dc:creator>Juan P. Lima</dc:creator>
      <pubDate>Tue, 24 Jan 2023 21:28:34 +0000</pubDate>
      <link>https://dev.to/juanpireslima/deploying-your-nestjs-api-on-aws-lambda-3ka9</link>
      <guid>https://dev.to/juanpireslima/deploying-your-nestjs-api-on-aws-lambda-3ka9</guid>
      <description>&lt;p&gt;If it's your first time dealing with AWS Lambda or if you would like to know a little more about it, you can check out my first article on the AWS Lambda series that will explain to you what AWS Lambda is, how to use, when to use, and when not to; you can find it right here &lt;strong&gt;&lt;a href="https://dev.to/juanpireslima/aws-lambda-what-it-is-how-to-use-when-to-use-and-when-not-to-3fod"&gt;-&amp;gt; Click Me &amp;lt;-&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting your NestJS Project
&lt;/h2&gt;

&lt;p&gt;In this section, I'll start a new NestJS project, if you already have one, feel free to skip this section.&lt;br&gt;
First, we'll need to globally install Nest's cli: &lt;code&gt;npm i -g @nestjs/cli&lt;/code&gt; , then you can generate a new NestJS project using &lt;code&gt;nest new your-project-name&lt;/code&gt;, after doing so, your project will be generated, your folder should look something like this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuy506fpstc2kbe6uuf3k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuy506fpstc2kbe6uuf3k.png" alt="My project's folder after running nest cli command" width="715" height="705"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up serverless framework
&lt;/h2&gt;

&lt;p&gt;Now that you have your NestJS project, let's set up the serverless framework that will help us deploy our API to AWS Lambda, first, you'll need to install the following packages:&lt;br&gt;
&lt;code&gt;npm i @vendia/serverless-express&lt;/code&gt;&lt;br&gt;
&lt;code&gt;npm i -g serverless&lt;/code&gt;&lt;br&gt;
Once it's done, we should create our handler function to handle Lambda's events, I'll create mine on the file lambda.ts I've created on the "src" folder, there we'll start our NestJS-Express server and create a function that will deal with our events:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2545y1facqck1v5f0rmh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2545y1facqck1v5f0rmh.png" alt="Lambda.ts file" width="800" height="751"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, we should create the serverless.yml file that will configure the serverless framework, you should create it on the root directory, there you'll be able to set the function's timeout, memory, region…&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz87zddgi1ucfxyyvgo06.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz87zddgi1ucfxyyvgo06.png" alt="Serverless.yml file" width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying
&lt;/h2&gt;

&lt;p&gt;Before deploying your project to AWS Lambda, you'll need to configure your credentials on serverless, I won't be covering it here, but you can check Serverless' documentation on that here &lt;strong&gt;&lt;a href="https://www.serverless.com/framework/docs/providers/aws/guide/credentials/" rel="noopener noreferrer"&gt;-&amp;gt; Click Me &amp;lt;-&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that it's all set up, you can run serverless deploy , wait a few seconds and your project will have been deployed, you can check it on AWS Lambda's page:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9u9e2d5ztx33ev6lhlm3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9u9e2d5ztx33ev6lhlm3.png" alt="AWS Lambda function list page" width="800" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can click on your function to see more details and test if it's working as expected, you can find the link to do it on configuration-&amp;gt;triggers:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffs4txawq0ijz2l3w8yv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffs4txawq0ijz2l3w8yv.png" alt="My Lambda's function page" width="800" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With that link, you can use your favorite API Client to test if it's working as expected:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2w74g81by5ckncrvk71e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2w74g81by5ckncrvk71e.png" alt="API Client testing my Lambda function" width="800" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, mine is working just fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;As you guys can see, its really simple to deploy your NestJS project to AWS Lambda, this was the third article of my AWS Lambda series, you can check the previous articles on the following links:&lt;br&gt;
&lt;strong&gt;&lt;a href="https://dev.to/juanpireslima/aws-lambda-what-it-is-how-to-use-when-to-use-and-when-not-to-3fod"&gt;-&amp;gt; AWS Lambda: What it is, how to use, when to use, and when not to&amp;lt;-&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;a href="https://dev.to/juanpireslima/deploying-a-nodejs-express-api-to-aws-lambda-hgc"&gt;-&amp;gt; Deploying a NodeJS - Express API to AWS Lambda &amp;lt;-&lt;br&gt;
&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
Github repository with my example &lt;strong&gt;&lt;a href="https://github.com/juanpireslima/nestjs-lambda" rel="noopener noreferrer"&gt;-&amp;gt; Click Me &amp;lt;-&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;NestJS documentation about serverless framework -&lt;strong&gt;&lt;a href="https://docs.nestjs.com/faq/serverless" rel="noopener noreferrer"&gt;&amp;gt; Click Me &amp;lt;-&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>motivation</category>
      <category>learning</category>
    </item>
    <item>
      <title>Deploying a NodeJS - Express API to AWS Lambda</title>
      <dc:creator>Juan P. Lima</dc:creator>
      <pubDate>Thu, 19 Jan 2023 00:14:49 +0000</pubDate>
      <link>https://dev.to/juanpireslima/deploying-a-nodejs-express-api-to-aws-lambda-hgc</link>
      <guid>https://dev.to/juanpireslima/deploying-a-nodejs-express-api-to-aws-lambda-hgc</guid>
      <description>&lt;p&gt;If you don't know what AWS Lambda is or would like to learn a little more about it, I highly recommend that you read the first article of my AWS Lambda series, you can find it right here -&amp;gt; &lt;a href="https://dev.to/juanpireslima/aws-lambda-what-it-is-how-to-use-when-to-use-and-when-not-to-3fod"&gt;&lt;strong&gt;Click me&lt;/strong&gt;&lt;/a&gt; &amp;lt;- On this second article, I'm going to teach you guys how you can deploy your NodeJS-Express API to AWS Lambda.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting your project
&lt;/h2&gt;

&lt;p&gt;In this section, I'm going to start a &lt;strong&gt;new NodeJS-Express project, if you already have one, feel free to jump this section. You can also check the source code on my GitHub that will be at the end of this post.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After creating a folder for your project(name it whatever you like) you can execute &lt;code&gt;npm init -y&lt;/code&gt; to generate your package.json, after doing so, you should install &lt;strong&gt;express&lt;/strong&gt; on your project, you can do it by executing &lt;code&gt;npm install express&lt;/code&gt;, now we can create our first router, controller, and service.&lt;br&gt;
In this example I'll be creating a ping route, controller, and service. Your folder should look something like this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7tmmd05nugx9kdxqct6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7tmmd05nugx9kdxqct6.png" alt="Our project's folder" width="271" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On our ping.services.js we will have our &lt;strong&gt;PingService class&lt;/strong&gt; with a method called &lt;strong&gt;getPing&lt;/strong&gt; that &lt;strong&gt;will return the word "pong":&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3mjoxomck24fhfn89ava.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3mjoxomck24fhfn89ava.png" alt="ping.services file" width="346" height="194"&gt;&lt;/a&gt;&lt;br&gt;
Now on our ping.controller.js, we'll have our &lt;strong&gt;PingController class&lt;/strong&gt; with a method the same name as the service one, and it will call the &lt;strong&gt;PingService's getPing method, returning the http 200 status and its result on a json:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh3n557aboyxglqflk11t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh3n557aboyxglqflk11t.png" alt="ping.controller file" width="525" height="265"&gt;&lt;/a&gt;&lt;br&gt;
Then on our ping.routes, we'll have a &lt;strong&gt;get route&lt;/strong&gt; that &lt;strong&gt;will be handled by our PingController's method getPing&lt;/strong&gt;, your file will look like this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F24a6iup1itns78dw03ld.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F24a6iup1itns78dw03ld.png" alt="ping.routes file" width="525" height="265"&gt;&lt;/a&gt;&lt;br&gt;
And last but not least, we'll set up our index.js on the routes folder, this is what it will look like:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbluy6wttvrqxv6np6uvf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbluy6wttvrqxv6np6uvf.png" alt="routes' folder index.js file" width="525" height="273"&gt;&lt;/a&gt;&lt;br&gt;
Now &lt;strong&gt;we're ready to go to the next step.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up serverless framework
&lt;/h2&gt;

&lt;p&gt;Serverless is the name of the framework that will help us deploy our project to the AWS Lambda, first, you should install "serverless-http" dependency on your project(&lt;code&gt;npm install serverless-http&lt;/code&gt;), then you'll need to globally install serverless framework by typing &lt;code&gt;npm install serverless -g&lt;/code&gt; then you'll need to install a devDependency called "serverless-offline" you can do it with &lt;code&gt;npm install serverless-offline -D&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now we can create our handler function that will handle our HTTP requests, on my project's root directory, I'll create a file called lambda.js, there we'll create our express application and export our handler that will contain our app wrapped to work with AWS Lambda-API Gateway:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxp8n7bsfzkwrwdwob2gb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxp8n7bsfzkwrwdwob2gb.png" alt="lambda.js file" width="800" height="516"&gt;&lt;/a&gt;&lt;br&gt;
Now we'll need to set up our serverless settings, on our root directory, we should create a file named "serverless.yml", there you'll have the runtime your project will be running in, the name of your service, the region your function will be deployed… it will look like this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3r9p3nykga49rczeu7yd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3r9p3nykga49rczeu7yd.png" alt="serverless.yml file" width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, we can now create a script on our package.json so we can check if everything is working as expected:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0al0owiuqnssbs2jojdz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0al0owiuqnssbs2jojdz.png" alt="package.json file" width="542" height="410"&gt;&lt;/a&gt;&lt;br&gt;
You can use nodemon if you like, this function will run our serverless-offline using the settings on our serverless.yml, we'll be running our project the same way lambda will, by running this script, our server will start running and we'll be able to make requests, I've tested mine using Insomnia:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16ub9kqd3hv9y6zjvrir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16ub9kqd3hv9y6zjvrir.png" alt="Project running" width="800" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, mine is working without any issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying to AWS Lambda
&lt;/h2&gt;

&lt;p&gt;Now it's time for us to deploy our project to AWS Lambda, for it, you'll have to configure your credentials on serverless, I won't be covering here how you can do it, but you can found out in this guide: -&amp;gt; &lt;a href="https://www.serverless.com/framework/docs/providers/aws/guide/credentials/" rel="noopener noreferrer"&gt;Click Me&lt;/a&gt; &amp;lt;-&lt;/p&gt;

&lt;p&gt;After doing so, you can run serverless deploy , after doing so, you can see your function on AWS Lambda function list:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnnhb5yprbdk9t98md3rf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnnhb5yprbdk9t98md3rf.png" alt="AWS Lambda function list" width="800" height="116"&gt;&lt;/a&gt;&lt;br&gt;
Serverless framework will have created the function for you with an API-Gateway trigger and with all settings you have set, by clicking on your function, you can see its details, and by going to configuration -&amp;gt; Triggers, you'll find the API-Gateway trigger with your API URL:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqbysj2k41o8fd5o4mcvp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqbysj2k41o8fd5o4mcvp.png" alt="Our Lambda function info" width="800" height="347"&gt;&lt;/a&gt;&lt;br&gt;
You can grab your API endpoint and test it using your favorite API Client, I'll be testing it using Insomnia:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fricrj6m8qawusote0st0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fricrj6m8qawusote0st0.png" alt="Test using API-Gateway endpoint" width="773" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, my API is working just fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;As you can see, it's that easy to deploy your NodeJS-Express API to AWS Lambda, feel free to comment any suggestion or feedback, if you haven't read the first article of the series, you can check it out -&amp;gt; &lt;a href="https://dev.to/juanpireslima/aws-lambda-what-it-is-how-to-use-when-to-use-and-when-not-to-3fod"&gt;here&lt;/a&gt; &amp;lt;-&lt;br&gt;
GitHub repository with our example: &lt;a href="https://github.com/juanpireslima/nodejs-api-lambda" rel="noopener noreferrer"&gt;https://github.com/juanpireslima/nodejs-api-lambda&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wish you all the best.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>career</category>
      <category>productivity</category>
    </item>
    <item>
      <title>AWS Lambda: What it is, how to use, when to use, and when not to</title>
      <dc:creator>Juan P. Lima</dc:creator>
      <pubDate>Tue, 10 Jan 2023 17:04:14 +0000</pubDate>
      <link>https://dev.to/juanpireslima/aws-lambda-what-it-is-how-to-use-when-to-use-and-when-not-to-3fod</link>
      <guid>https://dev.to/juanpireslima/aws-lambda-what-it-is-how-to-use-when-to-use-and-when-not-to-3fod</guid>
      <description>&lt;h2&gt;
  
  
  What is is
&lt;/h2&gt;

&lt;p&gt;AWS Lambda is a serverless, event-driven service that lets you run code without having to manage servers. Similar services includes Microsoft Azure and Google cloud functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages
&lt;/h3&gt;

&lt;p&gt;Some advantages of using AWS Lambda includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pay-as-you-go: On AWS Lambda, you're only charged for the number of requests and the duration of your functions, this means you will only be paying for what you use, more pricing info at &lt;a href="https://aws.amazon.com/lambda/pricing" rel="noopener noreferrer"&gt;https://aws.amazon.com/lambda/pricing&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Auto-scaling: If there's already one request being handled, AWS Lambda will provide separate instances for concurrent requests, by default, your account will have a limit of 1,000 concurrent requests across all Lambda functions in a region, but if you need, you can request a quota increase, more info at &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/lambda-concurrency.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/lambda/latest/dg/lambda-concurrency.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Server-free: You won't have to provide nor manage the infrastructure of your Lambda function, just upload your code as a .zip file or container image and you're good to go&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages and limitations
&lt;/h3&gt;

&lt;p&gt;Lambda's got a lot of advantages, but it's not all roses, let's take a look at some disadvantages and some limitations of it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Server-free: Both an advantage and a disadvantage, why? It's simple if you need to have full control of the environment your code is running, Lambda won't offer you this option&lt;/li&gt;
&lt;li&gt;10 GB Of temporary storage: On Lambda, you'll have up to 10 GB of temporary storage for your code, in most cases, it's going to be enough, but in some cases, you might need more(Large files like videos…).&lt;/li&gt;
&lt;li&gt;15-minute limit timeout: 15 minutes is the maximum timeout you can set on your Lambda function, again, this will fit most functions, but for some, it may not be enough.&lt;/li&gt;
&lt;li&gt;Deployment package limit of 250MB for unzipped and 50MB for zipped packages, this makes AWS Lambda not a good fit for big applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to use it
&lt;/h2&gt;

&lt;p&gt;After creating your AWS Account(I won't cover this process here), you can access the Lambda service, the first thing you're going to see is the following page:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk54q4hjnv3a1fdmjgjl6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk54q4hjnv3a1fdmjgjl6.png" alt="AWS Lambda service page" width="800" height="389"&gt;&lt;/a&gt;&lt;br&gt;
There you'll have some examples with different technologies: .NET, Node.js, Go… looking at those examples, you'll realize it's pretty simple to set up your first Lambda function, to do so, let's click to create a function, after doing so, you'll see this screen:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa4roksj06twfesh8keex.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa4roksj06twfesh8keex.png" alt="AWS Lambda creation page" width="800" height="389"&gt;&lt;/a&gt;&lt;br&gt;
There, you'll be able to start your function with a simple hello world, use a blueprint or select a container image; then you'll have some more settings, like the name of your function, the runtime of your function… lets create our hello world example. &lt;br&gt;
After creating your first function, you'll be redirected to it, and have the following view:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwirrjygdgdtir8ub5hdt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwirrjygdgdtir8ub5hdt.png" alt="AWS Lambda function page" width="800" height="391"&gt;&lt;/a&gt;&lt;br&gt;
there you'll see that it was generated a handler function for us, and that's the function Lambda will always execute, so you always gotta have a handler to be executed, that's how you'll handle your requests. Your function may deal with HTTP requests, WebSocket connections/messages… but we won't be covering this here. &lt;br&gt;
As you can see on the right-side, you can upload your code from a .zip file or from a S3 location, you can even code on the "Code source" section, make it your playground to discover what you can do with Lambda.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use it, and when not to
&lt;/h2&gt;

&lt;p&gt;Lambda is a great alternative if you don't need to have fully control of the environment your code is running and if your use respects Lambda's limitations, it will help you deploy faster and your code will be auto-scaling, thus not having to worry much about scaling it, also, you'll only pay what you use, and most times it's a really great deal.&lt;/p&gt;

&lt;p&gt;When your project start getting bigger, Lambda may not be the best choice, that's because you might need more control over the environment your code is running or the running period might be so long, that would be worth it to go for an EC2 or else, you could still use Lambda for your micro-services though.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;There's a lot of advantages and disadvantages of using AWS Lambda, it may or may not fit for your project, but I suggest you giving it a try nevertheless.&lt;br&gt;
You can create some small projects to see what Lambda is capable of, after all, there's a free tier so you won't be charged for some small tests.&lt;br&gt;
I hope I could bring you some insights on how you can use Lambda functions on your projects and the potential of it, and, hopefully, some of you may walk your first step towards using Lambda functions.&lt;/p&gt;

</description>
      <category>community</category>
      <category>discuss</category>
      <category>firstpost</category>
    </item>
    <item>
      <title>Why computer floating points are inaccurate</title>
      <dc:creator>Juan P. Lima</dc:creator>
      <pubDate>Tue, 05 Apr 2022 02:12:50 +0000</pubDate>
      <link>https://dev.to/juanpireslima/why-computer-floating-points-are-inaccurate-3281</link>
      <guid>https://dev.to/juanpireslima/why-computer-floating-points-are-inaccurate-3281</guid>
      <description>&lt;p&gt;Some days ago I went through a curious situation, I had a simple function that would turn money into cents, It was working properly until this happened: &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M-MQzAVf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2g87wkb18lkvwno469jt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M-MQzAVf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2g87wkb18lkvwno469jt.png" alt="Image description" width="402" height="33"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;18.17&lt;/strong&gt; was the float being sent to the function, the function was basically floatNumber x 100 and I had no idea why every number I tested was working just fine but this one was not, I tested it on my browser and the same thing happened, I had to find a way how to make it work… &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0o7-jPXx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83gn0k7tioomedgin29c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0o7-jPXx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83gn0k7tioomedgin29c.png" alt="Image description" width="155" height="39"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  It happens in almost every programming language
&lt;/h2&gt;

&lt;p&gt;So, after some research, I discovered the 0.1 + 0.2 problem and why in most programming languages 0.1 + 0.2 != 0.3(yes, you read it right), take a look at some of these examples:&lt;br&gt;
&lt;strong&gt;JS:&lt;/strong&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9IaKdAyP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjyp4oenpj568bbram9i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9IaKdAyP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjyp4oenpj568bbram9i.png" alt="Image description" width="222" height="42"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Java:&lt;/strong&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CHKd-J5C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czdcj06enotnlf7s3eyu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CHKd-J5C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czdcj06enotnlf7s3eyu.png" alt="Image description" width="800" height="104"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Dart:&lt;/strong&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---4UTyble--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zjpnubh3fcknx26jvwb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---4UTyble--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zjpnubh3fcknx26jvwb.png" alt="Image description" width="800" height="133"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, in these languages 0.1 + 0.2 != 0.3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does this happen?
&lt;/h2&gt;

&lt;p&gt;Double-precision floating-point format, also known as binary64(&lt;a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format"&gt;https://en.wikipedia.org/wiki/Double-precision_floating-point_format&lt;/a&gt;), is a computer number format most of our processors follow, it stores our number in bits this way:&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y6VbY4KO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqxi4gffdwvat6alnh1i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y6VbY4KO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqxi4gffdwvat6alnh1i.png" alt="Image description" width="608" height="119"&gt;&lt;/a&gt;&lt;br&gt;
Having 64 bits, 1bit is for the sign so we know if the number is positive or negative, 11bits are the exponent(&lt;a href="https://en.wikipedia.org/wiki/Exponentiation"&gt;https://en.wikipedia.org/wiki/Exponentiation&lt;/a&gt;) that will tell us if our mantissa represents an integer or a fraction, and 52bits for the mantissa(&lt;a href="https://en.wikipedia.org/wiki/Significand"&gt;https://en.wikipedia.org/wiki/Significand&lt;/a&gt;) that gives us from 15 to 17 decimal digits precision, &lt;strong&gt;the problem is:&lt;/strong&gt; some numbers just can’t be fully represented exactly in this way, only approximately. &lt;/p&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;My solution:&lt;/strong&gt; The solution for my problem, converting money into cents was the following:&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5zU1NJfo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7a6f2onugw3zomy40o99.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5zU1NJfo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7a6f2onugw3zomy40o99.png" alt="Image description" width="138" height="47"&gt;&lt;/a&gt;&lt;br&gt;
All I needed was to move the decimal points 2x to the right, and I did so by using the &lt;strong&gt;e notation&lt;/strong&gt;(&lt;a href="https://en.wikipedia.org/wiki/Scientific_notation#E_notation"&gt;https://en.wikipedia.org/wiki/Scientific_notation#E_notation&lt;/a&gt;) which represents 10 to the power of the number that comes next, in my case, 2. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final thoughts&lt;/strong&gt;&lt;br&gt;
I brought only one solution, but there are more solutions out there that will fit better what you want to do, so go ahead, find out more solutions, and don’t forget to come back here and comment the solution you’ve found so more people will benefit from this article, wish you all the best.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read more
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html"&gt;https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format"&gt;https://en.wikipedia.org/wiki/Double-precision_floating-point_format&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>computerscience</category>
      <category>todayilearned</category>
    </item>
  </channel>
</rss>
