<?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 Brian Lego on Medium]]></title>
        <description><![CDATA[Stories by Brian Lego on Medium]]></description>
        <link>https://medium.com/@legobw?source=rss-168f01422e83------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*apshQOUgBQgeTbs4TXpvuQ.jpeg</url>
            <title>Stories by Brian Lego on Medium</title>
            <link>https://medium.com/@legobw?source=rss-168f01422e83------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:02:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@legobw/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[Authentication in Node.js]]></title>
            <link>https://javascript.plainenglish.io/authentication-in-node-js-part-3-8604a09b2ca4?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/8604a09b2ca4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Sun, 31 Jan 2021 22:53:47 GMT</pubDate>
            <atom:updated>2021-02-01T15:03:31.598Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 3</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*oG7SeOjjbbTyIhosD02vkQ.png" /></figure><p>In the final part of my Authentication in Node series I’m going to add three last pieces of functionality to my backend Node server.</p><p>First will be what I’m calling a ‘grab user’ function, which essential will run every time the frontend gets reloaded, refreshed or redirected to take the stored token cookie and make sure that it’s still valid.</p><p>The second will be the main ‘is-auth’ function that will authenticate the user on every other route/request that requires a user to be logged in to access the db, request data, etc. And lastly will be a simple ‘logout’ function to delete the cookie stored on the client browser.</p><p>I’m going to jump just straight back in so if you need to revisit the previous code written it can be all be found in <a href="https://medium.com/javascript-in-plain-english/auth-in-node-js-http-cookies-jwt-bcrypt-part-1-64b3c0159035">Part One</a> &amp; <a href="https://medium.com/javascript-in-plain-english/authentication-in-node-js-adding-validation-part-2-bb3fbbaa7494">Part Two</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jO3SlsJwjlvFYqcDB1dAEA.png" /></figure><p>Above we have our User controller and User routes files with the other main functions already written and folded up, but this is where we will begin out grabUser functionality, beginning by defining the route as ‘/grabuser’ which can be used on our frontend and then sending it to the appropriate controller method. For the purposes of this demo this method would run ‘top level’ on ‘load’ of the application every time to fetch user data and send back anything that would need to be saved or stored in state on the client side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*w0v8sa0kck_DaPpZH3APvw.png" /></figure><p>First thing we do within our grabUser function is check for the token that may or may not be there. If we get an error from the checking for the token we know that no one is signed in and so send back that message.</p><p>Next if there is a token we attempt to decode it, if for whatever reason that fails (ie token expired, etc.) we send back a message communicating that as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*jsczFIRZ6kmzmdlyVgIcxQ.png" /></figure><p>Finally, if we make it through both of those checks without error, we take our decoded token and fetch our user from the database. We then send back any relevant user data associated with that user that may need to be stored within state of the application that would have been lost on reload/redirect. This allows for a fairly user-friendly experience too keep a logged in user from having to re-login every redirect or refresh of a page.</p><p>Next I’m going to add a middleware folder with a single file to check authentication on every potential route that would require a user to be signed in. To make use of this we would then require it in all of our other route files and pass it in as an argument before sending it to the relevant controller.</p><p>For example if this was a shop application and there were a route to look at a user’s shopping cart the route function may look something like this:</p><pre>const express = require(&#39;express&#39;)<br>const Shop = require(&#39;..models/shop&#39;)<br>const router = express.Router();<br>const shopController = require(&#39;../controllers/shop_controller&#39;)</pre><pre><strong>const auth = require(&#39;../middleware/auth&#39;)</strong></pre><pre><strong>router.get(&#39;/shoppingcart&#39;, auth, shopController.getShoppingCart)</strong></pre><pre>module.exports = router</pre><p>The two import pieces here are the auth function were requiring, and how we then pass it as a second argument to the get function of the ‘/shoppingcart’ route. So let’s go ahead and write this auth function which would run before the request gets passed to the shop_controller.getShoppingCart function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*LzGBacJQGmZDH91nk4YSqA.png" /></figure><p>We start off by doing essentially exactly what we do in our grabUser function that we just wrote. We take our token, if there isn’t one we throw an error, then we decode it. If it doesn’t pass we also throw an error. If it does pass we set our userId from the decoded token onto our request object and call the next() function. This allows us to access the req.userId in whatever controller function it then gets passed to. So if we need this user we simply have to call User.findById(req.userId) to access our current user.</p><p>With this we now have the ability to authenticate any route within our application, make sure a user is logged in, and then access that user data.</p><p>For our last function we’ll go back to our user_controller and user_routes to add a ‘log out’ function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DYo_WIHAUUerC2BVw4NKOA.png" /></figure><p>Starting off by again just defining the appropriate function within the routes file and then connecting it to its corresponding function within the controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*ebrAq4PUKHYXvccufSz3hA.png" /></figure><p>This one is the most simple execution of the three. Set the status to 200, use the ClearCookie to delete the cookie based on the name passed as an argument and then send back a message to communicate to the front end that the user has been logged out and cookie has been deleted. Done, and done.</p><p>And there you have it. For a basic personal project using HTTP cookies, BCrypt, JasonWebTokens, &amp; Validation we’ve been able to implement a fairly simply authentication process. We’ve been able to log in users, create users, check for a current user, log out users, and validate every subsequent request to a specific user. As always I will link any relevant docs for further reading or questions you may encounter along your own personal authentication process.</p><p><em>[1]: HTTP cookie Docs(</em><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies">https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies</a>)</p><p><em>[2]: JWT Docs (</em><a href="https://www.npmjs.com/package/jsonwebtoken">https://www.npmjs.com/package/jsonwebtoken</a>)</p><p><em>[3]: Bcrypt Docs (</em><a href="https://www.npmjs.com/package/bcrypt">https://www.npmjs.com/package/bcrypt</a><em>)</em></p><p><em>[4]: Express Validator Docs(</em><a href="https://express-validator.github.io/docs/">https://express-validator.github.io/docs/</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8604a09b2ca4" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/authentication-in-node-js-part-3-8604a09b2ca4">Authentication in Node.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication in Node.js]]></title>
            <link>https://javascript.plainenglish.io/authentication-in-node-js-adding-validation-part-2-bb3fbbaa7494?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb3fbbaa7494</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Mon, 25 Jan 2021 01:12:51 GMT</pubDate>
            <atom:updated>2021-01-25T14:09:42.388Z</atom:updated>
            <content:encoded><![CDATA[<h4>Adding Validation (Part 2)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*oG7SeOjjbbTyIhosD02vkQ.png" /></figure><p>This is a continuation on the piece I wrote about adding Authentication into a Node project using HTTP cookies, BCrypt and JWT tokens. Previously, I had set up my application to accept an incoming request where a user was signing up. I then took that info, hashed the password, saved the input data in my database and then returned a signed token which would be stored on the client side as an HTTP cookie. If you’d like to revisit those steps they can be found <a href="https://medium.com/javascript-in-plain-english/auth-in-node-js-http-cookies-jwt-bcrypt-part-1-64b3c0159035">here</a>, otherwise let’s start with a ‘login’ route and add some validation to our backend application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yxmKh8O19Np87gcUnCJ4iQ.png" /></figure><p>Currently this is what the Routes and User Controller files look like. Next let’s add login functionality. I’ll begin by adding some validation, which we will use within the route and controller file, thanks to the help of another piece of middleware.</p><pre>npm install --save express-validator</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agl8kNdzuPI96kDSf1rGWA.png" /></figure><p>We start by requiring the express-validator package and specifically it’s {body} method which we will use (I will link to the docs for express-validator at the bottom for more info on its functionality). We will also need access to our User model in the database so I’ve required that as well. Next, I define the ‘/login’ route that will come from our frontend &amp; as a second argument pass it an empty array. This is where our validation will go. Finally I pass it the third argument of the exported function from our controller, which is where it will head after going through the validations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*l5aWL9x_1lWxv3sEd7-a6Q.png" /></figure><p>To start, within our array of validations we call body and specify what from our request body we want to validate, in our case, ‘email’. There are TONS of validations you can use and specify, which I again invite you to look further into but I call just a few simple ones here by chaining them together. .isEmail() will check if it’s a valid email format (blah@blah.com). If that fails I give it a custom failure error message using .withMessage() . Next, I define a custom validation where I call to the database and attempt to find the User based on the email that’s within the body. If that foundUser is false then I return a rejected Promise with a message explaining just that. If a User is found then I go ahead and move forward and validate the password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*IvD6e14SvFmI3JDAk2Ap4A.png" /></figure><p>I start by calling body once again and checking against ‘password’ this time. I use a standard .notEmpty() just to make sure there is a password and then afterwards call a .custom() async validation which is where I will check the password is correct.</p><p>I once again grab my User from the DB. Then, using the bcrypt .compare() method I check the saved password for that user vs. the password given within the req.body. Compare() returns a boolean and based off that I make my final validation. If it fails I again return a rejected Promise.</p><p>The validations that fail, and their messages, would then be passed to the userController.login function where we can use them to create a response &amp; send back to the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*Q8Ir1ucU5kR05eLwXA04Xw.png" /></figure><p>We first begin by requiring another method from express-validator, {validationResult} .</p><p>This is allows us to call validationResult on the req that came in and returns a Result object with the validation errors available. If there are any errors at all we create a new Error, set the statusCode to 422, convert it to an array &amp; then throw it to our catch block which will send it back to the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*xANVCAxFEk9jLN7OrWx88Q.png" /></figure><p>Now with our validation and error handling out of the way we can go ahead and work towards sending back a new signed token which will authenticate that the User has signed in.</p><p>We go about creating the token the exact same way as before. Using jwt.sign() to create the token and sending back within it the email &amp; userId of the logged in User. We also include our ‘privateKey’ and some customization ensuring that the token only lasts for 2 hours. As I said in my last article, there are quite a few more customizations you can include and I would encourage you to look into.</p><p>Now with the token finally made all the stands is to send it back to the client as an HTTP cookie and your user is officially ‘logged in’ after going through some validations. If the validations failed the client will otherwise receive an array of errors, which you can use to inform the user why and how the validations failed. Ultimately your final user Routes and Controller should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErlIXDtV-atV2YXF_0vGUg.png" /></figure><p>With that done we can now successfully ‘login’. As I mentioned before this implementation is purely to get an application started. This can all be abstracted away into separate Auth files to make your application more reusable and scalable. Which is something I will actually begin to do in my third and final post about Auth in Node. I’ll go ahead and make a separate file which will be an authentication ‘check’. To be used for every route within the backend that requires a user to already be ‘logged in’ to access.</p><p><em>[1]: Express Validator Docs(</em><a href="https://express-validator.github.io/docs/">https://express-validator.github.io/docs/</a>)</p><p><em>[2]: JWT Docs (</em><a href="https://www.npmjs.com/package/jsonwebtoken">https://www.npmjs.com/package/jsonwebtoken</a>)</p><p><em>[3]: Bcrypt Docs (</em><a href="https://www.npmjs.com/package/bcrypt">https://www.npmjs.com/package/bcrypt</a><em>)</em></p><p><em>[4]: HTTP cookie Docs(</em><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies">https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb3fbbaa7494" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/authentication-in-node-js-adding-validation-part-2-bb3fbbaa7494">Authentication in Node.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication in Node.js, with HTTP Cookies, JWT & BCrypt]]></title>
            <link>https://javascript.plainenglish.io/auth-in-node-js-http-cookies-jwt-bcrypt-part-1-64b3c0159035?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/64b3c0159035</guid>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Sun, 17 Jan 2021 22:43:29 GMT</pubDate>
            <atom:updated>2021-01-24T14:21:03.086Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1</h4><blockquote>So, you’ve decided to finally broach the topic of authentication within your Node application. Come to find out there are of course a ton of ways to implement Auth within Node, so where do you start? First choice is to decide whether you want to just let a third party service handle it for you, or whether you’re brave enough to carry through and implement it on your own! If the second choice is for you, well then you’ve come to right place. I’m going to walk you through one (of many) methods you can use to implement Auth in your Node project using JsonWebTokens, BCrypt and HTTP Cookies.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*fHCalZHXSVLYARTikN0QDw.png" /></figure><p>First things first, why use JsonWebTokens, BCrypt, and Cookies?</p><p>Great question, starting with what are JWT’s and why use them? To quote from their <a href="https://jwt.io/introduction/">documentation</a>: <em>“A JSON Web Token (JWT) is an open standard (</em><a href="https://tools.ietf.org/html/rfc7519"><em>RFC 7519</em></a><em>) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object.” </em>If you’re creating a Node application you’re more than likely very familiar with JSON. So essentially a JWT exactly what the name implies, a compact token used to transmit data between parties, written in JSON. Implementation of using JWTs within a Node App is quite easy as well. A simple:</p><pre>npm install --save jsonwebtoken</pre><p>will include it as a dependency and we can therefore call on the module when needed through the application.</p><p>Next we have BCrypt, the most straightforward to explain, is simply a middleware for hashing passwords. There are of course many others but BCrypt is widely used, easy to install and has great <a href="https://www.npmjs.com/package/bcrypt">documentation</a>, which is everything you need to get started so let’s include that into the project as well:</p><pre>npm install --save bcryptjs</pre><p>Finally we have our Cookies, which if you’ve been using the web in the last 5 to 10 years you have no doubt heard of before. This is where we’ll be storing the JWT on the client side, and therefore be able to send back to the server upon every request. There are of course other options to the question of where to store this info. Local Storage? Session Storage? Cookies? Rather than go into all in’s and out’s between them, I’ll just <a href="https://bitsofco.de/an-overview-of-client-side-storage/">link this article</a> if you’re interested to learn more about the pro’s and con’s of all the different client side storage options available. Suffice to say, cookies are an easy to use/implement solution that can store our user’s JWT and is secure enough for simple auth. So one last package install before we can dive in a start implementing them within our code:</p><pre>npm install --save cookie-parser</pre><p>For this walk through we’ll be creating the auth for a backend, RESTful API using Express. To start, I’ve written out our <em>User </em>files that we’ll need following a MVC architecture (minus the Views, it being an API our response will be JSON data rather than an HTML page) and installed the other middleware we will need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uGCPhzjGW-9S1kRid-9OEw.png" /><figcaption>Initial User files</figcaption></figure><p>With all of this initial setup out of the way we can start to implement some Authentication within our app. First we’ll start in our routes file, so specify some end points, beginning with creating a User.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*9UjAeR7wCh2Idtu69W96fQ.png" /><figcaption>Setting up endpoint for User Signup route</figcaption></figure><p>First we’ll bring in and require our <em>user_controller.js</em>. Then we’ll define our first endpoint with just a simple ‘/signup’ which will ultimately be http://localhost:8000/signup</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*wXf0EGHLYHI4VXE_QQR7SA.png" /><figcaption>User Controller w/signup method using Bcrypt</figcaption></figure><p>With that done now we’ll go to the user controller file which is where most of our auth code will be. Starting with exporting our signup method that we’re calling in our route file. Within this demo I’ve written the method’s using ES6 async/await keywords but this can also be done using Promise chains. The docs for JWT &amp; Bcrypt both explain if you were to use promise chains instead.</p><p>We start by hashing our incoming password from the req.body using hashSync (which is asynchronous and blocking) and then creating/saving our new user as defined in our mongoose schema.</p><p>Something to note here, is that I have omitted any validation or serious error handling, which you would undoubtably have. Within this article I will only be walking through the implementation of ‘signup’ but with Parts 2 &amp; 3 I will end up adding validation to incoming req to check against email and password ‘uniqueness’, ‘format’, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*inux2trgADkvsS4je5xlIg.png" /><figcaption>User Controller creating JWT</figcaption></figure><p>Next we create our token using our jwt middleware. The .sign()method takes three parameters. The first being what you want the actual token to be, in this instance I’ll just be sending back to the client their email, and their userId which mongoose created.</p><p>The second parameter is a secretOrPrivateKey which can either be a string or an object but will ultimately be used within their algorithm to encode &amp; decode the token. We’ll be using this later when we decode the token. You can of course specify which algorithm you’d like to use, and for me info on that just check out their <a href="https://www.npmjs.com/package/jsonwebtoken#usage">docs</a>.</p><p>Lastly, you can pass it either options or a callback. We opt for the options, and while JWT gives you may customizations I’ve only opted for an expiration to help with security. All of their other optimizations are listed in their docs, see link from above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*QBbPmt9_5_3_CY-6GCiooQ.png" /><figcaption>User Controller creating and sending cookie</figcaption></figure><p>Finally we then create our cookie. The first argument is what want to call our cookie, I opt for a classic “token”.</p><p>The second argument is payload, in this case our new created token.</p><p>The third argument is our options. Just like JWT there are many different optimizations you can give your cookie, but I simply set it to httpOnly: true. Being set as an HTTP only cookie on the client, the cookie itself can not be altered on the client side make it slightly more secure.</p><p>Finally we send the cookie back with a JSON object that simply has a message but you could include anything you want, often times it would be some more details on the created user.</p><p>And there you have it! Your backend Node API is set up to create a new User and send back a cookie containing information about that User which will then be sent with every request from the client.</p><p>One important thing to note on your front-end application. Within development you most likely will running both your back-end server and your front-end server on two separate ports. By making your cookies secure and httpOnly they must be sent and received from the same domain. This means you will most likely need to use a proxy, at least during development, on your front end set to http://localhost:8000 which is what our node application is currently listening on. If you’re front-end application is a React app, as mine usually are, it’s a simple as adding “proxy”: “http://localhost:8000&quot; to your package.json file, and then adjusting your fetch() calls by removing the entire url and leaving only the relative endpoint. For example fetch(‘/signup’).then(resp=&gt;resp.json()).then() etc. The proxy will be used in all HTTP request your front-end sends.</p><p>In my next blog post I will go over how to handle receiving a request with that cookie, decoding it’s token and therefore verifying that the user exists allowing use to other endpoints &amp; functions within your back-end. I will also go ahead and add two more endpoint to our backend API, allowing our user to ‘login’ and ‘log out’.</p><p>If you’d like to read more about BCrypt, JSON Web Token, or Cookies I’ve linked some more documentation below.</p><p><em>[1]: HTTP cookie Docs(</em><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies">https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies</a>)</p><p><em>[2]: JWT Docs (</em><a href="https://www.npmjs.com/package/jsonwebtoken">https://www.npmjs.com/package/jsonwebtoken</a>)</p><p><em>[3]: Bcrypt Docs (</em><a href="https://www.npmjs.com/package/bcrypt">https://www.npmjs.com/package/bcrypt</a><em>)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64b3c0159035" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/auth-in-node-js-http-cookies-jwt-bcrypt-part-1-64b3c0159035">Authentication in Node.js, with HTTP Cookies, JWT &amp; BCrypt</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Refactoring Promise Chains w/Async-Await]]></title>
            <link>https://javascript.plainenglish.io/refactoring-promise-chains-w-async-await-d126c7fac3a8?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/d126c7fac3a8</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[refactoring]]></category>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Sun, 10 Jan 2021 19:37:18 GMT</pubDate>
            <atom:updated>2021-01-12T08:44:16.235Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>In my never ending journey of refactoring and refining my code my most recent endeavor has been in writing cleaner and easier to read code with the help of async-await</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*UlZuyMISHKZIgp0psATqxw.jpeg" /></figure><p>Up until recently I had only used JavaScript &amp; Promises primarily within the context of writing React code. As far as asynchronous code and Promises go, the only use-cases I had for them were in writing fetch() calls to an API. It would usually look something like this:</p><pre>function getUsers(){<br>   fetch(&#39;https://some-url-here.com/&#39;)<br>   .then(resp =&gt; resp.json()<br>   .then(data =&gt; someFunctionToUseReturnedData(data))<br>   .catch(err =&gt; console.log(err))<br>}</pre><p>Anyone familiar with the code above knows that JavaScript’s fetch API makes use of Promises&amp; by chaining subsequent Promises together you achieve asynchronous functionality. Calling fetch() returns a Promise, as does any subsequent .then() or .catch() call, which then each have to handled. The ‘lifecycle’ of a Promise is show below for reference if you need a quick refresher:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*0mBlni5vsYZE2wFzfVv8EA.png" /><figcaption>Promise lifecycle</figcaption></figure><p>A simple API call like this is easy to read and understand however once your logic and use-cases grow in complexity the ‘readability’ factor can easily get away from you. This became exactly the case once I started working with Node/Express/MongoDB as a stack for my backend API. Dealing with complex collections and documents within MongoDB and handling their associations, chaining Promises within controller functions often times quickly grew confusing and unreadable.</p><p>So I resolved to finally make use of theasync-await keywords and refactor all of my existing code to read more synchronously. Let’s start with that simple API fetch call above and then I’ll go into some greater detail and another use-case.</p><p>First off every function has to be declared to be asynchronous right off the bat:</p><pre><strong><em>async</em></strong> function getUsers(){<br>   ...<br>}</pre><p>This declares that zero or more asynchronous await expressions will happen within the context of the function. Next, to make use of error handling we won’t be using .catch() anymore so we instead are able to wrap our function’s inner code in a try/catch block.</p><pre><strong><em>async</em></strong> function getUsers(){<br>   try{<br>       ...<br>   } catch(error){<br>       console.log(error)<br>   } <br>}</pre><p>Next, we can finally refactor the .then() block of our Promise chain by using the await keyword. The biggest thing to understand here is that the await keyword is blocking. It blocks the execution of the rest of the code until the Promise-based functionality that is happening ‘behind the scenes’ is completed. So keeping that in mind, definitely be weary of how many await keywords you use within an asynchronous function. More often then not only when the returned result of an await expression depends on the one before should using multiple awaits be necessary. Usually, if you have many awaits within one async function this can be abstracted into smaller async functions which could potentially run parallel to each other, therefore speeding up your code execution.</p><p>Now for the final change in our small code:</p><pre><strong><em>async</em></strong> function getUsers(){<br>   try{<br>       const resp = <strong><em>await</em></strong> fetch(&#39;https://some-url-here.com/&#39;);<br>       const data = <strong><em>await</em></strong> resp.json();<br>       someFunctionToUseReturnedData(data);<br>   } catch(error){<br>       console.log(error)<br>   } <br>}</pre><p>We now have the exact same functionality as we did before but written without chaining Promises and in a more succinct, synchronous way that can be easier for people not familiar with your code could understand.</p><p>Just to show a quick example of how this can be utilized in a backend Node.js environment as well, I’ll include an example of a Promise chain (req/res) &amp; then a refactored version using the async-await keywords</p><pre>const Post = require(&#39;../models/post&#39;)<br>const express = require(&#39;express&#39;)<br>const router = express.Router();</pre><pre>...</pre><pre>router.get(&#39;/post/:id&#39;, (req, res, next) =&gt; {  <br>   Post.findById(req.params.id)   <br>      .then(post =&gt; {    <br>         if (!post){    <br>            const error = new Error(&#39;Could not find post&#39;);        <br>            error.statusCode = 404;  <br>            throw error;   <br>         } else {    <br>            res.status(200).json({      <br>               post: post    <br>            });   <br>         }  <br>      });   <br>      .catch(error =&gt; {   <br>         if (!error.statusCode){     <br>            error.statusCode = 500;   <br>         }    <br>         next(error);  <br>      })<br>})</pre><p>Here we have a Promise chain to fetch a post from a database and to either send back the post in json format or to send back an error describing either that the post couldn’t be found, or that there was a server error. Now lets go ahead and rewrite it using the async-await keywords</p><pre>router.get(&#39;/post/:id&#39;, <strong><em>async</em></strong> (req, res, next) =&gt; {<br>   try {<br>      const post = <strong><em>await</em></strong> Post.findById(req.params.id)<br>      if (!post){<br>         const err = new Error(&#39;Could not find post&#39;);<br>         err.statusCode = 404;<br>         throw err;<br>      } else {<br>         res.status(200).json({<br>            post: post<br>         }) <br>      }<br>   } catch (error) {<br>      if (!error.statusCode) error.statusCode = 500;<br>      next(error);<br>   }<br>})</pre><p>The code behaves the same as it did before but without the Promise chaining and by utilizing async-await it becomes more readable. The simple await expression makes for more synchronous written code.</p><p>Refactoring away from Promise chaining helps with readability especially when working on a large and growing application. If you’d like to do more research on async-await, Promises or the Fetch API, below are links to documentation.</p><p><em>[1]: async Function Docs(</em><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function</a>)</p><p><em>[2]: Promise Docs (</em><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise</a>)</p><p><em>[3]: Fetch API Docs (</em><a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d126c7fac3a8" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/refactoring-promise-chains-w-async-await-d126c7fac3a8">Refactoring Promise Chains w/Async-Await</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux Toolkit (Immer & Thunk)]]></title>
            <link>https://javascript.plainenglish.io/redux-toolkit-immer-thunk-5bcac23968d7?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bcac23968d7</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[redux-toolkit]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Sat, 02 Jan 2021 20:34:03 GMT</pubDate>
            <atom:updated>2021-01-02T22:35:15.457Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKO94vMhCG3pn0dQiBBbSA.jpeg" /></figure><blockquote>In my last post I did a short walk through of refactoring existing Redux code to utilize the Redux Toolkit and React-Redux Hooks. That article can be found (<a href="https://medium.com/javascript-in-plain-english/refactoring-existing-redux-w-redux-toolkit-hooks-550a628d74a9">here</a>) and seeing as I will be adding on to the demo started there it may be a good place to start. Now, two additional bits of Redux Toolkit functionality I wanted to touch on deal with directly mutating state within our slice (thanks to Immer) and then also making asynchronous HTTP calls (thanks to Thunk). So stick around and I’ll walk you through the process of adding these functionalities to our previous demo.</blockquote><p>Let’s start with just a quick look at our previous code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XbCOKaqPaZcrUsZZwR7CAw.png" /><figcaption>Store (left), Slice(center), App Component(right)</figcaption></figure><p>We have our basic store setup, our Slice with some simple state that our App Component is subscribed to and a dispatch method that will increase the ‘itemCount’ within our state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*h90YmTugnM4SLwe-8W6C0Q.png" /><figcaption>Adding &lt;form&gt; to App.js</figcaption></figure><p>Let’s dive straight in with some changes to our App component. I’ll start off by now incorporating actual item objects into our application. It will have a simple form that our users will fill out to create a new item and add it to their cart. Leaving the onSubmit blank, we’ll come back to it in a moment once we’ve written our dispatch method that will add it to our state within Redux. Next we need to go to our storeSlice.</p><p>Seeing as we’ll be working with an array of actual items, our itemCount becomes a redundant so we will just go ahead and swap it for an array we’ll call items. Therefore we can also get ride of the increaseCount() we had within our reducers and our exported selectItemCount as well. We’re going to replace all of these with functionality for an array, which our App component will then subscribe to and be able to determine the item count from the length of the array. The refactor should result in a storeSlice that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*kFCqSGUSfMSdZDQ36pG0Kg.png" /><figcaption>Refactored storeSlice for items: []</figcaption></figure><p>So with these new changes, we have set up our Slice to utilize Immer. Previously in Redux, best practices stated that changes to state had to be made without directly mutating state, ie creating a copy of the current state, manipulating that copy and then reassigning to state to your mutated copy. Immer does all of this behind the scenes for you. Their docs describe it like this:</p><blockquote>“The basic idea is that you will apply all your changes to a temporary <em>draftState</em>, which is a proxy of the <em>currentState</em>. Once all your mutations are completed, Immer will produce the <em>nextState</em> based on the mutations to the draft state. This means that you can interact with your data by simply modifying it while keeping all the benefits of immutable data.”</blockquote><blockquote>“Using Immer is like having a personal assistant; he takes a letter (the current state) and gives you a copy (draft) to jot changes onto. Once you are done, the assistant will take your draft and produce the real immutable, final letter for you (the next state).”</blockquote><p>What it means for us is a super simple way to work with and mutate our Redux state. We can directly push into the ‘items’ array and let Immer do a bunch of work behind the scenes for us. With this done we’ll go ahead and make some more changes to our App Component which can now reflect our changed Slice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*5VrnBCyAaEZtZpC_m1ii1g.png" /><figcaption>Refactored App component</figcaption></figure><p>We start off fixing our imports from the storeSlice to addItem(our dispatch method) and selectItem(our piece of state that we are subscribed to). We now simply add a submit handler for our form which will send our user created item to our Redux store. There Immer will take care of mutating our state appropriately and once the item is added to our items array it will be reflected in our items count show on line 26. This is but a small example of how we can mutate and change state within our Redux Toolkit with the help of Immer.</p><p>Next lets go back to our storeSlice where we can implement a GET request to a dummy API which would theoretically populate our items array on initial load of our application. This can all be done right within our storeSlice using the Thunk middleware built into Redux Toolkit to make asynchronous calls to an outside source(usually a database). There are of course other middleware options you could use for making asynchronous calls but Thunk comes ‘out-of-the-box’ with Redux Toolkit and with it’s ease-of-use, it’s a great place to start for writing async calls within Redux.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*szrxYrlU28BsUUomQZdviQ.png" /><figcaption>storeSlice.js w/Async Fetch Call</figcaption></figure><p>So, within our storeSlice we add two things, first a ‘fetchAll’ reducer action that will set our items array to whatever is returned from the fetch call. For the purposes of this demo we are assuming that our fetch call will just return an array of items from our DB. Second we add the actual fetch call ‘itemsFetch’ which we pass in our dispatch, and with the help of Thunk behind the scenes, makes an asynchronous call for us. We then of course parse our returned data and subsequently call our fetchAll() reducer method to assign our items array with the data we just received.</p><p>Fairly simple and a lot cleaner than previously writing Redux async calls and corresponding reducer methods. Now we simply need to use or itemsFetch method within our App component utilizing the useEffect hook and were all set up to make an initial async fetch call (using Thunk), through our Redux Toolkit which can directly mutate state (using Immer). Simple as that. Below are our final App Component and StoreSlice files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GPzNVcon0sAMMPllQ6bppw.png" /><figcaption>Final App.js (left) &amp; storeSlice.js (right)</figcaption></figure><p>So there you have two small examples of how you can continue to build out your Redux functionality. This is again, just scratching the surface as I’m sure you can imagine you could easily build this up and scale it to a fully fleshed out application. This was to hopefully just give you a taste of how easy writing previously complicated and often times convoluted Redux code can be simplified using the Redux Toolkit.</p><p>Of course if you’re looking for a further dive into it’s functionality the docs for Redux Toolkit, Immer and Thunk are all listed below and have some more great examples and use cases!</p><p><em>[1]: Redux-Toolkit Docs(</em><a href="https://redux-toolkit.js.org/">https://redux-toolkit.js.org/</a>)</p><p><em>[2]: Immer Docs (</em><a href="https://immerjs.github.io/immer/docs/introduction">https://immerjs.github.io/immer/docs/introduction</a>)</p><p><em>[3]: Thunk Docs (</em><a href="https://github.com/reduxjs/redux-thunk">https://github.com/reduxjs/redux-thunk</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bcac23968d7" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/redux-toolkit-immer-thunk-5bcac23968d7">Redux Toolkit (Immer &amp; Thunk)</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Refactoring Existing Redux w/ Redux Toolkit & Hooks]]></title>
            <link>https://javascript.plainenglish.io/refactoring-existing-redux-w-redux-toolkit-hooks-550a628d74a9?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/550a628d74a9</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux-toolkit]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-redux]]></category>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Sun, 27 Dec 2020 19:06:48 GMT</pubDate>
            <atom:updated>2020-12-30T07:29:20.515Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*vgwhbe1hCKVbopjose0v5g.jpeg" /></figure><p><em>During this year’s Reactathon one of the coolest presentation I had to chance to catch was with Mark Erickson. He was there to present some modern Redux techniques and specifically the React Toolkit and the use of the ever popular *hooks*. It inspired me to go back and refactor some of my old Redux code from using the ‘connect’ higher order component to using the Toolkit. So if you’re looking to refactor Redux to make use of it’s hooks I’m gonna walk through a simple refactor and implementation of Redux Toolkit.</em></p><p>First things first I’ll start with a basic React app that has some built in Redux ‘connect’ functionality built into it. For the purposes of this demo it will be a simple store app with an item counter. Below is the basic setup of the three main files that hold Redux functionality. The Reducer, Index.js (where I’m creating my store for the purposes of this demo), and App.js (which is connected to the store’s state and dispatch through it’s props):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_RFcDnFQjiW6puz6w6qTBA.png" /><figcaption>Reducer (left) &amp; Index.js (right)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cVGhvk-n2jxSXeJLJ6lOCA.png" /><figcaption>App.js</figcaption></figure><p>So here we have everything set up. Our App component is subscribed to our Redux store and it’s single piece of state (itemCount) and has it’s single dispatch method to increase the count of itemCount. Its a superrrr simple set up and normally on a larger scaled app you would see an action’s file that held all the different dispatch functions so they could be reused across components but this is fine for a simple demo.</p><p>So where do we begin on refactoring our code to make use of Redux Toolkit and then React-Redux hooks? Well, installing it would probably a good idea.</p><pre>npm install --save @reduxjs/toolkit </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5QLfvd6ugvhrfXkubspHjA.png" /><figcaption>packlock.json for Redux-Toolkit</figcaption></figure><p>This will install the toolkit which has a few tools conveniently bundled together. This does Not include however React-Redux which you will still need to install if you plan to be using Redux’s hooks (useSelector, useDispatch) but more on that a little later. It also comes with immer, thunk and reselect all of which are useful and will be important to how React Toolkit functions on a larger scale. But we’ll come back to those as well a little later. For now let’s just start with refactoring some of our existing code.</p><p>First we’ll go ahead and add a store.js file to our Redux folder. We’re going to move the creation of our store away from index.js and into this file now. Using the Redux Toolkit method configureStore we can import our storeReducer and export to our index.js a fully configured store. If we were to have multiple reducers this would also be where we can combine them (think combineReducers). Below is the refactored code, be sure to note the changes in imports. In store.js we’re now importing from @reduxjs/toolkit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75IUhahyLzep_-E1hr5CbQ.png" /><figcaption>New Store.js (left) &amp; Refactored Index.js (right)</figcaption></figure><p>Now that we have those two changes done we’ll move on to the real magic, which is going to be in our storeReducer. Here we will utilize my favorite Redux Toolkit method ‘createSlice’. This will essentially combine our Reducer and Actions all together into a ‘slice’ of state. First off, just for sake of clarity I’ll rename the reducer file storeSlice.js and then fix our import from the store.js file. Next, we will start by declaring a new slice using createSlice. We will then configure it with a few things using key/value pairs starting with “name” which will will stick with ‘store’. Next, we will also define its initial state, which for us only includes our itemCount set to zero initially. After the initialState we define our reducers which upon export Redux Toolkit will turn into dispatch actions we can use throughout our application. Ultimately, it should looks something like this and I’ve left the previous Reducer code for reference commented out on the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f16eQZ_xuOxLDN6UpkPtSQ.png" /><figcaption>Refactored reducer into storeSlice</figcaption></figure><p>Above you can also see we are exporting ‘increaseCount’ as an action of storeSlice. This is the dispatch method that we will ultimately call within our App component. This now leaves one last export that we’re missing which deals with subscribing to state. Now that we are refactoring away from the ‘connect’ method and not mapping our state/dispatch to props, we will be using the hook ‘useSelector’. We therefore need to export our piece of state (itemCount) right before we export our storeSlice.reducer. Our final storeSlice should ultimately look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1RGH0-CxSYru1HC3gv6CA.png" /><figcaption>Final storeSlice.js</figcaption></figure><p>State.store.itemCount points to our slice that we named ‘store’ and then within our initialState the itemCount which we set to zero. selectItemCount is of course a conventional naming of the export and you could name it whatever you like. Now finally on to our last refactor which will happen within our App component!</p><p>First thing we can do is go ahead and delete all our mapState and mapDispatch code. ‘Un-connect’ our App component and change all our imports so that we now import the two hooks we will need (useSelector &amp; useDispatch) from react-redux. Then we will also import our specific piece of state and our action from our storeSlice (selectItemCount &amp; increaseCount).</p><p>The final step is to then utilize them within the component. We declare a variable using ‘useSelector’ which will subscribe our component to that piece of the redux store. We also then declare our dispatch by calling the hook within the component. We then only need to call the dispatch method ‘increaseCount’ onClick of our App button!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XUH79qpwJ23fDxgtCEU9ag.png" /><figcaption>Refactor of App.js</figcaption></figure><p>And there you have it! We’ve essentially refactored all our original functionality from Redux’s ‘connect’ methodology to our new Redux Toolkit. This is of course only scratching the surface of what the Redux Toolkit can do. The functionality of being able to manipulate state easily within our newly created slice using Immer allows for direct manipulation of state which is a huge change from how Redux worked previously. In addition Thunk is also included in the Redux Toolkit which allows for asynchronous calls usually to an API. In an upcoming blog post I will expand on this example and add some more complex state manipulation and even some dummy examples of dispatch calls using JavaScripts ‘fetch’.</p><p>Of course if you’re looking to take a deeper dive into the functionality of Redux Toolkit and what’s happening ‘under the hood’, the docs provided on their official site are an incredible resource.</p><p><em>[1]: Redux-Toolkit Docs(</em><a href="https://redux-toolkit.js.org/">https://redux-toolkit.js.org/</a>)</p><p><em>[2]: Redux Docs (</em><a href="https://redux.js.org/">https://redux.js.org/</a>)</p><p><em>[3]: React-Redux Docs (</em><a href="https://react-redux.js.org/">https://react-redux.js.org/</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=550a628d74a9" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/refactoring-existing-redux-w-redux-toolkit-hooks-550a628d74a9">Refactoring Existing Redux w/ Redux Toolkit &amp; Hooks</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Rails/React app to Heroku]]></title>
            <link>https://legobw.medium.com/deploying-a-rails-react-app-to-heroku-9c3bec532dfd?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c3bec532dfd</guid>
            <category><![CDATA[rails-api]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Fri, 18 Dec 2020 20:06:05 GMT</pubDate>
            <atom:updated>2021-01-08T03:00:59.292Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>If you’re looking to take a project with a Ruby on Rails API backend &amp; React frontend into production, look no further. Over the past few weeks I’ve been working to deploy a number of my projects onto the Heroku platform. Here I’ll outline the steps needed to move a simple application from the development stage to production stage.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*iYKXspLKE0atWpINn39IuQ.jpeg" /></figure><p>When picking a platform to host my projects online Heroku seemed like the obvious choice. It had been recommended to me due to its ease of use and how quickly it could be up and running. So first things first, you’re going to want to sign up for Heroku! No worries though, its free to signup! Just go ahead and click this <a href="https://signup.heroku.com/login"><strong>link</strong></a> and it will take you right to the sign up page. Should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ND8uDlQsecWkEt3z_mDBxg.png" /><figcaption>Heroku SignUp</figcaption></figure><p>After confirming your email, setting your password and agreeing to their terms of service you’ll finally land on your dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cl6DQkM2AsSATspvh1sDHQ.png" /><figcaption>Heroku Dashboard</figcaption></figure><p>Here’s where your journey begins. Go ahead and click the ‘Create New App’ button and let’s get started. It immediately prompts you to enter your ‘app-name’. In this example deployment I’m going to assume that the frontend and backend code of your application are decoupled and therefore most likely two separate repositories. Speaking of repositories, if you haven’t already uploaded your application to GitHub as separate repositories I would <strong>Highly Recommend It</strong>. Heroku offers you three separate ways to deploy your code onto Heroku’s servers. 1) Using Heroku Git and the CLI provided by Heroku, 2) Using GitHub and connecting it to an existing repository, or 3) using Container Registry for your Docker App. For this article we will be only using 2)as I believe it’s the most straight forward and easy to use.</p><p>So go ahead and click ‘GitHub’ as the method of deployment and connect it to your GitHub that houses the repo for your project. Search for your specific repo and once Heroku finds it within GitHub you’ll get a screen something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R5HAwzUPRpMb4BJ6zZFYFg.png" /></figure><p>You’ll see you now have two options: Automatic Deploys or Manual Deploy. Here I recommend if you’re comfortable allowing Heroku in conjunction with GitHub to take some of the work off your hands and enable automatic deploys. Now you have the option to choose which branch you want to actually deploy. You can choose your main branch for production and then have subsequent offset branches used for testing/further development or vice versa. Dealers choice. Just know that when ever you push changes to your ‘chosen deployment branch’ on GitHub it will trigger a re-deployment of your application with those changes on Heroku, for better or worse!</p><p>So pretty much everything is ready to go on Heroku’s side, now to talk about some things that you may have been using in development and how you might have to adjust them going into deployment. I’m lookin at you Databases, ActiveStorage, etc. As far as a database options go, PostgreSQL is a great option as it is supported out of the box (and free up to 10,000 rows) on Heroku. So for now just be aware that you’re going to have to migrate your schema, seed your database and all that good stuff once you deploy onto Heroku. ActiveStorage is a different story…</p><p>I’ve deployed two projects now that utilized ActiveStorage in development and have since removed that functionality from Rails once deployed. Suffice to say it was a headache. Huge. I’ll just leave it at that and I’ll be writing another blog post soon about how I simply cut out the middle man of ActiveStorage and began sending things straight to AWS s3. But more on that another time. For now lets go ahead and hit that deploy button and get Heroku adding your Backend Application to their Servers!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o7HR1vk0_YLIzs-ULFZhPw.png" /><figcaption>Overview of Newly Made App</figcaption></figure><p>Heroku will then build your app and let you know once it’s finished and deployed. Now for my simple example I used PostgreSQL for just a single table for my Post model. But from the main landing page for your newly built app, the easiest way create, migrate, and seed your DB on Heroku is to click the ‘more’ button in the top right corner and then click the ‘run console’ option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*J8r7FtonML29MtXHkO_WBQ.png" /></figure><p>This will open up a console directly on Heroku that you can use as you previously did your own CLI in development. Having PostgreSQL singled out as your DB of choice within your config/database.yml file should have already told Heroku to build a database, so you can skip rails db:create, and go straight for rails db:migrate within the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twv-Emfo2700scnIzmDOgQ.png" /></figure><p>Be aware that if you were to do this within your own CLI off of Heroku’s site you would just need to install Heroku’s CLI and login in. More info on that can be found in their docs here: <a href="https://devcenter.heroku.com/articles/heroku-cli">https://devcenter.heroku.com/articles/heroku-cli</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eGd4_ivknWCibJxUcuzhyQ.png" /></figure><p>With your new DB migrated, you can then of course rails db:seed if need be or execute any other files/calls you need to populate your DB. But with this last step your basic backend application is set up! Now on to the frontend.</p><p>The initial steps for uploading your frontend application to Heroku are identical to what we did for the backend, with one small change, which we’ll get to in a sec. First off, unlike the backend, unless you plan on buying a specific domain and using that for your frontend, be aware that whatever you name your frontend app will be in the URL + herokuapp.com, so best to keep it short and sweet.</p><p>Now before we go ahead and connect our GitHub repository one important step we should do is specify the Buildpack. Normally Heroku is very good at just identifying what language you’re using and will build accordingly. However, if you’re like me, I generated my React frontend using ‘npx create-react-app’ which took care of a lot of the boilerplate stuff for me. Heroku therefor detects JavaScript as the language and tries to build it using Node.js, which we don’t want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*judYr8cJxdYWszshQUTsng.png" /></figure><p>Rather than refactoring your code and package.json it’s easier to just specify the Heroku Buildpack option. This can be found by going to settings and scrolling down to Buildpacks, then pasting in this line:</p><p><a href="https://buildpack-registry.s3.amazonaws.com/buildpacks/mars/create-react-app.tgz">https://buildpack-registry.s3.amazonaws.com/buildpacks/mars/create-react-app.tgz</a></p><p>Now we’re ready to go back to the ‘Deploy’ tab and connect to our GitHub repository just as we did before. Choose whether you want it to auto deploy just as we did before and then go ahead and have Heroku build your frontend app! In the past I have had some issues with package.json &amp; yarn.lock clashing, usually due to conflicting dependency versions so just be on the lookout for that. But besides that once it finishes building you should be able to open your brand new app and actually use your frontend! Now, don’t be surprised if everything crashes right away, there is one more step that you most likely need to do, which is to alter your fetch calls to your backend. Since you’re now hosting your backend and therefore database on Heroku, your frontend now needs to call out to that instead. It can be tedious but everywhere you were fetching to <em>(‘http://localhost:3000/’)</em> you now need to fetch to <em>(‘https://your-app-name/herokuapp.com/)</em>. But with that refactor done and pushed to GitHub, which should trigger a re-deploy of your backend app, you’re done!! And you’ve successfully deployed your app onto Heroku!</p><p>In my next blog post I’ll try and cover some more trouble shooting issues I’ve run into with going into production on Heroku and how to solve them. Feel free to leave comments if you have any questions!</p><p><em>[1]: Heroku Deployment Docs(</em><a href="https://devcenter.heroku.com/categories/deployment">https://devcenter.heroku.com/categories/deployment</a>)</p><p><em>[2]: Heroku Rails Docs (</em><a href="https://devcenter.heroku.com/articles/getting-started-with-rails6">https://devcenter.heroku.com/articles/getting-started-with-rails6</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c3bec532dfd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Hooks: A Quick Introduction]]></title>
            <link>https://legobw.medium.com/react-hooks-a-quick-introduction-e9990f3426e0?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9990f3426e0</guid>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Mon, 28 Sep 2020 16:31:07 GMT</pubDate>
            <atom:updated>2020-09-28T16:31:07.485Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*SIVTEKFbPz9QRX2rULbgOQ.jpeg" /></figure><p>When learning about React for the first time one of the very first decisions you’re faced with is which way to write your components. React gives you two different variants for this choice: Class Components &amp; Functional components. Initially when I was trying to wrap my head around this and learn why to use one and not the other I figured a good rule of thumb was to always base my decision off whether or not my component would need to make use of state. If it did then it had to be a Class component, if not then a functional component worked just fine. When React was first introduced this was convention, that is until Hooks were introduced!</p><p>The React Dev team introduced Hooks for a number of reasons, but I’ll go ahead and focus on just one because its the one I related to the most and was very much looking for an answer to. The dreaded ‘this’. After having come from Ruby and diving into JavaScript it was a Struggleeee to wrap my head around the way ‘this’ was used throughout JS. How it must be bound within class components still trips me up. So from my perspective one of the great pluses of using Hooks within functional components is not having to deal ‘this’.</p><blockquote>Now I’ll go ahead and examine what will be the two most familiar features that Hooks adopt to make them behave like Class Components. Right out of the box React has two methods useState and useEffect which as you might have already guessed allow for the use of State and mimic Lifecycle methods.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7HptDzHW5wJZvVRPwodsfQ.png" /><figcaption>Example of useState</figcaption></figure><p>The first method useState has a syntax that is super easy to adopt. You begin by declaring your functional component as you normally would. Be sure to remember to import useState from react! Then simply declare a variable and set it equal to useState. In the example above num represents a number but could be any data type (Object, String, Array, etc.) and setNum is a callback function. By declaring num here and useState React will now be able to preserve the state of this function even after it’s been run. Using it in this way is nearly identical to this.state within a Class Component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Uq2tk-RmGSucvEiprqWWQ.png" /><figcaption>JSX for example component</figcaption></figure><p>Next we simply add the appropriate JSX. For this example we have a &lt;p&gt; tag that displays the number of the times the button has been clicked. You can also see the button is being passed the callback function we declared earlier, setNum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*08liYa43LWE7WzDBodTIFg.png" /><figcaption>useState example</figcaption></figure><p>Now onClick the button will call the function setNum, which will then increment our num by 1 and then re-render to reflect the functional state. Simple right?!</p><p>Lets take a look at our other familiar out of the box method useEffect. Those who are comfortable with using componentDidMount, componentDidUpdate &amp; componentDidUnmount know their use case is super useful for making things like fetch calls or setting intervals. Well, with the useEffect Hook you are then able to mimic the behavior of these lifecycle methods within your functional components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A92n-cg9LA_dAhNTXwoWog.png" /><figcaption>useEffect example</figcaption></figure><p>Here we have mock fetch within the method useEffect. You can see that we don’t have to declare variables to call useEffect, it simply lives inside your functional component. React docs tell us to always make sure that the useEffect hook lives top level so as not to cause any strange behavior. By having it here you can also affect state and have access to props. This method is called immediately after render, just like DidMount and DidUpdate do because often times you will want to affect something not only on the first render but also after every update. The useEffect method also has functionality to unMount or end something that runs until a component gets removed from the DOM. By returning a function you would be able to end anything currently running, ie a setInterval or a subscription, useEffect will run that returned function once the component unMounts.</p><p>These are just two examples of ways to use Hooks within a functional component. There are a few more ‘out of the box’ hooks that do very specific things that I encourage you to checkout. If you’d like to see more examples or ways on how to use these Hooks, the React docs have quite good documentation covering Hooks. I hope these short examples and explanations help in furthering your React journey.</p><p><em>[1]: React Docs (</em><a href="https://reactjs.org/docs/hooks-intro.html">https://reactjs.org/docs/hooks-intro.html</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9990f3426e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helpful Tips and Tricks: Chrome DevTools]]></title>
            <link>https://legobw.medium.com/helpful-tips-and-tricks-chrome-devtools-638e8c7d481b?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/638e8c7d481b</guid>
            <category><![CDATA[devtools]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Tue, 08 Sep 2020 15:04:43 GMT</pubDate>
            <atom:updated>2020-09-08T15:04:43.864Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Upon my own personal journey to learn and become familiar with JavaScript I’ve found probably the Most helpful tool in refining my code is without a doubt Google Chrome’s DevTools.</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FPh5ELYJov9n5oHzVHZ%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FPh5ELYJov9n5oHzVHZ%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMW0zdXpwNXgycW9xZXF5dmM2c2I5d3N2enJ0dTB5ZjBmcWozYnRkNyZlcD12MV9naWZzX2dpZklkJmN0PWc%2FPh5ELYJov9n5oHzVHZ%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/3137bc192c0e820d7c3eae0c2f4e8bab/href">https://medium.com/media/3137bc192c0e820d7c3eae0c2f4e8bab/href</a></iframe><p>Anyone who has “inspected” a webpage probably has some understanding of how truly powerful the DevTools are. They include a very helpful visualization of the DOM tree, a REPL console in which you can run JavaScript, a CSS reference where you can manipulate elements style responsively, and a Network reference where you can delve into the load time/order/etc. of any webpage just to name a few. Today however I’m just going to be focusing on the Console feature of DevTools, but will include 2 of my other favorite features at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xcG-hfFTWg-9Rzk6EduA2g.png" /><figcaption>Opening DevTools using left-click “Inspect”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSo4Nj-L8xCWT6_XLmJl_Q.png" /><figcaption>Opening DevTools from Chrome Settings</figcaption></figure><p>To begin:</p><p>Launch the DevTools while on any webpage by either left clicking and selecting “inspect”, using a keyboard shortcut Command+Option+C (Mac) / Control+Shift+C (Windows, Linux, Chrome OS) or simply selecting “Developer Tools” from the “More Tools” option of Chrome’s settings. From there the DevTools window should pop up. From the main nav bar select the option “console” to open the console REPL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RF8F9_ntpiz2ab2T7PlK5Q.png" /><figcaption>Console within DevTools</figcaption></figure><p>Here is where you have the ability to run stand alone code OR run JavaScript code that has been loaded with the webpage itself. You can use things that have already been declared such as global variables or functions.</p><p>Now there are quite a few built in methods that come with Console. The most useful of these when debugging your code is going to be console.log(). This prints the console whatever the evaluation of its block. For example: console.log(&#39;hello world&#39;) will return simple =&gt; hello world. Where as something like console.log(32-10) will return =&gt; 22. Using this you can sprinkle console.log’s throughout your javascript code to ensure that functions are returning what you expect them to, or variables values are manipulated how you wrote them.</p><p>Another equally as useful tool is console.dir(). This prints a JSON representation of the object passed it. So in the example after selecting the h2 from the DOM, by then using console.dir(), this prints to the the object which you can then uncollapse and inspect the object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sAGrKEp4Y0AVtGZ0SDetcA.png" /><figcaption>console.dir()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a2N4mI7LQhfgqWRd8ttIlw.png" /><figcaption>console.group()</figcaption></figure><p>Another useful Console method is console.group(). This takes a label which will then log everything after it to this ‘group’ until console.groupEnd() is called. This is helpful for logging multiple values that are all associated with each other. For example if you were to log all of the attributes of a specific object.</p><p>A useful console method that help to evaluate website performance is console.time(). This starts a timer that will run until the code hits a console.timeEnd(). So if you were looking to test something like script load times by placing one at the beginning of your code and then an timeEnd at the end you’d be able to evaluate how long it took Chrome to load your script file.</p><p>Once you start getting into complex JavaScript patterns such as callbacks another useful Console method is console.trace() which will print out a stack trace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iuwvbLv_9eE9qWV6HnkxuQ.png" /><figcaption>console.trace()</figcaption></figure><p>These are quite a few other Console function that come with the DevTools which are absolutely worth looking more into and playing around with until you’re able to understand them. All of them will only continue to help you write better and cleaner code.</p><p>Another favorite feature of Console comes with its REPL abilities and how it can manipulate the DOM in real time. By running some simple JavaScript code you can then test and alter the DOM to suit your purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uw5BigPhPxU81JBnlCIH8Q.png" /><figcaption>DOM Manipulation from Console</figcaption></figure><p>There are many, many, MANY things you can do within the Console and these just scratch the surface. And Console is just ONE of the amazing tools that come with DevTools. Just really quickly I’ll talk about two of my other favorite features within DevTools that don’t deal with the Console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wp91_cICVgN2HyUhdXTfeQ.png" /><figcaption>Mobile Simulation</figcaption></figure><p>The first one being the Mobile Simulation. By clicking the small icon in the top left of the DevTools window that looks like an phone/tablet, DevTools then pairs down your website into what would be rendered with the selected device. This allows you to really see how your CSS and JS need to behave when pushed to a smaller aspect ratio than a laptop or PC.</p><p>My second favorite feature is seeing how your DOM content loads. Within the DevTools by clicking the Network tab and then within Network Settings you can choose ‘Show Overview’ and ‘Capture Screenshots’. This will give you a step by step representation of how your DOM loads and may point you in the direction of how to fix a pesky Unable To Load Content error, or any number of errors that deal with order of load.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ESs-Xtq4YdUYHmFPEwSXWg.png" /><figcaption>DOM Content Loading</figcaption></figure><p>These are just a SMALL sample of the powerful tools that come with DevTools and I invite you to go out and explore the Powerrrrrrr!!</p><p><em>[1]: Chrome DevTools (</em><a href="https://developers.google.com/web/tools/chrome-devtools">https://developers.google.com/web/tools/chrome-devtools</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=638e8c7d481b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Refactoring ActionView Form Helpers]]></title>
            <link>https://legobw.medium.com/refactoring-actionview-form-helpers-f3b190a269bc?source=rss-168f01422e83------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3b190a269bc</guid>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Brian Lego]]></dc:creator>
            <pubDate>Mon, 17 Aug 2020 12:02:55 GMT</pubDate>
            <atom:updated>2020-08-17T12:02:55.374Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Since Rails 5.1 theres a new form in town and it goes by the name of ‘form_with’.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*_VJ6QizxnkiTtQzYN5NLxw.jpeg" /></figure><h4>The Predecessors: &lt;form_for&gt; &amp; &lt;form_tag&gt;</h4><p>Those familiar with Ruby on Rails know that the two main Form Helpers that Rails provides out of the box are &lt;form_tag&gt; and &lt;form_for&gt;. Say for example you have an Article model that you would like the user to be able to create another instance of:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVb2ItdxLwvKY7csfTyxDQ.png" /></figure><p>The ActionView Helper allows us to set an object for the block |f| and therefore associate attributes to it when created, ie :title. This form helper is a simple way to create a form written in ruby that then outputs to the following HTML which can be read by the browser. Now what if we wanted a form didn’t have a model written that we could then associate the form with? Never fear, &lt;form_tag&gt; is here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiI6ey-N1OJUvyqwysJt0A.png" /></figure><p>Nearly identical HTML outputs as the &lt;form_for&gt;, &lt;form_tag&gt; however doesn’t need an instance or a model to build off of, it simply needs a url or path and doesn’t yield to a block. You are able to assign attributes, if necessary, nearly the same way as before but instead using input tags.</p><p>Now something you may have noticed. The two form helpers end up producing nearly Identical HTML. Rails developers must have obviously realized this was an inefficient way of integrating forms into applications as well as they came up with the alternative &lt;form_with&gt;</p><h4>Simply put, &lt;form_with&gt; gives you the best of both worlds.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGX85qPIq4TeXOWH2qcSvA.png" /></figure><p>Here it is operating similarly to the &lt;form_for&gt;. Its creating a block built around the article instance. It can be written nearly the exact same with given a local url path. By simply changing line 1 to form_with url: &quot;/articles&quot; you are able to achieve the same HTML.</p><p>There are some subtle differences that come with &lt;form_with&gt; as opposed to its sisters &lt;form_for&gt; and &lt;form_tag&gt;. The first being that data-remote as you can see in the example above gets sets by default to true . This means the article will be submitting using AJAX although you can specify and change this if needed and add local: true to line 1.</p><p>Another subtle difference is that &lt;form_with&gt; no longer automatically assigns class or id . It allows you as the developer to assign which HTML elements you wish to have classes and ids. &lt;form_with&gt; also allows you to specify scope with using a url. &lt;%=form_with url: &#39;/articles&#39;, scope: articles do |f| %&gt; gives you the ability to assign the params when submitting that then point them to the correct controller. Another notable change is when nesting things within your form. Before you would have used the fields_for syntax but with &lt;form_for&gt; you simply use fields.</p><p>With the new addition of &lt;form_with&gt; it simplifies writing forms into a single ActionView Helper and allows for the syntax to write forms for both an instance of a model or a url path the same. With this new change the code for &lt;form_for&gt; and &lt;form_tag&gt; will more than likely slowly be deprecated.</p><p>To read more about all the ActionView Helpers for forms here are some links:</p><blockquote>[1]: Rails Guides(<a href="https://guides.rubyonrails.org/form_helpers.html">https://guides.rubyonrails.org/form_helpers.html</a><em>)</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3b190a269bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>