<?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 Codeuix on Medium]]></title>
        <description><![CDATA[Stories by Codeuix on Medium]]></description>
        <link>https://medium.com/@uix?source=rss-56a665c48bdf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*P3hRRATd8tjf2WjhLa1f2Q.png</url>
            <title>Stories by Codeuix on Medium</title>
            <link>https://medium.com/@uix?source=rss-56a665c48bdf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 23:00:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@uix/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[Building a Rest API using Node and MongoDB]]></title>
            <link>https://medium.com/@uix/building-a-rest-api-using-node-and-mongodb-bf7ac086e8f7?source=rss-56a665c48bdf------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf7ac086e8f7</guid>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Codeuix]]></dc:creator>
            <pubDate>Sat, 25 May 2019 14:04:33 GMT</pubDate>
            <atom:updated>2019-06-16T07:59:44.810Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xHM2dZYSm6Tk697cgVzLkA.jpeg" /></figure><p>In this article, we will be learning what an API is, types of API&#39;s available and finally build a custom API that allows us to perform CRUD operations for our blog website using NodeJs and MongoDB.</p><h4>What is an API?</h4><p>API is the acronym for Application Program Interface, which is a piece of software intermediary that allows two applications to talk to each other. Every application that you use to check the weather or send a message instantly on your mobile device, you&#39;re using an API.</p><h4>How API Works?</h4><p>When an application needs to retrieve data from a remote server, It raises a request to the server via API which intern interacts with a remote server and waits for that server to retrieve the requested data, interprets it, performs the necessary actions and sends back a response to the API. The API Carrying the response provides the data to the application.</p><h4>Types of API’s Available</h4><p><strong>Rest API</strong>: Rest is the acronym to Representational State Transfer, which is based on URIs and HTTP protocols, and use JSON for a data format. Here data is a representation of some object. We can get content of the object using HTTP GET Method, modify the content of the object using a POST, PUT or DELETE Methods.</p><p><strong>SOAP API</strong>: Soap is the acronym to Simple Object Access Protocol, which is its own protocol and offers more comprehensive features in the way of security, transactions, and ACID (Atomicity, Consistency, Isolation, Durability) compliance then Rest API.</p><h4>Getting Started...</h4><p>Hoping that NodeJS is installed on your system, we’ll start by creating a project folder and name it as <strong>node-api</strong>, open the project directory in your favorite code editor.</p><p>If you don&#39;t have any code editor in your local computer, My suggestion would be to use Visual Studio code which is the most preferred editor used amongst the developer community.</p><p><a href="https://code.visualstudio.com/">Visual Studio Code - Build what comes next</a></p><p>Now to initialize the project by running the following command in the terminal by navigating to your project folder.</p><pre>//intitialize the project<br>$ npm init -y</pre><h4>Directory Structure</h4><p>you will need to organize your project files in the following order to follow along.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*ERZKK5musPcaumVWZpwuTw.png" /></figure><p>Here routes folder contains a file that lists the routes that are available for the application.</p><p>You will be using the MVC model to build the application where <strong>Model</strong> holds all the code that handles the database functionality, the <strong>Controller</strong> contains the core logic on how each route needs to be handled and interacts with the models to perform specific tasks and <strong>View</strong> which are not implemented as you are not going to develop pages to showcase the output using templates.</p><h4>Building the Server in NodeJS</h4><p>We will need to use an express framework to speed up our development process as all of the basic blocks for setting the server and creating the routes are already provided by express to use it.</p><p>Install Express as a dependency in our project using the following command.</p><pre>npm install express --save</pre><p>Once the installation is complete you can start with implementing the server to handle incoming requests.</p><pre>const express = require(&#39;express&#39;);<br>const app = express();</pre><pre>app.get(&#39;/&#39;, (req, res, next) =&gt; {<br>    res.send(&#39;running node api&#39;);<br>});</pre><pre>//serving the application the port 3000<br>app.listen(3000, console.log(&#39;server started on port 3000&#39;));</pre><p>now running the command <strong>node app.js</strong> will start the server and fetch the application to run on port 3000 which outputs “<strong>running node api</strong>” when you the load the URI <a href="http://localhost:3000."><strong>http://localhost:3000</strong>.</a></p><h4>Using MongoDB</h4><p>MongoDB can be used as a database server to store, retrieve, update and delete documents for your application, you may use a free tier cluster provided by the MongoDB to deploy database for the application to use.</p><p><a href="https://www.mongodb.com/download-center">MongoDB Download Center</a></p><p>Use the above link to register and avail your first free cluster provided by MongoDB.</p><p>Once you have created and logged into your account navigate to the security tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8LsF_EZ8ww_4LdHhy6Amiw.png" /><figcaption>navigate to the security tab</figcaption></figure><p>Create a new user with admin privileges to add/modify the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*e4pH9OTj7otZ8c0N2ytVsA.png" /><figcaption>Add a new user with Admin privileges</figcaption></figure><p>Whitelist the IP address to make sure the cluster can be connected via the IP address your application is running on.</p><p>Whitelist the IP address <strong>0.0.0.0</strong> to make the cluster available to connect from any of the IP addresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LGlB1wDes3b-L-IBKEHQIg.png" /></figure><p>Rename the cluster to your liking and wait for it to get configured it will take from few seconds to minute or so to start running.</p><h4>Using MongoDB in your application</h4><p>Let&#39;s start by installing the mongoose package which will help us to manage our MongoDB database.</p><pre>npm install mongoose --save</pre><p>Connecting to MongoDB database using connection string in app.js</p><p>you need to replace the user and password in the connection string with the database username and password you created in the last step.</p><pre>//app.js<br>const express = require(&#39;express&#39;);<br>const mongoose = require(&#39;mongoose&#39;);<br>const app = express();</pre><pre>//mongoDB connection string<br>const url = mongodb+srv://user:&lt;password&gt;@node-api-8r36a.mongodb.net/test?retryWrites=true;</pre><pre>app.get(&#39;/&#39;, (req, res, next)=&gt;{<br>    res.send(&#39;running node api&#39;);<br>});</pre><pre>mongoose.connect(url,{useNewUrlParser: true})<br>  .then(()=&gt;{<br>    app.listen(3000);<br>    console.log(&#39;database connected!&#39;);})<br>  .catch(err =&gt; console.log(err));</pre><p>now if you run the command <strong>node app.js</strong> it will output “<strong>database connected!</strong>” once the connection is established.</p><h4>Handling Routing externally</h4><p>Removing routing from our core application will make application easier to maintain as we can divide different aspects of the application into sub-models that will handle specific tasks rather than a single file handling all the heavy lifting of our application.</p><p>Here we will implement routing externally by creating an <strong>api_routes.js</strong> file under routes folder and start adding the routers there as shown below.</p><pre>//api_routes.js file<br>const express = require(&#39;express&#39;);<br>const router = express.Router();</pre><pre>router.get(&#39;/&#39;,(req, res, next) =&gt; {<br>     res.send(running node api);<br>})</pre><pre>module.exports = router;</pre><p>modify the <strong>app.js</strong> file to use the routes specified in the <strong>api_routes.js</strong> file.</p><pre>//app.js<br>const express = require(&#39;express&#39;);<br>const mongoose = require(&#39;mongoose&#39;);<br>const app = express();</pre><pre>//mongoDB connection string<br>const url = mongodb+srv://user:&lt;password&gt;@node-api-8r36a.mongodb.net/test?retryWrites=true;</pre><pre>const apiroutes = require(&#39;../routes/api_route.js&#39;);</pre><pre>app.use(&#39;/&#39;, apiroutes); //using routes specified externally</pre><pre>mongoose.connect(url,{useNewUrlParser: true})<br>  .then(()=&gt;{<br>    app.listen(3000);<br>    console.log(&#39;database connected!&#39;);})<br>  .catch(err =&gt; console.log(err));</pre><pre>app.listen(3000);})<br>  .catch(err =&gt; console.log(err));</pre><p>now we achieved the same result by running the command <strong>node app.js</strong> fetching routes from the external file.</p><p><strong>Hot reloading using Nodemon</strong>.</p><p>Let’s install a package called Nodemon that will pick up the changes and restart our server when changes are made to our application.</p><p>run the following command to install Nodemon package to our project</p><pre>$ npm install nodemon --save-dev</pre><p>Here we can run <strong>nodemon app.js </strong>command to start the server.</p><h4>Further modularizing the application</h4><p>In the recent step, we saw how we can modularize your application by placing the routes in an external file. here let us see how we can further modularize our application by placing logic that is used to handle the routes in a separate file named <strong>post_controller.js</strong> under controllers folder.</p><pre>//post_controller.js<br>exports.showIndex = (req, res, next) =&gt; {<br>       res.send(&#39;ruunning node api&#39;);<br>}</pre><p>modify your <strong>api_route.js</strong> file to get the function to be handled from the controller file.</p><pre>//api_routes.js file<br>const express = require(&#39;express&#39;);<br>const postcontroller = require(&#39;../controller/post_controller&#39;);<br>const router = express.Router();</pre><pre>router.get(&#39;/&#39;, postcontroller.showIndex);</pre><pre>module.exports = router;</pre><h4>Creating a Post Model in MongoDB</h4><p>Here we’ll see how to create a collection named posts that will be used to store information about the post.</p><p>create a file name <strong>post_model.js</strong> under the <strong>model</strong> directory where we will be adding the code necessary to create a post schema for our application.</p><pre>//post_model.js<br>const mongoose = require(&#39;mongoose&#39;);<br>const schema = mongoose.Schema;</pre><pre>const postSchema = new Schema({<br>      title:{<br>        type: String,<br>        required: true<br>      },<br>      description:{<br>        type: String,<br>        required: true<br>      },<br>      image:{<br>        type: String,<br>        required: true<br>      },<br>      author:{<br>        type: Date,<br>        default: Date.now<br>      }<br>});</pre><pre>module.exports = mongoose.model(&#39;post&#39;, postSchema);</pre><p>The above code will create a collection named <strong>posts</strong> with the following field attributes to store data.</p><h4>Creating API Routes and Controllers</h4><p>here you will be creating multiple routes to handle requests from the client-server and provide a response by performing a certain operation specified by the controller.</p><h4>Creating a post</h4><p>create an add -post route that handles the post request in the api_routes.js file.</p><pre>//api_routes.js<br>const express = require(&#39;express&#39;);<br>const postcontroller = require(&#39;../controller/post_controller&#39;);<br>const router = express.Router();</pre><pre>router.post(&#39;/add-post&#39;, postcontroller.addPost);</pre><pre>module.export = router;</pre><p>create a function name <strong>addPost</strong> in a <strong>post_controller.js</strong> file that handles the post request made to <strong>add-post</strong> route and insert the request data into the MongoDB collection.</p><pre>//post_controller.js<br>const Post = require(&#39;../model/post_model.js&#39;);//include post schema</pre><pre>exports.addPost = (req, res, next) =&gt; {<br>      const post = new Post({<br>           title: req.body.title,<br>           description: req.body.description,<br>           image: req.body.image<br>      }).then(result =&gt; {<br>           return result.save()<br>      }).then(() =&gt; {<br>           res.send(&#39;post added successfully&#39;);<br>      }).catch(err =&gt; {<br>           res.status(400).send(err);<br>      })<br>}</pre><p>Now our API route to create a post is ready to be used before we get started with testing the route we add a middleware in <strong>app.js</strong> that parse our request body into JSON and sent the content type to <strong>application/json</strong>.</p><pre>//app.js</pre><pre>app.use(express.json()) //sets content-type to json</pre><p>Let&#39;s start the server by running <strong>nodemon app.js</strong></p><p>We will use the postman application to test our API Routes, you can download it on your system or install the chrome extension.</p><p><a href="https://www.getpostman.com/">Postman | The Collaboration Platform for API Development</a></p><p>Open postman and enter the API Route to create a post and select post method from the dropdown selection at the left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxESF1ZKdZJSruI_CbgFYg.png" /></figure><p>Add request headers in the Headers section as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iWTmwXrvNh58rf5opJd6OA.png" /></figure><p>Finally, let&#39;s add the request body containing the post information in JSON format in the body section by checking the raw button and choosing content type JSON (application/json) from the dropdown as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiL0SYBcG-8gZL937kh6VA.png" /></figure><p>Now click on the Send button to send the post request, which will send back a JSON response containing the status of the request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xb1iJv_SlCPH6u76iSZGnA.png" /><figcaption>Post Request Status</figcaption></figure><p>Let&#39;s check our MongoDB collection to verify if the data is been inserted or not by visiting our free cluster provided by MongoDB Atlas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ntm79vpGpLuhWCR-5Tz2fQ.png" /><figcaption>node-api cluster</figcaption></figure><p>Click on Collections to view the documents and records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sV82N-dV39iANzQOE--0IA.png" /></figure><p>You could see a test table is been created with the collection named posts and a new document is been added inside the posts collection via the post request made in the previous step.</p><p><strong>Read All Posts</strong></p><p>We will create a route name <strong>posts</strong> that will fetch all the posts from the database collection.</p><p>Use the HTTP GET method and register the route inside the api_routes.js file.</p><pre>//api_routes.js</pre><pre>router.get(&#39;/posts&#39;, postcontroller.showPost);</pre><p>Create a function named <strong>showPost</strong> inside the post controller that retrieves the posts from the database and sends them back as a response.</p><pre>//post_controller.js</pre><pre>exports.showPost = (req, res, next) =&gt; {<br>      Post.find() //fetches all the posts<br>         .then(result =&gt; {<br>             res.send(result);<br>         }).catch(err =&gt; {<br>             res.status(400).send(err);<br>         })<br>}</pre><p>Use postman to and enter the API Route to view all post records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3O12zTvMRRA70p8VGgtRIA.png" /></figure><p>Click on the send button to make a get request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8HXuOwqgqqmWhoEkWkkSg.png" /></figure><p>The array JSON string is outputted that contains information of all the posts available in the database.</p><p><strong>Retrieve Single Post</strong></p><p>To retrieve details of a particular post we should pass the <strong>_id</strong> field as a parameter to the API route to identify the individual post among all the posts in the database collection.</p><p>Create a route named post that is followed by the post id in the api_rotes.js</p><pre>//api_routes.js</pre><pre>router.get(&#39;/post/:id&#39;, postcontroller.singlePost);</pre><p>Create a function named <strong>singlePost</strong> inside the post controller that uses the post id parameter passed along with the route to filter the post from the database and send it back as a response.</p><pre>//post_controller.js</pre><pre>exports.singlePost = (req, res, next) =&gt; {<br>      Post.findById(req.params.id) //filters the posts by Id<br>         .then(result =&gt; {<br>             res.send(result);<br>         }).catch(err =&gt; {<br>             res.status(400).send(err);<br>         })<br>}</pre><p>Use postman to and enter the API Route followed by the post id by copying the <strong>_id</strong> field of the post from the database to view the post records.</p><p><strong>example route</strong>: http://localhost:3000/post/ 5ce9088ea076100fe466294c</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wnqWGeYcwDTGnxBUP-RPSg.png" /></figure><p>The output will showcase the information of a post containing the same _id field as the request parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqbtEhVoSUJG1ceGwFeOsg.png" /></figure><p><strong>Updating the Post</strong></p><p>We will create a route named <strong>post-update</strong> which is followed by the id parameter and uses the <strong>HTTP PATCH</strong> method.</p><pre>//api_routes.js</pre><pre>router.patch(&#39;/post-update&#39;, postcontroller.updatePost);</pre><p>Create a function named <strong>updatePost</strong> that gets that post information from the request body and update the post which matches the id field in the request body.</p><pre>//post_controller.js</pre><pre>exports.updatePost = (req, res, next) =&gt; {<br>      Post.findById(req.body.id)<br>         .then(result =&gt; {<br>             result.title = req.body.title;<br>             result.description = req.body.description;<br>             result.image = req.body.image;<br>         }).then(() =&gt; {<br>             res.send(&#39;post updated successfully&#39;);<br>         }).catch(err =&gt; {<br>             res.status(400).send(err);<br>         })<br>}</pre><p>Use postman to and enter the API Route to update the post along with the JSON string containing the updated information in the request body.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GDYIbGhHbNoEEL27LCAM7A.png" /></figure><p>output on sending the patch request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8EZpI-tuVyrv4GNdmHsVXg.png" /></figure><p>The shows a string stating the post is updated, we can cross-check by visiting posts collection in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*X5T-Qe21zUFDeGE4nEX3sQ.png" /><figcaption>updated post document in posts collection</figcaption></figure><h4>Deleting a Post</h4><p>we will create a route <strong>remove-post</strong> which contains post id as a parameter with the <strong>HTTP DELETE</strong> method.</p><pre>//api_routes.js</pre><pre>router.delete(&#39;/remove-post/:id&#39;, postcontroller.deletePost);</pre><p>Create a function named <strong>deletePost</strong> that removes the post from the posts collection which matches the <strong>id</strong> field provided in the parameter.</p><pre>//post_controller.js</pre><pre>exports.deletePost = (req, res, next) =&gt; {<br>      Post.findByIdAndRemove(req.params.id)<br>        .then(()=&gt;{<br>            res.send(&#39;post deleted&#39;);<br>        })<br>        .catch(err =&gt; res.status(400).send(err));<br>};</pre><p>now enter the API route followed by post id in the postman and choose the delete method and sent a request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AY84Bbmth4Gf-wW-DEc12g.png" /></figure><p>We can see the response stating the post is deleted, let&#39;s check the database to make sure the post is deleted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*qPDDQLD8ErE57ZtYfvVssw.png" /></figure><p>surely, enough the post record is been removed from the posts collection.</p><p>Finally, here’s a <a href="https://github.com/nithinmuniswamy/node-api"><strong>GitHub repo</strong></a> containing the project files.</p><p><strong>Summary</strong></p><p>We gained a little knowledge about what an API is how it plays a major role in our daily lives, build a basic API from scratch using NodeJS and MongoDB that can perform CURD operations on any document set.</p><p>Although this is a basic building block to build an API, you can implement your own way of handling the incoming request and personalize the response that needs be sent based on the response status.</p><p>Let us know what you felt about this article in the comments below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf7ac086e8f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running a Node application in Docker.]]></title>
            <link>https://medium.com/@uix/running-a-node-application-in-docker-8950f176ec4e?source=rss-56a665c48bdf------2</link>
            <guid isPermaLink="false">https://medium.com/p/8950f176ec4e</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Codeuix]]></dc:creator>
            <pubDate>Fri, 10 May 2019 09:58:57 GMT</pubDate>
            <atom:updated>2019-05-10T15:56:11.185Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b09xb-uH4quoeaAkruypSQ.png" /></figure><p>In this article we will learn some basics stuff about Docker, adding a NodeJS application into a Docker container and finally create a custom Docker image that will watch for any changes in the node application and automatically recompile and run our application without having to recompile and rerun our docker image.</p><h4>What is Docker?</h4><p>Docker is a tool that can be used to perform virtualization at the level of operating system, It provides a concept called containers which allows us to create, deploy and run applications. Containers will allow developers to bundle up the application with all its dependencies along with the libraries that are vital for an application, and ship them all out as a single package. By doing so, the developer can now focus on writing and testing the code, rather than evaluating if the code needs to altered according to the machine it is deployed on, as Docker assures that the application will run on any other Linux machine regardless of any customized settings the machine might be configured with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pREIeCWVMYuuXzZRKknotA.png" /><figcaption>Virtual Machine vs Containers</figcaption></figure><p>Docker may seem to be like a virtual machine. Unlike virtual machine Docker does not create a whole virtual operating system, it only allows the applications to use the same Linux kernel as the system on which they’re running on and requires applications to be shipped with things that are not already running on the host computer into containers. This will exponentially increase the performance and reduces the size of the application.</p><h4>Benefits of using Docker</h4><p>Docker benefits both developers and system administrators, which makes it a part of DevOps (developers + operations) tools.</p><p>For Developers, it means they can focus on writing code for an application without worrying about the system on which it will be running. It allows them to get a head start by using any of one programs that are already designed to run in a Docker container as a part of their application.</p><p>For Operations staff, it gives them a flexibility and potentially reduce the number of systems needed because of its lower overhead and small footprint.</p><h4>Getting started</h4><p>Firstly, we need to install Docker in our system, by downloading <a href="https://docs.docker.com/docker-for-windows/install/"><strong>Docker installer</strong></a> and following the instructions provided by the installer.</p><p>To confirm the installation we will run the following command in the terminal.</p><pre>$ docker -v    //Prints the version of the Docker</pre><p>Docker come with n number commands and flags that we can use in combination to perform certain task.</p><h4>Creating an NodeJS application</h4><p>First, let’s create a project directory name node-application. In this directory create a <strong>package.json</strong> file that contains project information along with the dependencies.</p><pre>// package.json file</pre><pre>{  &quot;name&quot;: &quot;node-application&quot;,<br>   &quot;version&quot;: &quot;1.0.0&quot;,<br>   &quot;description&quot;: &quot;Dockerizing nodejs application&quot;,<br>   &quot;main&quot;: &quot;app.js&quot;,<br>   &quot;scripts&quot;: {    <br>         &quot;start&quot;: &quot;node app.js&quot;  <br>    },<br>   &quot;author&quot;: &quot;Codeuix&quot;,<br>   &quot;license&quot;: &quot;ISC&quot;,<br>   &quot;dependencies&quot;: {<br>     &quot;express&quot;: &quot;^4.16.4&quot;,<br>   }<br>}</pre><p>with the new <strong>package.json</strong> file, run npm install will generate <strong>package-lock.json</strong> file which will be copied to the docker image.</p><p>Then, create a <strong>app.js</strong> file defies our web application using <a href="https://expressjs.com/"><strong>Express.js</strong></a> framework:</p><pre>const express = require(&#39;express&#39;);</pre><pre>const PORT = 8080;</pre><pre>const app = express();</pre><pre>app.get(&#39;/&#39;, (req, res, next){<br>   res.send(&#39;Hello From Node application&#39;);<br>});</pre><pre>app.listen(PORT, () =&gt; console.log(`server listening to ${PORT}`));</pre><p>In the following steps, we’ll look at how we can run this application inside of a docker container by using an Docker image. First, we need to build a custom Docker image of our application.</p><h4>Creating a Dockerfile</h4><p>Create a file called Dockerfile:</p><pre>$ touch Dockerfile</pre><p>Dockerfile is used as an configuration file that defines instructions to be followed in order to build a Docker image.</p><p>Firstly, we need to do is define the image from which we will be building our application. Here we will mostly use the official image available from <a href="https://hub.docker.com/"><strong>Docker Hub</strong></a>.</p><pre>FROM node:7</pre><p>Next we need to create a directory inside the image that will hold our application code, which will we working directory of our application.</p><pre># Create app directory<br>WORKDIR /app</pre><p>The official node image comes with the Node.js and NPM preinstalled, so the next thing to do is install our application dependencies by copying package.json file inside Docker image and running command from inside the container.</p><pre># Copying package.json and package-lock.json using a wildcard<br>COPY package*.json ./</pre><pre># Install app dependencies<br>RUN npm install</pre><p>To package our application source code inside the Docker image, use the <strong>COPY </strong>instruction:</p><pre># Bundle app source<br>COPY . ./app</pre><p>To bind our application to port 8080, we’ll need to use <strong>EXPOSE</strong> instruction that will be mapped to the port by docker deamon:</p><pre>EXPOSE 8080</pre><p>Lastly, we will define the command that will run our application using <strong>CMD</strong> instruction which will define our runtime. Here we will use a basic npm start which will run node app.js to start our server:</p><pre>CMD [&quot;npm&quot;, &quot;start&quot;]</pre><p>Our Dockerfile will now look like this:</p><pre>FROM node:7</pre><pre># Create app directory<br>WORKDIR /app</pre><pre># Copy package.json and package-lock.json using a wildcard<br>COPY package*.json ./</pre><pre># Install app dependencies<br>RUN npm install</pre><pre># Bundle app source<br>COPY . ./app</pre><pre>EXPOSE 8080</pre><pre>CMD [&quot;npm&quot;, &quot;start&quot;]</pre><p>The <a href="https://docs.docker.com/engine/reference/builder/#usage">Dockerfile reference</a> explains more about instructions and commands available to implement for our application.</p><h4>Create dockerignore file</h4><p>create a .dockerignore file in the project directory with the following content:</p><pre>node_modules</pre><p>This file prevents Docker image from copying the node_modules from our system and prevents overwriting modules installed within our image.</p><h4>Building our Docker image</h4><p>Navigate to the project directory that contains our Dockerfile and run the following command to build our Docker image.</p><pre>$ docker build -t node-app .</pre><blockquote><strong>-t</strong> flag lets us to tag our image so it will be easier to find later using the <strong>docker images</strong> command.</blockquote><p>The build command needs two parameters namely image name and src path.</p><h4>Running the Docker Image</h4><p>We can run our image in the container in two ways:</p><p><strong>Interactive mode</strong>: In this mode a log of the running application will be displayed. We can use <strong>-it</strong> flag to run our application in this mode.</p><p><strong>Detached mode</strong>: This mode will run the application in the background and will output an id when executed, <strong>-d</strong> flag is used to run the application in detached mode.</p><p>The very important parameter of the run command is mapping the port of the application along with the port for the docker container to run.</p><pre>$ docker run -it -p 8000:8080 node-app //run app in interactive mode</pre><pre>$ docker run -d -p 8000:8080 node-app  //run app in detached mode</pre><p>ports are mapped by <strong>-p</strong> flag followed by the <strong>port</strong> 8000 for the application and <strong>port</strong> 8080 for docker container.</p><p><a href="https://medium.com/the-code-review/top-10-docker-commands-you-cant-live-without-54fb6377f481">Top 10 Docker CLI commands you can’t live without</a></p><h4><strong>Testing the application</strong></h4><p>To test if the app is running, by entering the URL <a href="http://localhost:8000/"><strong>http://localhost:8000</strong></a> in the browser will display <strong>hello world</strong> text.</p><p>you can display the list of running containers by running the command <strong>docker ps </strong>in the command prompt.</p><h4>Hot Reloading with Nodemon</h4><p>We will use <a href="https://nodemon.io/"><strong>nodemon</strong></a> package which will watch the files in the project directory. If any change is made to the files, nodemon will automatically restart our node application.</p><pre>FROM node:7</pre><pre># Create app directory<br>WORKDIR /app</pre><pre># install nodemon globally<br>RUN npm install nodemon -g</pre><pre># Copy package.json and package-lock.json using a wildcard<br>COPY package*.json ./</pre><pre># Install app dependencies<br>RUN npm install</pre><pre># Bundle app source<br>COPY . /app</pre><pre>EXPOSE 8080</pre><pre>CMD [&quot;nodemon&quot;, &quot;app.js&quot;]</pre><p>Building the image with using the Dockerfile in the above section will ensure that code is rebuilt when there is a change inside the app directory.</p><pre>$ docker build -t live-app .<br>$ docker run --rm -it -p 8001:8080 -v $(pwd):/app live-app</pre><blockquote><strong>if you get error will running the above command in replace $(pwd) with the relative path to your project folder</strong></blockquote><p><strong>-v</strong>(volume) flag will mount the files in the src path into the container via dest path so nodemon can actually work</p><p>All edits to app directory will trigger a rebuild and changes will be made available at <a href="http://localhost:8001/"><strong>http://localhost:8001</strong></a>.</p><p>Finally, here’s a <a href="https://github.com/nithinm50/nodeapp"><strong>github repo</strong></a> for all the work we’ve done!</p><h4>Overview</h4><p>Let’s summarize what we have accomplished till now.</p><p>We have seen what a docker is and who all can benefit by using it, created a simple node application and shipped the application into docker container using the set of instructions stored in Dockerfile.</p><p>Lastly, we learn’t how we can build, run and automatically rebuild, rerun an application from inside a docker container.</p><p>Let us know what you felt about this article in the comments below. To learn more visit the official <a href="https://docs.docker.com/">docker documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8950f176ec4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing your front-end development workflow using Gulp 4]]></title>
            <link>https://medium.com/@uix/enhancing-your-front-end-development-workflow-using-gulp-4-51c5d265c1bd?source=rss-56a665c48bdf------2</link>
            <guid isPermaLink="false">https://medium.com/p/51c5d265c1bd</guid>
            <category><![CDATA[sass]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[gulp]]></category>
            <dc:creator><![CDATA[Codeuix]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 13:54:38 GMT</pubDate>
            <atom:updated>2019-04-29T13:54:38.053Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2pxhVpbEvQWLz0DQzSta0A.png" /><figcaption>Automating front-end development tasks using Gulp 4</figcaption></figure><p>In this Article we will setup a sample project and implement the following tasks which will help us in speeding up the development process.</p><ul><li>Initializing the server</li><li>Reloading the browser automatically when changes are made to a file.</li><li>Using Scss preprocessor to convert Scss file to CSS file.</li><li>Optimizing CSS, JavaScript and images.</li><li>Auto prefixing to write vendor-free CSS</li></ul><h4><strong>What is Gulp?</strong></h4><p>Gulp is a JavaScript toolkit which helps you in implementing multiple front end tasks during web development, it can be used to do wide range of things which can help you in reducing the development time. You can create your own customized build process that suits your development needs.</p><h4><strong>Installing Gulp</strong></h4><p>Before we install gulp you need to have Node.js (Node) installed in your computer.</p><p>If Node.js is not already installed in your computer, you can download the <a href="https://nodejs.org/en/">installer from Node’s website</a>.</p><p>Once we’re done with installing Node, you can install Gulp using the following code in the command line tool.</p><pre>// for windows users<br>npm install gulp -g</pre><pre>// for mac users<br>sudo npm install gulp -g</pre><blockquote>Note: Mac users should prepend the keyword <strong>sudo</strong> before the command in order for command to execute as administrator.</blockquote><p>The <strong>npm install</strong> syntax used in the command specify to install Gulp onto your system using Node Package Manager (npm).</p><p>The <strong>-g</strong> flag specifies npm to install the Gulp package globally on your system, which will allow you to access the gulp command anywhere on your system.</p><p>Now that we have install Gulp, let’s create a project that uses Gulp.</p><h4><strong>Creating a Project</strong></h4><p>Firstly, let’s create a folder called <strong>Gulp4</strong> to serve as our project root. Run the following command from inside the directory to initialize the project.</p><pre>//initialize the project<br>npm init </pre><p>The above command creates a file named <strong>package.json</strong> which stores all the information about the project, like the dependencies used in the project, scripts to execute particular command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*zTSGupdWBFp5Sqe0EUwuyA.png" /></figure><p><strong>npm init</strong> will prompt you the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*EvZlypgtqiiMOFy1gwzC8g.png" /></figure><p>After creation of package.json file, install gulp in your project using the following command.</p><pre>npm install gulp --save-dev</pre><p>Here we are installing Gulp as development dependency instead of installing it globally.</p><p>The keyword –save-dev will install the package and append the package name under dev dependency in package.json file.</p><p>After the command execution is finished view your project folder, you will find a new folder name <strong>node_modules</strong> created. You will also find gulp folder inside node_modules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*Mvk7k6Kcp7JoGNgfKgecfw.png" /></figure><p>Now we’re ready to start working with the Gulp. Before we do so, let’s decide on how we are going to use the gulp in the project, and directory structure of the project.</p><h4><strong>Determining Folder Structure of the Project</strong></h4><p>Gulp can flexible enough to work with any folder structure, for this article we will use the structure as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iO0fZZKj9V6eizntuY5kCA.png" /></figure><blockquote>In this structure, we will use <strong>src</strong> folder for development purposes, while <strong>dist</strong> (as in “distribution”) folder containing the optimized files for product site.</blockquote><p>We should keep project structure in mind while we work on our Gulp configurations. Now, we will create a gulp task in <strong>gulpfile.js</strong> file which will store all Gulp configurations.</p><h4><strong>Creating our first Gulp Task</strong></h4><p>Firstly, we will require gulp in <strong>gulpfile.js</strong></p><pre>const gulp = require(&#39;gulp&#39;);</pre><p>Let’s create gulp task named hello which says “<em>hello from gulp</em>”</p><pre>gulp.task(&#39;hello&#39;, function (done) {</pre><pre>console.log(&#39;hello from gulp&#39;);</pre><pre>done();</pre><pre>});</pre><p>The command line will return a log that outputs <strong>hello from gulp </strong>when the command <strong>gulp hello</strong> is executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EmwxCmbEn5jZtbWQVTYtpQ.png" /></figure><p>Gulp tasks are usually more complex that this, it contains additional Gulp methods and Gulp plugins.</p><p>Here’s what a real task will look like:</p><pre>gulp.task(&#39;task-name&#39;, function () {   <br>   return gulp.src(&#39;source-files&#39;)  //Get source files<br>          .pipe(aGulpPlugin())     //Send it through a gulp plugin<br>          .pipe(gulp.dest(&#39;destination&#39;))  //Output to destination<br>})</pre><p><strong>gulp.src</strong> will tell the Gulp task what files to use for the task, while <strong>gulp.dest</strong> tells Gulp where to output the files after completion of the task.</p><h4>Preprocessing with Gulp</h4><p>We can compile Sass to CSS in Gulp with the use the plugin gulp-sass. Firstly, install the plugin as dev dependency using the following command.</p><pre>npm install gulp-sass --save-dev</pre><p>We will have to require gulp-sass from node_modules folder before we can use the plugin.</p><pre>const sass = require(&#39;gulp-sass&#39;);</pre><p>Create a task named sass which compile scss file from the source and create a css file in the destination.</p><pre>gulp.task(&#39;sass&#39;, function () {   <br>   return gulp.src(&#39;src/scss/main.scss&#39;)<br>          .pipe(sass())<br>          .pipe(gulp.dest(&#39;src/css&#39;)) <br>})</pre><p>Now let’s edit main.scss file and add a sass function.</p><pre>//main.scss</pre><pre>$primary-color:#6c63ff;<br>$font: &#39;lato&#39;;</pre><pre>body{<br>  background: $primary-color;<br>  font-family: $font;<br>  p{<br>    color: #ffffff;<br>  }<br>}</pre><p>If you run <strong>gulp sass</strong> in command line, you could see a new main.css file was created in src/assets/css. In addition you can view the compiled code written in the css file.</p><pre>//main.css</pre><pre>body{<br>  background: #6c63ff;<br>  font-family: &#39;lato&#39;;<br>}</pre><pre>body p{<br>   color: #ffffff;<br>}</pre><p>That’s great, we are now able to compile sass file to css file.</p><p>There are times when we want to compile using multiple Scss file into a single CSS file, we implement this by using regular expressions that specifies path also known as node globs.</p><h4>Using Node Globs</h4><p>Globs are used for matching patterns in files that allows you to add more than one file into <strong>gulp.src</strong>.</p><p>There are 4 different globbing patterns used in the workflow.</p><ol><li>*.scss: The * pattern is a wildcard that matches any file ending with “ <strong>.scss ”</strong> in directory.</li><li>**/*.scss: this version * pattern matches any file ending with .scss in root folder and any child directories.</li><li>!not.scss: the ! indicates gulp to exclude from its matches.</li><li>*.+(scss|sass): the plus+ and parentheses () allows to match multiple patterns, which different pattern separated by pipe | Character.</li></ol><p>Since we are aware of globs, we can replace src/scss/main.scss with a src/scss/**/*.scss pattern which matches any file with a .scss extension in /scss or a child directory.</p><pre>gulp.task(&#39;sass&#39;, function () {   <br>   return gulp.src(&#39;src/scss/*.scss&#39;)<br>          .pipe(sass())<br>          .pipe(gulp.dest(&#39;src/css&#39;)) <br>})</pre><p>Now we can have multiple scss files that can be compiled to a css file by running <strong>gulp sass </strong>command.</p><h4>Watching sass file for changes</h4><p>Gulp provides you a method called which will watch for the changes in the file and execute certain function when a change is detected.</p><p>We will watch for any changes in scss file.</p><pre>gulp.watch(&#39;src/scss/**/*.scss&#39;, gulp.series(&#39;sass&#39;));</pre><p>Here we will create gulp task named watch and place the watch method that needs to be watched, list can contain multiple watch processes.</p><pre>gulp.task(&#39;watch&#39;, function() {<br>    gulp.watch(&#39;src/scss/**/*.scss&#39;, gulp.series(&#39;sass&#39;));<br>})</pre><p>Now run <strong>gulp watch</strong> in command line which will start watching for changes in scss files, when a change is made to the file it will automatically compile the scss to css.</p><h4>Using Vendor free CSS</h4><p>We can add vendor free css automatically while compiling scss to css by using gulp plugin called <strong>gulp-prefixer</strong>.</p><p>Installing the gulp plugin.</p><pre>npm install gulp-autoprefixer --save-dev</pre><p>Now let’s alter sass task to add vendor free css.</p><pre>const autoprefixer = require(&#39;gulp-autoprefixer&#39;);<br>gulp.task(&#39;sass&#39;, function () {   <br>   return gulp.src(&#39;src/scss/*.scss&#39;)<br>          .pipe(sass())<br>          .pipe(autoprefixer())<br>          .pipe(gulp.dest(&#39;src/css&#39;))<br>});</pre><p>Running <strong>gulp sass</strong> will compile scss to css and add vendor free css.</p><h4>Live-reloading using Browser Sync</h4><p>Browser Sync will help us make web development easier by spinning up the server that allows us to do live reloading easily.</p><p>Let’s start by installing browser sync as dev dependency.</p><pre>npm install browser-sync --save-dev</pre><p>After finishing the installation, we can start configuring gulp task for starting the server in gulpfile.js file.</p><pre>const browserSync = require(&#39;browser-sync&#39;).create();</pre><pre>gulp.task(&#39;serve&#39;, function(){<br>     browserSync.init({<br>         server: &#39;src&#39;,<br>         port: 4000<br>     });<br>})</pre><p>When we run <strong>gulp serve</strong> in command line the application will served in the respective port via the browser.</p><p>We will change our sass task slightly so Browser Sync can inject updated css styles into the browser.</p><pre>gulp.task(&#39;sass&#39;, function () {   <br>   return gulp.src(&#39;src/scss/**/*.scss&#39;)<br>          .pipe(sass())<br>          .pipe(autoprefixer())<br>          .pipe(browserSync.reload{<br>               stream:true<br>           })<br>          .pipe(gulp.dest(&#39;src/css&#39;))<br>});</pre><p>Now we will configure the task that will watch for changes in sass files and reload the browser accordingly.</p><p>Step 1: creating browser reload function</p><pre>//Browser Reload Function<br>gulp.task(&#39;reload&#39;, function(done){<br>    browserSync.reload();<br>    done();<br>})</pre><p>Step 2: altering watch function to reload the browser</p><pre>gulp.task(&#39;watch&#39;, function() {<br>    gulp.watch(&#39;src/scss/**/*.scss&#39;, gulp.series(&#39;sass&#39;,&#39;reload&#39;));<br>})</pre><p>Final step: create a live-server function.</p><pre>gulp.task(&#39;live-server&#39;, gulp.series(&#39;serve&#39;, &#39;watch&#39;);</pre><p>Executing the command <strong>gulp live-server</strong> will start the server and reload the browser when a change is detected in any of the assets.</p><h4>Optimizing the JavaScript and CSS files.</h4><p>One of the major focus of the developer during production phase would be optimize the assets so the site can load faster, we can achieve this by minification.</p><p>Let’s assume we have included 2 script tags in index.html</p><pre>&lt;body&gt;</pre><pre>    &lt;!-- build:js js/main.min.js --&gt;</pre><pre>    &lt;script src=&quot;js/main.js&quot;&gt;&lt;/script&gt;</pre><pre>    &lt;script src=&quot;js/custom.js&quot;&gt;&lt;/script&gt;</pre><pre>    &lt;!-- endbuild --&gt;</pre><pre>&lt;/body&gt;</pre><p>We will use the gulp plugin called <strong>gulp-useref</strong> which concatenates any number of css and JavaScript files into a single file by looking for a comment that starts with “&lt;! — build” and ends with “&lt;! — endbuild — &gt;”. Its syntax is:</p><pre>&lt;-- build:&lt;type&gt; &lt;path&gt; --&gt;</pre><pre>.............................( Html markup code for scripts )</pre><pre>&lt;!—endbuild --&gt;</pre><blockquote><strong>&lt;type&gt;</strong> can be either js, css. It is necessary to set the type of file we are trying to concatenate.</blockquote><blockquote><strong>&lt;path&gt;</strong> refers to the target path of the generated file.</blockquote><p>setting up useref task which is similar to all other tasks we’ve done so far.</p><pre>const useref = require(&#39;gulp-useref&#39;);</pre><pre>gulp.task(&#39;useref&#39;, function(){<br>   return gulp.src(&#39;src/*.html&#39;)<br>       .pipe(useref())<br>       .pipe(gulp.dest(&#39;dist&#39;))<br>});</pre><p>Now let’s run <strong>useref </strong>task, Gulp will go through the 2 scripts and concatenate them into <strong>dist/js/main.min.js</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*0UiIqvHAinmj8_eB4hYcrg.png" /></figure><p>Let’s minify the JavaScript files by using <strong>gulp-uglify</strong> plugin and second plugin called <strong>gulp-if</strong> to ensure we only attempt to minify JavaScript files.</p><p>Installing the plugin</p><pre>npm install gulp-uglify gulp-if --save-dev</pre><p>Modify <strong>useref</strong> task that minifies the JavaScript files in <strong>src</strong> folder.</p><pre>const uglify = require(&#39;gulp-uglify&#39;);<br>const gulpif = require(&#39;gulp-if&#39;);</pre><pre>gulp.task(&#39;asset-opt&#39;, function(){<br>   return gulp.src(&#39;src/*.html&#39;)<br>       .pipe(useref())<br>       .pipe(gulpif(&#39;*.js&#39;, uglify()))<br>       .pipe(gulp.dest(&#39;dist&#39;))<br>});</pre><p>Minifying css files using <strong>gulp-csso</strong> plugin.</p><pre>const gulpif = require(&#39;gulp-if&#39;);</pre><pre>gulp.task(&#39;asset-opt&#39;, function(){<br>   return gulp.src(&#39;src/*.html&#39;)<br>       .pipe(useref())<br>       .pipe(gulpif(&#39;*.js&#39;, uglify()))<br>       .pipe(gulp.dest(&#39;dist&#39;))<br>});</pre><h4>Copying files to Dist</h4><p>Let’s consider there is folder name fonts inside <strong>src</strong> folder that contains all the fonts used in the project.</p><p>now create a function that copies the files from src to dist</p><pre>gulp.task(&#39;fonts&#39;, function(){<br>   return gulp.src(&#39;src/fonts/**/*&#39;)<br>         .pipe(gulp.dest(&#39;dist&#39;))<br>});</pre><p>running the command <strong>gulp fonts</strong> will copy the files to dist folder.</p><h4>Combining Gulp tasks</h4><p>Let’s combine two or more task that needs to executed simultaneously, so particular task can be used in different occasions.</p><p>First set of task is for production, here we optimize all the assets files and copy the files from src to dist.</p><p>Create a task named build that combines two tasks named <strong>useref</strong> which optimizes files and <strong>fonts</strong> which copies the files to dist.</p><pre>gulp.task(&#39;build&#39;, gulp.series(&#39;useref&#39;, &#39;fonts&#39;));</pre><p><strong>gulp build </strong>command will create dist folder with all the optimized assets for production site.</p><p>Second set of task is for development, here we compile sass to css, watch for any changes in the sass files and reload the browser using browser sync.</p><p>we will create a default gulp function that combines two tasks named <strong>serve</strong> and <strong>watch</strong>.</p><pre>gulp.task(&#39;default&#39;, gulp.series(&#39;serve&#39;,&#39;watch&#39;));</pre><p>Now run gulp default function by executing the command <strong>gulp</strong>, which will compile the files and serve it in the browser for development purpose.</p><p>Finally, here’s a <a href="https://github.com/nithinm50/gulp4"><strong>github repo</strong></a> for all the work we’ve done!</p><h4>Conclusion</h4><p>We’ve seen the basic working of Gulp and created a workflow that’s will compile Scss into CSS while watching files for changes at the same time. We can run this task with the <strong>gulp</strong> command.</p><p>we’ve built a second task named build that create a dist folder for production site, we compiled sass to css, optimize all the assets and copy necessary folder to <strong>dist</strong> folder. we can run this task by typing <strong>gulp build</strong> in the command line.</p><p>The workflow we’ve created is enough for most web developers. Gulp has lot more to offer and make the development process more efficient. Here are some ideas that we can implement:</p><p>For Development:</p><ul><li>Creating sprites with <a href="https://www.npmjs.com/package/sprity"><strong>sprity</strong></a></li><li>Compiling the files for which changes were made with <a href="https://www.npmjs.com/package/gulp-changed"><strong>gulp-changed</strong></a></li><li>Writing Javscript with the latest syntax with <a href="https://www.npmjs.com/package/Babel"><strong>Babel</strong></a> or <a href="https://www.npmjs.com/package/traceur"><strong>Traceur</strong></a></li><li>Generating Modernizr script automatically with <a href="https://www.npmjs.com/package/gulp-modernizr"><strong>gulp-modrenizr</strong></a></li><li>Using template engines like <a href="https://www.npmjs.com/package/pug"><strong>Pug</strong></a> to modularize HTML</li></ul><p>For Optimization:</p><ul><li>Removing usnused CSS with <a href="https://www.npmjs.com/package/uncss"><strong>unCSS</strong></a></li><li>Generating inline CSS with <a href="https://www.npmjs.com/package/critical"><strong>critical</strong></a> to improve the performance</li></ul><p>Let us know what you felt about the article in the comments below. If you have any questions on workflow. We’ll be happy to reply!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51c5d265c1bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>