<?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: Lincoln W Daniel</title>
    <description>The latest articles on DEV Community by Lincoln W Daniel (@lincolnwdaniel).</description>
    <link>https://dev.to/lincolnwdaniel</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%2F233475%2Fbdee7378-38d0-4d4f-ace9-2e88c5ad6295.jpg</url>
      <title>DEV Community: Lincoln W Daniel</title>
      <link>https://dev.to/lincolnwdaniel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lincolnwdaniel"/>
    <language>en</language>
    <item>
      <title>How to Use JavaScript Functions - Crash Course [Video]</title>
      <dc:creator>Lincoln W Daniel</dc:creator>
      <pubDate>Sat, 08 Feb 2020 23:03:08 +0000</pubDate>
      <link>https://dev.to/lincolnwdaniel/javascript-functions-crash-course-video-5g1h</link>
      <guid>https://dev.to/lincolnwdaniel/javascript-functions-crash-course-video-5g1h</guid>
      <description>&lt;p&gt;Functions are another necessary part of programming in JavaScript. When building programs in JavaScript, you should use functions to organize your program into smaller, executable pieces of code that are responsible for specific actions. With your functions defined, you can call them from anywhere in your program with arguments that can influence the result.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/x7Um3T59SIY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this video, we learn how to declare JavaScript functions with a name and arguments, call a function with parameters, and return a result. We also learn how to define functions on objects as methods and access the properties of the object within the function.&lt;/p&gt;

&lt;p&gt;Along the way, we explore the DRY and Single Responsibility (SRP) principles for keeping our code clean and easy to reason about. By the end of this tutorial, you should have a strong understanding of how to use functions in JavaScript to build better programs.&lt;/p&gt;

&lt;p&gt;My LinkedIn profile: &lt;a href="https://www.LinkedIn.com/in/LincolnWDaniel"&gt;https://www.LinkedIn.com/in/LincolnWDaniel&lt;/a&gt;&lt;br&gt;
My website: &lt;a href="http://www.LincolnWDaniel.com"&gt;http://www.LincolnWDaniel.com&lt;/a&gt;&lt;br&gt;
1Liner Blog: &lt;a href="https://www.1Liner.dev"&gt;https://www.1Liner.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>functions</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Use JavaScript Arrays - Crash Course [Video]</title>
      <dc:creator>Lincoln W Daniel</dc:creator>
      <pubDate>Fri, 07 Feb 2020 19:31:30 +0000</pubDate>
      <link>https://dev.to/lincolnwdaniel/javascript-array-crash-course-ep4</link>
      <guid>https://dev.to/lincolnwdaniel/javascript-array-crash-course-ep4</guid>
      <description>&lt;p&gt;In this &lt;a href="https://youtu.be/70QO8Qf6Qwk"&gt;video&lt;/a&gt;, we take a crash course on how to use JavaScript arrays to store a list of items, access individual items of an array by their index, and loop through an array to access all or some of the elements of an array. We end by learning how to manipulate an array to change a specific element at an index, push items onto an array, and remove items from an array in JavaScript.&lt;/p&gt;

&lt;p&gt;Storing data is an important part of programming; accessing that data is also important. In many cases, you'll have to store data as a list, array for the sake of efficiency when accessing, transferring, and manipulating that data later in your program.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/70QO8Qf6Qwk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;My LinkedIn profile: &lt;a href="https://www.LinkedIn.com/in/LincolnWDaniel"&gt;https://www.LinkedIn.com/in/LincolnWDaniel&lt;/a&gt;&lt;br&gt;
My website: &lt;a href="http://www.LincolnWDaniel.com"&gt;http://www.LincolnWDaniel.com&lt;/a&gt;&lt;br&gt;
1Liner Blog: &lt;a href="https://www.1Liner.dev"&gt;https://www.1Liner.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>arrays</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to use Variables in JavaScript [Video]</title>
      <dc:creator>Lincoln W Daniel</dc:creator>
      <pubDate>Fri, 07 Feb 2020 19:29:20 +0000</pubDate>
      <link>https://dev.to/lincolnwdaniel/how-to-use-variables-in-javascript-video-lad</link>
      <guid>https://dev.to/lincolnwdaniel/how-to-use-variables-in-javascript-video-lad</guid>
      <description>&lt;p&gt;In this &lt;a href="https://youtu.be/YrWYUhruUIQ"&gt;video&lt;/a&gt;, we learn how to define mutable and immutable variables (and constants) using the "let" and "const" keywords in JavaScript.&lt;/p&gt;

&lt;p&gt;Variables are a foundational piece to any programming language. Defining variables in your JavaScript code  will allow you to store data that you can access and manipulate at a later point in your program.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/YrWYUhruUIQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>variables</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My first open source project: Minimize &amp; Automate ExpressJs REST API setup with 2 Lines of Code</title>
      <dc:creator>Lincoln W Daniel</dc:creator>
      <pubDate>Sat, 05 Oct 2019 16:54:12 +0000</pubDate>
      <link>https://dev.to/lincolnwdaniel/my-first-open-source-project-minimize-automate-expressjs-rest-api-setup-with-2-lines-of-code-f9f</link>
      <guid>https://dev.to/lincolnwdaniel/my-first-open-source-project-minimize-automate-expressjs-rest-api-setup-with-2-lines-of-code-f9f</guid>
      <description>&lt;p&gt;I've been building the same server for the last three years. I've learned a lot along the way. One of my greatest learnings is the tedium kills morale and momentum. Accordingly, I've done everything I can to prevent tedium, especially when it stems from having to writing boilerplate code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TL;DR&lt;/p&gt;

&lt;p&gt;This library, &lt;a href="https://github.com/Lwdthe1/jsdoc-rest-api"&gt;jsdoc-rest-api,&lt;/a&gt; can generate a map of your REST API endpoints from your JsDoc and use that map to automatically hook up your endpoints to your ExpressJs app when starting your REST API web server.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The server started out as a single file when I was just learning NodeJs and the MEAN stack. That went well  enough to support 1k users. Then I decided to build a full system to support the growth of the platform, Smedian.com. That went well and got us to 3k users. From there, I realized I was slowing down because there was a lot of boilerplate involved in adding new features.&lt;/p&gt;

&lt;p&gt;Whenever I wanted to add a new API endpoint, I had to write a lot of boilerplate just to get the pipeline hooked up. Part of the pipeline is adding the ExpressJs endpoint middleware. The system was big enough for that to become a pain. Always having to write &lt;code&gt;app.get()&lt;/code&gt;, &lt;code&gt;app.post()&lt;/code&gt;, &lt;code&gt;app.put()&lt;/code&gt;, and &lt;code&gt;app.delete()&lt;/code&gt; was getting tiresome. With that said, I decided to automate that part. But there was more to the tedium.&lt;/p&gt;

&lt;p&gt;I still had to store all the endpoint definitions somewhere in order to loop over them when hooking up the server. That introduced more tedium of its own. I had to create a new file for each group of endpoints, create an array to host the endpoint definitions, and correctly map each point to the correct handler which was hosted in another file. Sure, the end product was much better than writing &lt;code&gt;app.get()&lt;/code&gt; on my own each time, but there was still room for improvement.&lt;/p&gt;

&lt;p&gt;It took me another year to get to this point, but I finally figured out how to cut that final point of tedium. I got tired of creating those files, writing out the endpoint definitions in objects, and making sure they mapped correctly to the correct handler in another file. I knew there should be a way to host an endpoint definition in the same place as its handler while also not having to write &lt;code&gt;app.get()&lt;/code&gt; ever again. &lt;/p&gt;

&lt;p&gt;Another thing that started to become necessary was better documentation of my API as I looked to bring on some help. I was sparsely documenting each endpoint in its definition, but that wasn't always in sync with the actual handler function, which, again, was in another file. The handler, in rare cases, also had its own documentation as JsDoc.&lt;/p&gt;

&lt;p&gt;I was having trouble thinking of how to cut all this boilerplate writing. I couldn't figure out a simple, clean, and minimally magical way to automate adding all and new REST API endpoints to my  ExpressJS app as I added new handlers throughout my codebase. At this point, I had already done some other automations by simply parsing files and generating other files from them. However, such a solution would be hard to implement in this case because I needed a very flexible solution; string parsing is very hard to do while trying to produce a flexible solution.&lt;/p&gt;

&lt;p&gt;Nonetheless, I knew any solution would require parsing the file. I just needed a way to do it in a consistent and extremely flexible manner. By flexible, I mean a solution that would succeed for any type of function definition across various object definition syntaxes. Of course, I also wanted the solution to be able to support easy documentation of my API. That desire to brush two birds with one comb is what lead me to an ideal solution: I could just parse JsDoc!&lt;/p&gt;

&lt;p&gt;The solution required two parts: defining an interface for the JsDoc and creating a parser for that interface. Again, this parser would have to work under all possible (and reasonable) scenarios across my codebase.&lt;/p&gt;

&lt;p&gt;I found a great JsDoc parser package and got to work.&lt;/p&gt;

&lt;h1&gt;
  
  
  Defining the interface
&lt;/h1&gt;

&lt;p&gt;Take this module for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ArticleApiController {
    /**
     * @apiPath GET /api/i/article/:id
     */
    getArticle(req, res, next) {
        // 1. Insert the user into db
        const dbArticle = this.articleDbDriver.getById(req.params.id);
        // 2. Respond with the article
        res.status(200).send(dbArticle);
    }

    /**
     * @apiPath PUT /api/i/article/:id
     * @apiBody {"title": "String", "subtitle":"String", "content": "String"}
     * @apiKey Update Article
     * @apiDescription Create a new article
     * @apiResponse Article object
     */
    updateArticle(req, res, next) {
        // 1. Update the article in the db
        const updatedDbArticle = this.articleDbDriver.updateById(req.params.id, req.body);
        // 2. Respond with the new article
        res.status(200).send(updatedDbArticle);
    }
}

module.exports = ArticleApiController
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My REST API endpoint handlers are grouped in modules I call &lt;code&gt;ApiContoller&lt;/code&gt;. These are controllers. A controller has functions that can handle incoming requests to my api; I refer to such a handler as a &lt;code&gt;ctrl&lt;/code&gt; in this system. In the controller above, if a request comes into our server for &lt;code&gt;PUT&lt;/code&gt; &lt;code&gt;/api/i/article/article1&lt;/code&gt;, it should be handled by &lt;code&gt;ArticleApiController.prototype.updateArticle()&lt;/code&gt;. If a request comes in for &lt;code&gt;GET&lt;/code&gt; &lt;code&gt;/api/i/article/article1&lt;/code&gt;, it should be handled by &lt;code&gt;ArticleApiController.prototype.getArticle()&lt;/code&gt;. All of that should just happen without any more code than what you see above. &lt;/p&gt;

&lt;p&gt;I know I may sound like an entitled brat, and that's because I am. I'm entitled to a system that just does what should happen without any extra input from me 😜&lt;/p&gt;

&lt;p&gt;Like this controller, there are many other controllers across my codebase to handle other parts of our API. I want to automate adding all of them to our ExpressJs app when our server starts, and I want it to happen in a single line of code. I looked far and wide and came up short, so I built it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Enter &lt;a href="https://github.com/Lwdthe1/jsdoc-rest-api"&gt;&lt;code&gt;jsdoc-rest-api&lt;/code&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;This &lt;a href="https://github.com/Lwdthe1/jsdoc-rest-api"&gt;library&lt;/a&gt; can generate a map of your REST API endpoints from your JsDoc and use that map to automatically hook up your endpoints to your ExpressJs app when starting your REST API web server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Methods
&lt;/h2&gt;

&lt;p&gt;There are two methods in this library, at the time of this writing; one of them relies on the other:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;generateRoutes()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;attachExpressAppEndpoints()&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first one, &lt;code&gt;#generateRoutes()&lt;/code&gt;, will simply return a mapping of all your defined REST API endpoints from your JsDoc by traversing your code.&lt;/p&gt;

&lt;p&gt;The second one, &lt;code&gt;#attachExpressAppEndpoints()&lt;/code&gt;, allows you to easily attach all of your defined REST API endpoints from your JsDoc to your ExpressJs app without ever having to write &lt;code&gt;app.get(...)&lt;/code&gt;, &lt;code&gt;app.post(...)&lt;/code&gt; (etc.) for each endpoint again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Now to start my ExpressJs REST API server, all I have to do is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
const jsdocRestApi = require("jsdoc-rest-api");
const app = express();

const PORT = process.env.PORT || 3100;
app.set("port", PORT);

// Attach all our supported HTTP endpoints to our ExpressJs app
jsdocRestApi.attachExpressAppEndpoints({
    app,
    source: "server/api/**/*Controller.js"
});

// Listen for incoming HTTP requests.
app.listen(PORT);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I can just write my REST API endpoints, handlers, and documentation in one place and have them automatically recognized by my web server. Never again will I have to create another file to host definitions, or write loops over objects, or write &lt;code&gt;app.get()&lt;/code&gt;. It all just happens. I've built what I always thought I and other devs deserve 😀&lt;/p&gt;

&lt;p&gt;If I want to add a new controller or endpoint, all I have to do is something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
    /**
     * @apiPath GET /greet/:name
     * @apiDescription Prints a greeting with the provided "name" path param.
     */
    greet (req, res) {
        res.send(`Hello, ${req.params.name}! Your REST API is up and running thanks to jsdoc-rest-api`);
    },
    /**
     * @apiPath GET /bye
     */
    bye(req, res) {
        res.send("Bye, world!");
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just write the handler, annotate the &lt;code&gt;@apiPath&lt;/code&gt;, and keep it pushing. No more tedium.&lt;/p&gt;

&lt;h2&gt;
  
  
  Popularity
&lt;/h2&gt;

&lt;p&gt;For what it's worth, I &lt;a href="https://www.npmjs.com/package/jsdoc-rest-api"&gt;published the package to npmjs&lt;/a&gt; two days ago and it already has 260 downloads on, according to the people over at NpmJs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contributors
&lt;/h2&gt;

&lt;p&gt;I'd love for anyone who is also passionate about cutting down tedium in developing REST API's to join in contributing to this library. There's a lot that can be automated in this process.&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>rest</category>
      <category>api</category>
    </item>
  </channel>
</rss>
