<?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: Dan Englishby</title>
    <description>The latest articles on DEV Community by Dan Englishby (@danenglishby).</description>
    <link>https://dev.to/danenglishby</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%2F143451%2Fd7c08fbf-cd2a-4e00-98b7-c53e4fc43b83.jpg</url>
      <title>DEV Community: Dan Englishby</title>
      <link>https://dev.to/danenglishby</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danenglishby"/>
    <language>en</language>
    <item>
      <title>The Complete JSON Tutorial – Quickly Learn JSON</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Tue, 26 May 2020 10:51:25 +0000</pubDate>
      <link>https://dev.to/danenglishby/the-complete-json-tutorial-quickly-learn-json-14b9</link>
      <guid>https://dev.to/danenglishby/the-complete-json-tutorial-quickly-learn-json-14b9</guid>
      <description>&lt;p&gt;JavaScript Object Notation or more commonly known as it’s abbreviated name JSON is extensively used throughout all kinds of applications. Its purpose is to streamline communications, most commonly between a browser and a server. Although having said this, it’s perfectly normal for this to work the opposite way around too.&lt;/p&gt;

&lt;p&gt;You will inevitably fall upon JSON one time or another during your developer journey and this article hopes to give you a content-know-how to work with it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Some Background&lt;/li&gt;
&lt;li&gt;A Basic Introduction&lt;/li&gt;
&lt;li&gt;JSON Data Types&lt;/li&gt;
&lt;li&gt;JSON Formatting&lt;/li&gt;
&lt;li&gt;Basic Example&lt;/li&gt;
&lt;li&gt;Nested JSON&lt;/li&gt;
&lt;li&gt;Advanced Example&lt;/li&gt;
&lt;li&gt;Managing JSON With JavaScript&lt;/li&gt;
&lt;li&gt;Working With The Console&lt;/li&gt;
&lt;li&gt;Summary&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Some Background
&lt;/h3&gt;

&lt;p&gt;JSON is a major part of the JavaScript programming language, it uses go far and beyond the imaginable eye. Discovered in March 2001 and Catering for over 40 languages, yes 40! JSON, with the right library, can be used in almost every programming language you’ve heard of. &lt;/p&gt;

&lt;p&gt;This technology even has its own &lt;a href="https://www.json.org/"&gt;website&lt;/a&gt;, which lists all the libraries that can bootstrap your application with JSON. In addition, there are some technical diagrams to provide an insight into how this great communication helper works.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Basic Introduction
&lt;/h3&gt;

&lt;p&gt;JSON is quite easy to use when you get your head around it, it’s nothing more than simple text structured in a certain way. If you’ve never seen it in the flesh before, then this is a good time to show a small example. Here is what it can look like –&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SiteName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;CodeWall&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ArticleName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;JSON Tutorials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Revision&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see from the example, it’s just as stated, simple text, formatted with quotations, separated by colons and comma’s and completely wrapped in some braces. It can get more advanced with bigger data, but we will go through that in detail within this article too.&lt;/p&gt;

&lt;h3&gt;
  
  
  JSON Data Types
&lt;/h3&gt;

&lt;p&gt;JavaScript Object Notation can handle nearly every data type you could possibly need it too. This, of course, makes it an extremely powerful tool, being able to handle arrays and objects in itself is super-cool. Let’s go through the data types with some small examples showing how they would look in a working application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;StringDataType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;String&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Object&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ObjectDataType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;myObj&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ObjectData&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Array&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ArrayDataType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Number&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NumberDataType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Boolean&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BooleanTrueDataType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BooleanFalseDataType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Date&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DateStringDataType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2011-07-14 19:43:37 +0100&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;JavaScriptDateDataType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1310669017000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  JSON Formatting
&lt;/h3&gt;

&lt;p&gt;There are some strict rules when it comes to formatting JavaScript Object Notation and if not adhered too, expect your code to fall over.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule #1. Key/Identifier &amp;amp; Value&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSON consists of 2 main elements, a key, and a value. No matter the data type, it needs to be in this format. The key you specify will ultimately be used to access the value later on within your application or on the alternative consumer end.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0nzpwfth--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/key-value-json.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0nzpwfth--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/key-value-json.jpg" alt="key value json"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule #2. Key/Identifier Double Quoted&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, you may get away with it in JavaScript, but with JSON, you can’t. Every identifier or key you specify in a JSON object must be double-quoted, essentially making it a &lt;code&gt;String&lt;/code&gt; type. It may be hard to rid habits of not having to do this, but it soon falls into place.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XEV8BdGx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/double-quote-json.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XEV8BdGx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/double-quote-json.jpg" alt="double quoted format"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule #3. Wrap Objects In Curly Braces&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Whether you have one object or fifty in your JSON code, each object needs to be wrapped inside curly braces, specifying the start and the end of each object inside. This is extremely important, especially to interpreters, if these are missed, you will soon be alerted about it!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WfUuomL9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/object-curly-braces.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WfUuomL9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/object-curly-braces.jpg" alt="object curly braces"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule #4. Separate Key/Value by Colons&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data within JSON must be separated out, to do this, a simple colon is sufficient, it goes straight after the key or identifier statement and just before the value. This is another imperative concept which you will see the importance when logging data to the console, which is explained later in this tutorial.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2pHtGbDy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/key-value-separator.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2pHtGbDy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/key-value-separator.jpg" alt="key value separator"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule #5. Arrays Are To Be Treated Like Arrays&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When using arrays within JSON, treat them exactly the same as you would do in normal JavaScript syntax. Whether that be a string or numeric array, the same rules apply.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5nb6RTvg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/json-array-data-type-example.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5nb6RTvg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/json-array-data-type-example.jpg" alt="array data type example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule #6. Encapsulate Objects With Square Brackets (Array)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Multiple objects must sit in an array, giving you what is called an Array Of Objects, this will be used when you have advanced data that you need to communicate to the front-end or the back-end. Notice the bracket-syntax highlighted in blue within the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V9AU1Zgg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/object-array-example.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V9AU1Zgg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/object-array-example.jpg" alt="object array example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule #7. Objects &amp;amp; Data Separated By Commas&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No doubt you will end up working with multiple object JSON in your lifetime, they must be separated correctly, with a simple comma each time. Similarly, data must be separated out with commas too, let’s see this in action with a bit more of an advanced JSON snippet. The important syntax is highlighted in blue for visual understanding.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i0r5m71u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/comma-separation-example.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i0r5m71u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/comma-separation-example.jpg" alt="comma separation example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Example
&lt;/h3&gt;

&lt;p&gt;Now that we’ve gone through the main rules of JSON, it’s time for an example with a range of data types. Feel free to use the following code for your own learning, it will be a great reference or starting point. In this example, these four data-types are present –&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  String&lt;/li&gt;
&lt;li&gt;  Integer&lt;/li&gt;
&lt;li&gt;  Decimal&lt;/li&gt;
&lt;li&gt;  Boolean
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Article&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tutorial&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Author&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dan Englishby&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YearPublished&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2018&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;IsPublished&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;AverageWordsPerSentce&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;20.3&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Nesting
&lt;/h3&gt;

&lt;p&gt;Ok, so JSON can become pretty complicated in terms of data-load and that’s why nesting is a key factor to this technology. When you have tons of data to communicate, nesting is a beautiful art. Within the following example, nesting down to two levels is shown because, in theory, nesting is endless. Therefore, knowing how to do it will inevitably come in handy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do we nest objects?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Nesting objects are achieved by creating an Array-of-objects within a JSON property. See the following example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;OuterObject&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NestedObjects&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SomeName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SomeValue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SomeName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SomeValue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SomeName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SomeValue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;}]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How do we nest arrays?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similarly, we can nest arrays, and it’s pretty simple too. The only problem with doing it, is you lose the ability to specify the array’s data with identifier or keys. This is because the nested array will be identified with a numeric index rather than a key-value pair.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;OuterObject&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NestedArray&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="p"&gt;[&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SomeValue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                &lt;span class="p"&gt;],&lt;/span&gt;
                &lt;span class="p"&gt;[&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SomeValue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                &lt;span class="p"&gt;],&lt;/span&gt;
                &lt;span class="p"&gt;[&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SomeValue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;}]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Advanced Examples
&lt;/h3&gt;

&lt;p&gt;See the following examples that use nested concepts to section out data. The property &lt;strong&gt;Articles&lt;/strong&gt; holds a nested set of article names, in addition, it holds the next nested set of data, &lt;strong&gt;Shared On&lt;/strong&gt;, which again nests social network names.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advanced Example #1&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Category&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tutorials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Articles&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ChartJS Lesson 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shared On&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Facebook&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Twitter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Google+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ChartJS Lesson 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shared On&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Facebook&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Twitter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Google+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;

            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ChartJS Lesson 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shared On&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Facebook&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Twitter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Google+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ChartJS Lesson 4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shared On&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Facebook&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Twitter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SocialNetwork&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Google+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above example shows how to nest objects, but you can also nest arrays too, having an array-of-arrays is perfectly normal. It all depends on what your specific needs are. The following example shows the &lt;strong&gt;Shared On&lt;/strong&gt; property holding an array of social network names.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advanced Example 2&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Category&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tutorials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Articles&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ChartJS Lesson 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shared On&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Facebook&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Twitter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Google+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Managing JSON With JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript works super-fluently with JSON, which of course it does, JS did create it! Managing data within JS can be done in numerous ways, from storing variables to finally accessing the data. In this section, we will learn how to do each one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Storing JSON In A JavaScript Variable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you’ve already worked with JavaScript before, I know this will be teaching you to suck eggs, but for the readers who haven’t see the example below –&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Storing as a variable&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Article&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tutorial&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Author&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dan Englishby&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YearPublished&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2018&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;IsPublished&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;AverageWordsPerSentce&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;20.3&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Yep, it’s as simple as that, you’ve just stored your first JSON data-set in a JS variable!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Accessing the data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Accessing JSON values can be done in two ways&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Dot Notation Style&lt;/li&gt;
&lt;li&gt;  Bracket Notation Style&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dot Notation Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the variable we created in the last example, we can now access the values with the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;articleName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Article&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// variable is now "Tutorial"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Bracket Notation Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;articleName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Article&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// variable is now "Tutorial"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Working With The Console
&lt;/h3&gt;

&lt;p&gt;Visualizing the data, you create in JSON is quite important to understand it even further, once you see it properly logged into a console, it makes such a difference. All we need to successfully log data to the console is first, a browser with the console facility and secondly some JavaScript.&lt;/p&gt;

&lt;p&gt;Browsers such as Google Chrome, Internet Explorer, Firefox all have this functionality, so If you haven’t got one of them already, go download one and then come back to this part of the tutorial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do I see the console?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The good news here is that to expose the console in most browsers is done by the exact same method. Use the following steps to find your console.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Right click on the web page.&lt;/li&gt;
&lt;li&gt; Find the Inspect Element option.&lt;/li&gt;
&lt;li&gt; Click it.&lt;/li&gt;
&lt;li&gt; After the new window opens, find the sub-headed Console window and click it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;See chromes console in the image below –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lnoM4gTa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/chrome-console-example.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lnoM4gTa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/chrome-console-example.jpg" alt="chrome console example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logging to the console&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we’ve discovered the console, let’s use it, add the following code to your JavaScript and reload the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Article&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tutorial&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Author&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dan Englishby&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YearPublished&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2018&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;IsPublished&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;AverageWordsPerSentce&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;20.3&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iJ03ckCQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/console-log-example.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iJ03ckCQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2018/08/console-log-example.jpg" alt="console log example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the JSON created within the JavaScript has been nicely logged to the Google Chrome console. It’s sectioned and colored beautifully so you can quickly-visually understand it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Within this tutorial, all aspects of working with JSON were covered, hopefully giving you the knowledge to go and play with it and learn even more. With a little practice, you will become fluent with it too and then start daring to work with some really complicated nested JSON. As I mentioned before, knowing these concepts will be invaluable to your tool-set because there are so many libraries and API’s that use it.&lt;/p&gt;

&lt;p&gt;I’ve logged all the examples within this tutorial to the console, so you can see them all in their full glory. Right-click, inspect element and click the console window to see them.&lt;/p&gt;

&lt;p&gt;Lastly, a great online tool that is extremely helpful in verifying that JSON is syntactically correct is the &lt;a href="https://jsonlint.com/"&gt;JSONLint interface&lt;/a&gt;, it’s free and very easy to use.&lt;/p&gt;

&lt;p&gt;Hope it helps, thanks for reading!&lt;/p&gt;

&lt;p&gt;This post is cross-posted from my blog - &lt;a href="https://www.codewall.co.uk/the-complete-json-tutorial-quickly-learn-json/"&gt;CodeWall JSON Tutorial&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>40 reasons why I love being a DEV!</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Tue, 26 May 2020 10:13:02 +0000</pubDate>
      <link>https://dev.to/danenglishby/40-reasons-why-i-love-being-a-dev-3hg6</link>
      <guid>https://dev.to/danenglishby/40-reasons-why-i-love-being-a-dev-3hg6</guid>
      <description>&lt;p&gt;Here’s my personal list of reasons why I love being a developer and always will. I hope you can share this list with people who aspire to be web developers or programmers and maybe, it will make them jump and give it go! Honestly, If you’re fed up with your current job, and it’s not in development, try being a developer, it’s awesome.&lt;/p&gt;

&lt;p&gt;The whole purpose of this post is to try to give non-developers a glimpse into the life of what it’s like to be a developer. From there, you can make your own mind up!&lt;/p&gt;

&lt;h2&gt;
  
  
  Reasons why being a developer is awesome
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; Learning something new pretty much every day.&lt;/li&gt;
&lt;li&gt; Being challenged every day whether that be a simple bug fix, to something big like a new project.&lt;/li&gt;
&lt;li&gt; Being able to see technology make life easier.&lt;/li&gt;
&lt;li&gt; Taking part in a fast-moving industry that never ceases to amaze you.&lt;/li&gt;
&lt;li&gt; Lots of coffee.&lt;/li&gt;
&lt;li&gt; Discovering new open-sourced (free) tools &amp;amp; resources to work with consistently – thanks to GitHub.&lt;/li&gt;
&lt;li&gt; The opportunity to be creative with your own ideas.&lt;/li&gt;
&lt;li&gt; Being part of a global industry where everyone knows that arrays start at zero :).&lt;/li&gt;
&lt;li&gt; With the right dedication and consistency, you can learn yourself to be a pro at this type of work.&lt;/li&gt;
&lt;li&gt; Pretty decent money, especially for something you love.&lt;/li&gt;
&lt;li&gt; More coffee.&lt;/li&gt;
&lt;li&gt; There is always room to learn more.&lt;/li&gt;
&lt;li&gt; Technology is the future, and it will be here for a long, long time.&lt;/li&gt;
&lt;li&gt; No worries about the development industry disappearing.&lt;/li&gt;
&lt;li&gt; It’s great fun and there is definitely lots of coffee.&lt;/li&gt;
&lt;li&gt; The only job that you can eat a chocolate cake for breakfast and now be frowned upon. (Devs need much sugar)&lt;/li&gt;
&lt;li&gt; Using beautiful coding software like Visual Studio.&lt;/li&gt;
&lt;li&gt; Learning to interface applications with just about anything these days.&lt;/li&gt;
&lt;li&gt; This one is hard to believe… Actually not being too bothered about going to work.&lt;/li&gt;
&lt;li&gt; Realizing that StackOverflow is my new Bible.&lt;/li&gt;
&lt;li&gt; Google is now my best friend.&lt;/li&gt;
&lt;li&gt; Appreciating, deeply, how much effort is used in things like Xbox Games &amp;amp; Virtual Assistants like Amazon’s Alexa.&lt;/li&gt;
&lt;li&gt; The only job that you and your colleagues can get over-excited when you reduce 6 lines of code to 1.&lt;/li&gt;
&lt;li&gt; Maintaining and being proud of my 80 words per minute typing speed.&lt;/li&gt;
&lt;li&gt; Red Bull.&lt;/li&gt;
&lt;li&gt; Making time-consuming tasks super fast.&lt;/li&gt;
&lt;li&gt; Having a good reason to actually be on Twitter. Ahem, follow me – &lt;a href="https://twitter.com/DanEnglishby"&gt;@DanEnglishby&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; Developing things that quite possibly have the potential to change the world.&lt;/li&gt;
&lt;li&gt; Seeing the look on the client’s faces when they get their software/website or another technical resource!&lt;/li&gt;
&lt;li&gt; My nan telling everyone I’m a genius because I’m a coder.&lt;/li&gt;
&lt;li&gt; Being able to take my laptop to a beach and write code (Yep I did this once).&lt;/li&gt;
&lt;li&gt; Having the skills to become a freelancer or start my own business easily.&lt;/li&gt;
&lt;li&gt; Being able to just look at a website and pretty much figure out how it was made.&lt;/li&gt;
&lt;li&gt; Caring about what color my IDE theme is. (Dark, of course)&lt;/li&gt;
&lt;li&gt; Having a genuinely fulfilling career.&lt;/li&gt;
&lt;li&gt; Taking pride in telling people why Internet Explorer is useless and Google Chrome is superior.&lt;/li&gt;
&lt;li&gt; Having great job security, there are always jobs available for developers.&lt;/li&gt;
&lt;li&gt; Being passionate about what I do.&lt;/li&gt;
&lt;li&gt; There is how-to-guides to build or learn just about anything.&lt;/li&gt;
&lt;li&gt; Did I mention there is lots of coffee?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Summing Up
&lt;/h3&gt;

&lt;p&gt;I hope you enjoyed my reasons as to why being a web developer or programmer is awesome. I would love to hear your personal reasons as to why you love being a developer too! Please leave a comment with yours.&lt;/p&gt;

&lt;p&gt;Like my content? Feel free to check out my blog : &lt;a href="https://codewall.co.uk"&gt;CodeWall&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>MongoDB Beginner Tutorial With Compass GUI &amp; The Mongo Shell CLI</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Thu, 12 Dec 2019 20:11:09 +0000</pubDate>
      <link>https://dev.to/danenglishby/mongodb-beginner-tutorial-with-compass-gui-the-mongo-shell-cli-1kgc</link>
      <guid>https://dev.to/danenglishby/mongodb-beginner-tutorial-with-compass-gui-the-mongo-shell-cli-1kgc</guid>
      <description>&lt;p&gt;Original Article on : &lt;a href="https://www.codewall.co.uk/mongodb-beginner-tutorial-with-compass-gui-the-mongo-shell-cli/"&gt;https://www.codewall.co.uk/mongodb-beginner-tutorial-with-compass-gui-the-mongo-shell-cli/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Introduction.&lt;/li&gt;
&lt;li&gt;  Installation Guide.&lt;/li&gt;
&lt;li&gt;  Pre-requisites.&lt;/li&gt;
&lt;li&gt;  MongoDB Setup &amp;amp; Connecting To DB.&lt;/li&gt;
&lt;li&gt;  Downloading MongoDB.&lt;/li&gt;
&lt;li&gt;  Installing MongoDB &amp;amp; Connecting.&lt;/li&gt;
&lt;li&gt;  Compass for MongoDB Setup &amp;amp; Connecting To DB.&lt;/li&gt;
&lt;li&gt;  Downloading Compass for MongoDB.&lt;/li&gt;
&lt;li&gt;  Installing Compass for MongoDB.&lt;/li&gt;
&lt;li&gt;  The Data.&lt;/li&gt;
&lt;li&gt;  Link to Excel data file.&lt;/li&gt;
&lt;li&gt;  Managing Data With Compass (CRUD)&lt;/li&gt;
&lt;li&gt;  Creating a Database &amp;amp; Initial Collection.&lt;/li&gt;
&lt;li&gt;  Creating documents (data)&lt;/li&gt;
&lt;li&gt;  Viewing documents (data)&lt;/li&gt;
&lt;li&gt;  Updating documents (data)&lt;/li&gt;
&lt;li&gt;  Deleting documents (data)&lt;/li&gt;
&lt;li&gt;  Managing Data With MongoDB CLI (CRUD)&lt;/li&gt;
&lt;li&gt;  Creating a Database.&lt;/li&gt;
&lt;li&gt;  Creating a collection adding documents (data)&lt;/li&gt;
&lt;li&gt;  Inserting one document&lt;/li&gt;
&lt;li&gt;  Inserting multiple documents.&lt;/li&gt;
&lt;li&gt;  Viewing documents (data)&lt;/li&gt;
&lt;li&gt;  Updating documents (data)&lt;/li&gt;
&lt;li&gt;  Deleting documents (data)&lt;/li&gt;
&lt;li&gt;  Advanced functionality with MongoDB.&lt;/li&gt;
&lt;li&gt;  Projection.&lt;/li&gt;
&lt;li&gt;  Sort&lt;/li&gt;
&lt;li&gt;  Skip.&lt;/li&gt;
&lt;li&gt;  Limit&lt;/li&gt;
&lt;li&gt;  Indexing.&lt;/li&gt;
&lt;li&gt;  Aggregation.&lt;/li&gt;
&lt;li&gt;  BackUp.&lt;/li&gt;
&lt;li&gt;  Restore.&lt;/li&gt;
&lt;li&gt;  Import With mongoimport.exe.&lt;/li&gt;
&lt;li&gt;  Advanced Data With MongoDB.&lt;/li&gt;
&lt;li&gt;  Advanced MongoDB CLI Setup (Windows OS Only)&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;NoSQL is an emerging database technology that provides a non-relational structure of data. In this following document, key factors of getting started with NoSQL with a database container of MongoDB will be explored. In addition to installing and utilizing MongoDB, another piece of software will be used in Tandem with it too. Namely, Compass, MongoDB’s official GUI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation Guide
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pre-requisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Internet Connection&lt;/li&gt;
&lt;li&gt;  Windows Operating System PC/Laptop&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  MongoDB Setup &amp;amp; Connecting To DB
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Downloading MongoDB
&lt;/h3&gt;

&lt;p&gt;To download the latest version of MongoDB, follow the steps below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Go to &lt;a href="https://www.mongodb.com/download-center/community"&gt;https://www.mongodb.com/download-center/community&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Choose the current release from the version dropdown.&lt;/li&gt;
&lt;li&gt;  Select Windows 64-bit x64 from the OS dropdown.&lt;/li&gt;
&lt;li&gt;  Make sure MSI is the package selected.&lt;/li&gt;
&lt;li&gt;  Click download.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Installing MongoDB &amp;amp; Connecting
&lt;/h3&gt;

&lt;p&gt;To install MongoDB onto your computer/server follow the steps below.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; Locate and open the downloaded installation file.&lt;/li&gt;
&lt;li&gt; Double click and open.&lt;/li&gt;
&lt;li&gt; See the images below with arrow prompts to install.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E3i6iUCF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure1-mongo-db-setupwizard.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E3i6iUCF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure1-mongo-db-setupwizard.jpg" alt="figure 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 1. MongoDB SetupWizard Page1&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6MSgBxwf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure2-mongo-db-setupwizard-page2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6MSgBxwf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure2-mongo-db-setupwizard-page2.jpg" alt="figure 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 2. MongoDB SetupWizard Page2&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qrBc1BiM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure3-mongodb-setupwizard-page-3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qrBc1BiM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure3-mongodb-setupwizard-page-3.jpg" alt="figure 3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 3. MongoDB SetupWizard Page3&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2
&lt;/h4&gt;

&lt;p&gt;For this tutorial, MongoDB will be installed under the Network Service user, but alternatively, you can specify a local or domain user if required. For the latter, you must provide an Account Domain and Account Password.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Tick Install MongoDB as a service (This will ensure that MongoDB is online/running each time the computer is booted) Otherwise, it would need to be started manually.&lt;/li&gt;
&lt;li&gt; Tick run service as Network Service User.&lt;/li&gt;
&lt;li&gt; Leave the default service name of MongoDB so it’s easily recognized.&lt;/li&gt;
&lt;li&gt; Leave default data and log directory intact unless you must have it somewhere different.&lt;/li&gt;
&lt;li&gt; Click next.&lt;/li&gt;
&lt;li&gt; Make sure Install MongoDB Compass is &lt;strong&gt;unticked&lt;/strong&gt;, as this is to be installed manually later.&lt;/li&gt;
&lt;li&gt; Click next.&lt;/li&gt;
&lt;li&gt; Click Install.&lt;/li&gt;
&lt;li&gt; Wait for install to complete and click finish.&lt;/li&gt;
&lt;li&gt; Finally, open TaskManager and click the services tab or use windows key + R and type services.msc&lt;/li&gt;
&lt;li&gt; Try and locate the MongoDB service instance to make sure the installation was a success. See figure 4.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S-mI7hzl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure4-windows-services-mongodb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S-mI7hzl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure4-windows-services-mongodb.png" alt="figure 4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 4. Services. MongoDB&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3
&lt;/h4&gt;

&lt;p&gt;Note: If you want to undertake a more advanced setup to access the mongo shell, see Page 45, Advanced MongoDB CLI Setup (Windows OS Only).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Open the command prompt on your computer.&lt;/li&gt;
&lt;li&gt; Enter the following command – cd C:\Program Files\MongoDB\Server\4.0\bin (Or replace with the path of the MongoDB installation bin folder)&lt;/li&gt;
&lt;li&gt; Now type the following command – mongo&lt;/li&gt;
&lt;li&gt; You will now be connected to the MongoDB instance on the local machine. See the following reference on the mongo shell.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Compass for MongoDB Setup &amp;amp; Connecting To DB
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Downloading Compass for MongoDB
&lt;/h3&gt;

&lt;p&gt;Follow the steps below to download the free, community edition of Compass.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Go to the following download page URL for Compass &lt;a href="https://www.mongodb.com/download-center/compass?jmp=docs"&gt;https://www.mongodb.com/download-center/compass?jmp=docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; Pick the &lt;strong&gt;Community Edition Stable&lt;/strong&gt; version from the drop-down.&lt;/li&gt;
&lt;li&gt; Select Windows 64-bit (7+) from the platforms dropdown.&lt;/li&gt;
&lt;li&gt; Click the download button.&lt;/li&gt;
&lt;li&gt; Wait for the download to complete.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Installing Compass for MongoDB
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Step 1
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; Locate and launch the MongoDB Compass installer that was download earlier.&lt;/li&gt;
&lt;li&gt; Read the License Agreement and click agree if you are happy with the conditions.&lt;/li&gt;
&lt;li&gt; Navigate through the series of how-to panes until you reach the privacy setting window and tick/untick to your preference.&lt;/li&gt;
&lt;li&gt; Lastly, click Start Using Compass.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Step 2
&lt;/h4&gt;

&lt;p&gt;You should now be presented with the following page to set up the GUI software and connect to the MongoDB instance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LqqWBB9a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure5-mongodb-connection-wizard.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LqqWBB9a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure5-mongodb-connection-wizard.jpg" alt="figure 5"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 5. Compass Initial Setup&lt;/p&gt;

&lt;p&gt;Add the following parameters as follows&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Hostname: localhost or Remote ServerIP&lt;/li&gt;
&lt;li&gt; Port: 27017&lt;/li&gt;
&lt;li&gt; Leave the rest of the fields as their default and press connect.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After these three steps, the following page should have loaded within the software.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NttUzbag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure6-mongodb-connected-to-host.jpg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NttUzbag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure6-mongodb-connected-to-host.jpg.png" alt="figure 6"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 6. COMPASS Connected To Host&lt;/p&gt;

&lt;h2&gt;
  
  
  The Data
&lt;/h2&gt;

&lt;p&gt;The data that is going to be used for the purpose of this tutorial is a simple data set generated from the cool website &lt;a href="https://www.generatedata.com/"&gt;https://generatedata.com&lt;/a&gt;. The data consists of people, their first and last name, age, email, education, etc. In addition, It’s a flat data set that is perfect for MongoDB.&lt;/p&gt;

&lt;p&gt;It’s worth noting here that the Primary Key of id has been removed from the excel data set due to MongoDB’s default functionality of giving each document (row) a unique id of its own.&lt;/p&gt;

&lt;h3&gt;
  
  
  Link to Excel data file
&lt;/h3&gt;

&lt;p&gt;If you want to use the exact same data file that I have, then download the excel file below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.codewall.co.uk/assets/people.csv"&gt;People.csv&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing Data With Compass (CRUD)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Creating a Database &amp;amp; Initial Collection
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Step 1
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; Open up MongoDB Compass Community that was installed earlier.&lt;/li&gt;
&lt;li&gt; Connect to the MongoDB Server by specifying parameters as below

&lt;ol&gt;
&lt;li&gt; Hostname: localhost&lt;/li&gt;
&lt;li&gt; Port: 27017&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt; Click connect.&lt;/li&gt;
&lt;li&gt; From the loaded dashboard click the Create database button.&lt;/li&gt;
&lt;li&gt; The create database helper will be loaded, as shown in Figure 7.&lt;/li&gt;
&lt;li&gt; Specify the Database Name as peopledb&lt;/li&gt;
&lt;li&gt; Specify the Collection Name as people&lt;/li&gt;
&lt;li&gt; Click the Create Database button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QqT8yFOE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure7-create-database-helper.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QqT8yFOE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure7-create-database-helper.png" alt="figure 7"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 7. Create Database Helper&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating documents (data)
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;p&gt;Locate the People Database under the MyCluster Pane located on the left-hand pane and click it. You will be presented a screen as shown in Figure 8.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kyx78SS---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure8-people-database-view.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kyx78SS---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure8-people-database-view.jpg" alt="figure 8"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 8. People Database View&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;p&gt;Then progress to click on the earlier created collection, people, the software will then present a new dashboard of functions shown in Figure 9.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nIlpkekG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure9-people-collection-view.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nIlpkekG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/11/figure9-people-collection-view.jpg" alt="figure 9"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 9. People Collection Dashboard&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;Now to add some documents (data), proceed by clicking on the Insert Document button to open the insert document helper as shown in Figure 10.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lqfF4z0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure10-mongodb-compass-insert-document-helper.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lqfF4z0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure10-mongodb-compass-insert-document-helper.jpg" alt="figure 10"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 10. Insert Document Helper&lt;/p&gt;

&lt;p&gt;Using the data from People excel data set, fill out the key-value fields for the first row of data altering the data types with the right-hand dropdowns, after that press the insert button. See figure 11.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Al2PqrCe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure11-mongo-db-insert-document-example.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Al2PqrCe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure11-mongo-db-insert-document-example.jpg" alt="figure 11"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 11. Insert Document Data Example&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hover over the newly created document in the data pane, and hit the clone document button, this will replicate the data into another insert pane. From here, simply type in the next row of data from the excel file, no need to specify the field names or data types this time!&lt;/p&gt;

&lt;h3&gt;
  
  
  Viewing documents (data)
&lt;/h3&gt;

&lt;p&gt;Compass GUI offers two ways to view data, List view (Figure 12) and Table view (Figure 13). To view data or collection of documents, follow the steps below.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Within Compass click the peopledb in the left-hand pane.&lt;/li&gt;
&lt;li&gt; Click the collection name People.&lt;/li&gt;
&lt;li&gt; The documents will now be visible in the default List View.&lt;/li&gt;
&lt;li&gt; If you want to change it to Table view, simply click the Table toggle parallel to the View menu. See Figure 14 with arrow indicators.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FtKJs0e7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure12-compass-list-view-data.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FtKJs0e7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure12-compass-list-view-data.jpg" alt="figure 12"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Figure 12. List view of data&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qd7kuUlt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure13-mongodb-compass-table-view-data.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qd7kuUlt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure13-mongodb-compass-table-view-data.png" alt="figure 13"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 13. Table view of data&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c7u1dfum--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure14-compass-view-data-toggle.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c7u1dfum--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure14-compass-view-data-toggle.jpg" alt="figure 14"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 14. View data toggle&lt;/p&gt;

&lt;h3&gt;
  
  
  Updating documents (data)
&lt;/h3&gt;

&lt;p&gt;Editing or updating documents with Compass is straight forward, follow the next steps to utilize the software and update value fields.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the document you want to update and hover over it until the tooltip pops up.&lt;/li&gt;
&lt;li&gt; Click the edit document Pencil icon as shown in Figure 15. This will enable the full modification of the document within the viewer.&lt;/li&gt;
&lt;li&gt; Double click the value field of the data you want to update, as shown in Figure 16.&lt;/li&gt;
&lt;li&gt; Change the data to your requirement and press enter.&lt;/li&gt;
&lt;li&gt; You will notice a Document Modified notification will appear, click the update button on this notification to save changes. See Figure 17.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MSoSivgO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure15-edit-document-icon.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MSoSivgO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure15-edit-document-icon.jpg" alt="figure 15"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 15. Edit document icon&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cjHgoRpo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure16-editing-value.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cjHgoRpo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure16-editing-value.jpg" alt="figure 16"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 16. Editing a value&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rF96PlK0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure17-document-modified-update.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rF96PlK0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure17-document-modified-update.jpg" alt="figure 17"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 17. Document modified &amp;amp; Update data button&lt;/p&gt;

&lt;h3&gt;
  
  
  Deleting documents (data)
&lt;/h3&gt;

&lt;p&gt;Deleting documents is another simple task with the Compass software and can be done in two clicks of a button. Please follow the next steps to delete a document.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the document you want to update and hover over it until the tooltip pops up.&lt;/li&gt;
&lt;li&gt; Click the delete Trash Can icon as shown in Figure 18.&lt;/li&gt;
&lt;li&gt; A notification will appear stating the document has been flagged for deletion in red, Click the delete button as shown in Figure 20 and the document will be deleted.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QO7OZa5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure18-mongodb-compass-delete-document-icon.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QO7OZa5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure18-mongodb-compass-delete-document-icon.jpg" alt="figure 18"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Figure 18. Delete Document Icon&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iSCvumft--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure19-flagged-for-deletion.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iSCvumft--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure19-flagged-for-deletion.jpg" alt="figure 19"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 19. Document Flagged For Deletion Icon&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kXHtv-tF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure20-delete-document-button.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kXHtv-tF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure20-delete-document-button.jpg" alt="figure 20"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Figure 20. Delete document button&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing Data With MongoDB CLI (CRUD)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Creating a Database
&lt;/h3&gt;

&lt;p&gt;To create a new database with the MongoShell, please make sure you are already connected via the command line, if not see Page 3, Installing MongoDB &amp;amp; Connecting. Or simply follow these steps –&lt;/p&gt;

&lt;h6&gt;
  
  
  Quick Command Line Connection Recap
&lt;/h6&gt;

&lt;ol&gt;
&lt;li&gt; Open the command prompt on your computer.&lt;/li&gt;
&lt;li&gt; Enter the following command – cd C:\Program Files\MongoDB\Server\4.0\bin (Or replace with the path of the MongoDB installation bin folder)&lt;/li&gt;
&lt;li&gt; Now type the following command – mongo&lt;/li&gt;
&lt;/ol&gt;

&lt;h6&gt;
  
  
  Create the DB
&lt;/h6&gt;

&lt;ol&gt;
&lt;li&gt; Type use peopledb. (This command &lt;strong&gt;creates&lt;/strong&gt; the peopledb database)&lt;/li&gt;
&lt;li&gt; Press enter, see Figure 21 for what should be displayed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y1yFEeyG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure21-mongo-cli-create-database.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y1yFEeyG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure21-mongo-cli-create-database.jpg" alt="figure 21"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 21. Creating database via mongo shell&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a collection adding documents (data)
&lt;/h3&gt;

&lt;p&gt;To create a new document and add documents with the MongoShell, please make sure you are already connected via the command line, if not see Page 3, Installing MongoDB &amp;amp; Connecting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inserting one document
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; Make sure you are using the peopledb database (see Figure 21)&lt;/li&gt;
&lt;li&gt; Using the command db.people.insertOne() will create the People collection automatically if it does not exist. Between the parenthesis is where the JSON data should go.&lt;/li&gt;
&lt;li&gt; Use the &lt;em&gt;CodeBlock 1&lt;/em&gt; below to insert a row of the CSV file dataset.&lt;/li&gt;
&lt;li&gt; A JSON response will be returned to the console, displaying the inserted id. See Figure 22.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CodeBlock 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;db.people.insertOne({"firstName":"Grace","lastName":"Nelson","gender":"Female","age":{"$numberInt":"21"},"email":"g.nelson@randatmail.com","education":"Bachelor","salary":{"$numberInt":"5347"},"maritalStatus":"Single"})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--04ckptAR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure22-mongo-cli-insertOne-command.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--04ckptAR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure22-mongo-cli-insertOne-command.jpg" alt="figure 22"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 22. After insertOne command is used&lt;/p&gt;

&lt;h3&gt;
  
  
  Inserting multiple documents
&lt;/h3&gt;

&lt;p&gt;Rather than inserting documents one method at a time, you can utilise the insertMany() command. Follow the steps below –&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Make sure you are using the peopledb database (see Figure 21)&lt;/li&gt;
&lt;li&gt; Using the command &lt;code&gt;db.people.insertMany()&lt;/code&gt; will create the people collection automatically if it does not exist. Between the parenthesis is where the array of JSON data should go.&lt;/li&gt;
&lt;li&gt; Use the CodeBlock 2 below to insert multiple rows of the CSV file dataset.&lt;/li&gt;
&lt;li&gt; A JSON response will be returned to the console, displaying the inserted ids. See Figure 23.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CodeBlock 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;db.people.insertMany([{"firstName":"Daryl","lastName":"Johnson","gender":"Male","age":{"$numberInt":"20"},"email":"d.johnson@randatmail.com","education":"Upper Secondary","salary":{"$numberInt":"4450"},"maritalStatus":"Married"},{"firstName":"Justin","lastName":"West","gender":"Male","age":{"$numberInt":"27"},"email":"j.west@randatmail.com","education":"Doctoral","salary":{"$numberInt":"5783"},"maritalStatus":"Married"}])&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A9aZw-L9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure23-mongo-cli-insertMany-command.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9aZw-L9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure23-mongo-cli-insertMany-command.jpg" alt="figure 23"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 23. After insertMany() command&lt;/p&gt;

&lt;h3&gt;
  
  
  Viewing documents (data)
&lt;/h3&gt;

&lt;p&gt;To view data within the MongoShell, please make sure you are already connected via the command line, if not see Page 3, Installing MongoDB &amp;amp; Connecting.&lt;/p&gt;

&lt;p&gt;Follow the steps below –&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Make sure you are using the peopledb database (see Figure 21)&lt;/li&gt;
&lt;li&gt; Type the command &lt;code&gt;db.people.find()&lt;/code&gt; and press enter. The documents in the collection will be returned to the console. See Figure 24&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WvJpZ0Zg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure24-mongo-cli-find-command.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WvJpZ0Zg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure24-mongo-cli-find-command.jpg" alt="figure 24"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 24. db.people.find() all results displayed&lt;/p&gt;

&lt;h3&gt;
  
  
  Updating documents (data)
&lt;/h3&gt;

&lt;p&gt;To update documents with the MongoShell, please make sure you are already connected via the command line, if not see Page 3, Installing MongoDB &amp;amp; Connecting.&lt;/p&gt;

&lt;p&gt;Updating a document uses a method called updateOne() which requires multiple parameters in the format of JSON. The first is the criteria or search term to find the document in question, the second is the values we want to set.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Make sure you are using the peopledb database, see Figure 21.&lt;/li&gt;
&lt;li&gt; Use the command in CodeBlock 3 to change the salary of the person with the email of &lt;a href="mailto:west@randatmail.com"&gt;west@randatmail.com&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt; The response returned should give you an acknowledgment that the document was modified. See Figure 25.&lt;/li&gt;
&lt;li&gt; Check that the document was updated visually with the following command – &lt;code&gt;db.people.find({email: "j.west@randatmail.com" })&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CodeBlock 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;db.people.updateOne({ email: "j.west@randatmail.com" }, {  $set: { "salary": 9999 }   } )&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dGBgRkkg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure25-mongo-cli-updateOne-command.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dGBgRkkg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure25-mongo-cli-updateOne-command.jpg" alt="figure 25"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 25. Updating documents with updateOne()&lt;/p&gt;

&lt;h3&gt;
  
  
  Deleting documents (data)
&lt;/h3&gt;

&lt;p&gt;To delete a document from the database with the mongo CLI, please make sure you are already connected via the command line, if not see Page 3, Installing MongoDB &amp;amp; Connecting.&lt;/p&gt;

&lt;p&gt;Deleting a document uses a method called updateOne() which takes up to 3 parameters but, for this example, we will only be using one; filter.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Make sure you are using the peopledb database, see Figure 21.&lt;/li&gt;
&lt;li&gt; Enter the following command to delete the document that has the email of &lt;a href="mailto:j.west@randatmail.com"&gt;j.west@randatmail.com&lt;/a&gt; – people.deleteOne({email: “&lt;a href="mailto:j.west@randatmail.com"&gt;j.west@randatmail.com&lt;/a&gt;” })&lt;/li&gt;
&lt;li&gt; Mongo should give a JSON response notifying the deletion was successful. See Figure 26.&lt;/li&gt;
&lt;li&gt; Check to see if the document above still exists by using the following command – people.find({email: “&lt;a href="mailto:j.west@randatmail.com"&gt;j.west@randatmail.com&lt;/a&gt;” }) and you should see nothing returned from mongo.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_lNjvUcM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure26-mongo-cli-deleteOne-command.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_lNjvUcM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure26-mongo-cli-deleteOne-command.jpg" alt="figure 26"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 26. Response after deleteOne() method utilised&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced functionality with MongoDB
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Projection
&lt;/h3&gt;

&lt;p&gt;Projections are a way of overriding the default way of how MongoDB returns data via a query. Using a projection enables customization of how the data is returned or as otherwise put, what fields are returned.&lt;/p&gt;

&lt;p&gt;For example, MongoDB will, by default be similar to the following query in SQL&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * from tbl
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Selecting all fields when executed.&lt;/p&gt;

&lt;p&gt;With projection parameters, it could be like the following&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT field1, field2 from tbl
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Specifying specific fields to be returned in the result set.&lt;/p&gt;

&lt;h4&gt;
  
  
  With Compass
&lt;/h4&gt;

&lt;p&gt;Using the Compass query bar, you can specify projection fields easily. Following the steps below to perform a projection query on the collection.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the database and collection of documents you want to query in the left-hand pane and click it.&lt;/li&gt;
&lt;li&gt; After the view is loaded locate the query bar and press the options button as shown in Figure 27 and click it.&lt;/li&gt;
&lt;li&gt; Four options will now appear on the left-hand side, one of these is Project.&lt;/li&gt;
&lt;li&gt; Fill out fields that you want to return in the result set in JSON format where the first value in the field and the second is a Boolean 1 or 0 to show the field or not. For example {email : 1}&lt;/li&gt;
&lt;li&gt; After filling out the JSON within the project option, click the find button as shown in Figure 28.&lt;/li&gt;
&lt;li&gt; The result set returned will now be displayed in the list view below the query bar. See Figure 29 for an example.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a28eBPhG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure27-mongo-compass-query-bar-options.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a28eBPhG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure27-mongo-compass-query-bar-options.jpg" alt="figure 27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 27. Query bar options button&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--64Y_1ZI_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure28-mongo-compass-find-button.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--64Y_1ZI_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure28-mongo-compass-find-button.jpg" alt="figure 28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 28. Find button&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mxh6vrUa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure29-mongo-compass-projected-result-set.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mxh6vrUa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure29-mongo-compass-projected-result-set.jpg" alt="figure 29"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 29. Projected result set&lt;/p&gt;

&lt;h4&gt;
  
  
  With MongoDB CLI
&lt;/h4&gt;

&lt;p&gt;Projection in the Mongo shell is done with JSON projection parameters passed into the find() method. By specifying a query and secondly, field names and an integer (1 to show and 0 to hide) we can utilize projection.&lt;/p&gt;

&lt;p&gt;See the following steps –&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Connect to MongoDB instance with the CLI.&lt;/li&gt;
&lt;li&gt; Type use peopledb&lt;/li&gt;
&lt;li&gt; Type &lt;code&gt;db.people.find({}, {email : 1})&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Notice the first empty object parameter in the method above, as we do not want to specify any criteria, in particular, just simply ask for all results instead.&lt;/li&gt;
&lt;li&gt; Also, notice the default behavior of the output, the _id field is also included without request.&lt;/li&gt;
&lt;li&gt; See Figure 30 for the output.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3IOTUPyn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure30-mongo-cli-projected-result-set.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3IOTUPyn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure30-mongo-cli-projected-result-set.jpg" alt="figure 30"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 30. Example Projection Query&lt;/p&gt;

&lt;h3&gt;
  
  
  Sort
&lt;/h3&gt;

&lt;p&gt;Sorting of data (documents) can be utilized by using the Sort option which takes a field name and the ascending or descending parameter in the format of a number. 1 for Ascending and -1 for descending.&lt;/p&gt;

&lt;p&gt;For example, sorting is exactly similar to how you would sort in SQL. See the query below.&lt;/p&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT

&lt;p&gt;*&lt;/p&gt;

&lt;p&gt;FROM&lt;/p&gt;

&lt;p&gt;TBL&lt;/p&gt;

&lt;p&gt;ORDER BY&lt;/p&gt;

&lt;p&gt;age&lt;/p&gt;

&lt;p&gt;ASC&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  With Compass&lt;br&gt;
&lt;/h4&gt;

&lt;p&gt;See the following steps to perform a sort in a query on collections.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the database and collection of documents you want to query in the left-hand pane and click it.&lt;/li&gt;
&lt;li&gt; After the view is loaded locate the query bar and press the options button as shown in Figure 21 and click it.&lt;/li&gt;
&lt;li&gt; Four options will now appear on the left-hand side, one of these is Sort.&lt;/li&gt;
&lt;li&gt; In the sort option bar enter the parameters in the format of JSON. For example {age: -1}&lt;/li&gt;
&lt;li&gt; Press the find button and you will see the document view now be ordered by length descending. See figure 31 for the result view.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rT6sBxpE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure31-mongo-compass-sort.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rT6sBxpE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure31-mongo-compass-sort.jpg" alt="figure 31"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 31. Results after sort by descending length&lt;/p&gt;

&lt;h4&gt;
  
  
  With MongoDB CLI
&lt;/h4&gt;

&lt;p&gt;The sort method can be chained to a find method, making it extremely understandable and in opinion, better than executing within compass. The integer supplied acts the same as it does in Compass too, 1 for ascending and -1 for descending.&lt;/p&gt;

&lt;p&gt;See the following steps –&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Connect to MongoDB instance with the CLI.&lt;/li&gt;
&lt;li&gt; Type use peopledb&lt;/li&gt;
&lt;li&gt; Type &lt;code&gt;people.find({}, {age : 1}).sort({age: -1})&lt;/code&gt; for descending result.&lt;/li&gt;
&lt;li&gt; Type &lt;code&gt;people.find({}, {age : 1}).sort({age: 1})&lt;/code&gt; for ascending result.&lt;/li&gt;
&lt;li&gt; See Figure 32 for results sorted by age.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s9pm0tlO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure32-mongo-cli-sort.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s9pm0tlO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure32-mongo-cli-sort.jpg" alt="figure 32"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 32. Sorting results&lt;/p&gt;

&lt;h3&gt;
  
  
  Skip
&lt;/h3&gt;

&lt;p&gt;Skip serves the purpose of skipping x number of documents during a query search, by specifying an integer, the MongoDB will skip this amount and return the results next in the collection.&lt;/p&gt;

&lt;p&gt;For example, you can execute this command in SQL too. See the following SQL code.&lt;/p&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT

&lt;p&gt;*&lt;/p&gt;

&lt;p&gt;FROM&lt;/p&gt;

&lt;p&gt;TBL&lt;/p&gt;

&lt;p&gt;SKIP&lt;/p&gt;

&lt;p&gt;1&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  With Compass&lt;br&gt;
&lt;/h4&gt;

&lt;p&gt;To skip documents when executing a query, use the following steps for Compass.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the database and collection of documents you want to query in the left-hand pane and click it.&lt;/li&gt;
&lt;li&gt; Click the options button on the query bar and look to the bottom right of the dropped down box, parallel to collation. Here you will find the Skip option. See Figure 33.&lt;/li&gt;
&lt;li&gt; Enter an integer, for this tutorial the number 1 will be used.&lt;/li&gt;
&lt;li&gt; Click the find button and you will see the result set with the first two collections missing. See Figure 34.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TV-vOgOO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure33-mongo-compass-skip.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TV-vOgOO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure33-mongo-compass-skip.jpg" alt="figure 33"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 33. Skip option&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---R8f_wQX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure34-mongo-compass-skip-result.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---R8f_wQX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure34-mongo-compass-skip-result.jpg" alt="figure 34"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 34. Skip 1 document result set&lt;/p&gt;

&lt;h4&gt;
  
  
  With MongoDB CLI
&lt;/h4&gt;

&lt;p&gt;Again, this method can be chained to existing methods already in the command line, for this example we will use the commands for both the Find and Sort tutorials.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Connect to MongoDB instance with the CLI.&lt;/li&gt;
&lt;li&gt; Type use peopledb&lt;/li&gt;
&lt;li&gt; Type &lt;code&gt;people.find({}, {email : 1}).sort({age: -1}).skip(1)&lt;/code&gt; for descending result that skips the first document, see Figure 35 for an example.&lt;/li&gt;
&lt;li&gt; Alternatively use people.find().skip(1) to request all documents, skipping the first document.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y3FpsLHt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure35-mongo-cli-skip.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y3FpsLHt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure35-mongo-cli-skip.jpg" alt="figure 35"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 35. Skip method example&lt;/p&gt;

&lt;h3&gt;
  
  
  Limit
&lt;/h3&gt;

&lt;p&gt;Limit is a filter to limit the number of results returned, this can be any number you desire and can serve really good purposes in some use cases.&lt;/p&gt;

&lt;p&gt;SQL offers the very same functionality, see the example below, the returned result set would be one row only.&lt;/p&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT

&lt;p&gt;*&lt;/p&gt;

&lt;p&gt;FROM&lt;/p&gt;

&lt;p&gt;TBL&lt;/p&gt;

&lt;p&gt;LIMIT 1&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  With Compass&lt;br&gt;
&lt;/h4&gt;

&lt;p&gt;To skip documents when executing a query, use the following steps for Compass.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the database and collection of documents you want to query in the left hand pane and click it.&lt;/li&gt;
&lt;li&gt; Click the options button on the query bar and look to the bottom right of the dropped down box, parallel to collation. Here you will find the limit option. See Figure 26.&lt;/li&gt;
&lt;li&gt; Enter an integer, for this tutorial the number 1 will be used.&lt;/li&gt;
&lt;li&gt; Click the find button and you will only see one document in the result view. See Figure 27.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---cv45ZF9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure36-mongo-compass-limit-option.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---cv45ZF9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure36-mongo-compass-limit-option.jpg" alt="figure 36"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 36. Limit option&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TQH5a4uE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure37-mongo-compass-limit-option-result.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TQH5a4uE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure37-mongo-compass-limit-option-result.jpg" alt="figure 37"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 37. Limit 1 result set&lt;/p&gt;

&lt;h4&gt;
  
  
  With MongoDB CLI
&lt;/h4&gt;

&lt;p&gt;The Limit method is highly similar to the Skip method, it requires a single integer and again, it can be chained, see the following steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Connect to MongoDB instance with the CLI.&lt;/li&gt;
&lt;li&gt; Type use peopledb&lt;/li&gt;
&lt;li&gt; Type &lt;code&gt;people.find({}, {email : 1}).sort({age: -1}).skip(1).limit(1)&lt;/code&gt; See Figure 38 for an example&lt;/li&gt;
&lt;li&gt; Alternatively, you can use skip without chaining to all the methods above. Use the command people.find().limit(1) to retrieve the first document in the collection.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qF8cCL2m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure38-mongo-cli-limit.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qF8cCL2m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure38-mongo-cli-limit.jpg" alt="figure 38"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 38. Limit method example&lt;/p&gt;

&lt;h3&gt;
  
  
  Indexing
&lt;/h3&gt;

&lt;p&gt;Just like in SQL server, MongoDB can place indexes on specific fields too. This helps speed up queries but at the same time can add more hard-disk usage with the more indexes utilized.&lt;/p&gt;

&lt;h4&gt;
  
  
  With Compass
&lt;/h4&gt;

&lt;p&gt;By using Compass GUI, indexes can be added to fields in the database’s collections. See the following steps to utilize indexing.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the database and collection you want to place an index on and click it.&lt;/li&gt;
&lt;li&gt; From the initial collection dashboard look to the top of the view and find the Indexes tab as shown in Figure 39 and click it.&lt;/li&gt;
&lt;li&gt; Next, click the green Create Index button, as shown in Figure 40.&lt;/li&gt;
&lt;li&gt; From the modal popup, enter an index name, something of descriptive purpose to the field you want to index. For this example, ageIndex.&lt;/li&gt;
&lt;li&gt; Select the field you want to index, for this example, age was selected.&lt;/li&gt;
&lt;li&gt; Choose ASC from the index type dropdown*&lt;em&gt;. (MongoDB, Index Types, 2018).&lt;/em&gt;*&lt;/li&gt;
&lt;li&gt; Click the create button, see Figure 41.&lt;/li&gt;
&lt;li&gt; You will now be able to see the index within the indexes tab view. See Figure 42.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lazM1w3W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure39-mongo-compass-indexing-tab.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lazM1w3W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure39-mongo-compass-indexing-tab.jpg" alt="figure 39"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 39. Index Tab Location&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tz7MxaXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure40-mongo-compass-create-index.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tz7MxaXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure40-mongo-compass-create-index.jpg" alt="figure 40"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 40. Start Creating Index Button&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CsXLC78I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure41-mongo-compass-create-index-button.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CsXLC78I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure41-mongo-compass-create-index-button.jpg" alt="figure 41"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 41. Create Field Index Button&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RidSG6Yv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure42-mongo-compass-index-view.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RidSG6Yv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure42-mongo-compass-index-view.jpg" alt="figure 42"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 42. Indexes View After Index Creation&lt;/p&gt;

&lt;h4&gt;
  
  
  With MongoDB CLI
&lt;/h4&gt;

&lt;p&gt;Creating an index is executed with the following method createIndex(), it takes two parameters, the first being specifying the fields that you want to index and the second is specifically for index options which you can see more detail in the documentation.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Connect to MongoDB instance with the CLI.&lt;/li&gt;
&lt;li&gt; Type use peopledb&lt;/li&gt;
&lt;li&gt; Type &lt;code&gt;people.createIndex({age: 1})&lt;/code&gt; to place an index on the age field.&lt;/li&gt;
&lt;li&gt; See Figure 43 for the successful index creation response.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G9Uz_471--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure43-mongo-cli-createIndex.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G9Uz_471--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure43-mongo-cli-createIndex.jpg" alt="figure 43"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 43. createIndex() response&lt;/p&gt;

&lt;h3&gt;
  
  
  Aggregation
&lt;/h3&gt;

&lt;p&gt;Aggregation in MongoDB is similar to SQL Server aggregation functions like Group By or Sum. Mongo offers 3 prominent options for aggregation; Aggregation Pipeline, Map-Reduce and Single Purpose Aggregation. See the following reference for fine detail on the above-listed methodologies.&lt;/p&gt;

&lt;h4&gt;
  
  
  With Compass
&lt;/h4&gt;

&lt;p&gt;Compass GUI comes out-of-the-box prepared for aggregation and has its own tab within the collections dashboard. See the steps below to perform a simple aggregation of counting by specific criteria.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the database and collection you want to perform aggregation on and click it, in this case the peopledb DB &amp;amp; people collection.&lt;/li&gt;
&lt;li&gt; Locate the Aggregation tab towards the top of the view and click it. See Figure 44 for the location of the tab.&lt;/li&gt;
&lt;li&gt; Once the aggregation tab has loaded, enter a Pipeline name, for this example use Count Of Males Pipeline.&lt;/li&gt;
&lt;li&gt; Then locate the aggregation stage widget as shown in Figure 45.&lt;/li&gt;
&lt;li&gt; Click the select drop down and pick the $match operator, this will load the initial format requirements to the window. See Figure 46.&lt;/li&gt;
&lt;li&gt; Within this window, enter a key and value like the following – { gender: “Male” }&lt;/li&gt;
&lt;li&gt; Once this is filled out, you will notice the output window on the right displaying only documents with the Gender of ‘Male’. See Figure 47.&lt;/li&gt;
&lt;li&gt; Now to add the Count aggregation, to start this, click the Add Stage button underneath the $match query.&lt;/li&gt;
&lt;li&gt; Again, from the new stage’s dropdown, select $count.&lt;/li&gt;
&lt;li&gt; This JSON blueprint requires a key field only, what you want this count field to be named. Name it malePeopleCount, keeping apostrophes intact.&lt;/li&gt;
&lt;li&gt; The output window on the right of this stage will then load the result. See figure 48.&lt;/li&gt;
&lt;li&gt; Finally, save the pipeline with the Save Pipeline button at the top of the aggregation view. – This will allow you to preload this aggregation functionality for quick use another time.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Brsot1l2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure44-mongo-compass-aggregation-tab.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Brsot1l2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure44-mongo-compass-aggregation-tab.jpg" alt="figure 44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 44. Aggregations tab&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XmPKLqta--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure45-mongo-compass-aggregation-stage-widget.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XmPKLqta--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure45-mongo-compass-aggregation-stage-widget.jpg" alt="figure 45"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 45. Aggregation Stage Widget&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VQneW1qe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure46-mongo-compass-match-operator-json.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VQneW1qe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure46-mongo-compass-match-operator-json.jpg" alt="figure 46"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 46. $Match operator JSON&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TJw2OVk8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure47-mongo-compass-match-operator-result.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TJw2OVk8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure47-mongo-compass-match-operator-result.jpg" alt="figure 47"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 47. $match output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--91mKh9QH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure48-mongo-compass-match-operator-and-count.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--91mKh9QH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure48-mongo-compass-match-operator-and-count.jpg" alt="figure 48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 48. $match &amp;amp; $count output&lt;/p&gt;

&lt;h4&gt;
  
  
  With MongoDB CLI
&lt;/h4&gt;

&lt;p&gt;The aggregate() function of the Mongo Shell provides many possibilities for aggregation, it allows multiple instances of its aggregating parameters. In this example, a query for the count of all instances of documents with a specific gender.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Connect to MongoDB instance with the CLI.&lt;/li&gt;
&lt;li&gt; Type use peopledb&lt;/li&gt;
&lt;li&gt; Type the following command people.aggregate([{ $match: { gender: “Male” } }, {“$group” : {_id:”$gender”, count:{$sum:1}}}])&lt;/li&gt;
&lt;li&gt; See Figure 49 for the output of the above command.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6rdbS_4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure49-mongo-compass-match-operator-and-count.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6rdbS_4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure49-mongo-compass-match-operator-and-count.jpg" alt="figure 49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 49. Aggregation, group and count&lt;/p&gt;

&lt;h3&gt;
  
  
  BackUp
&lt;/h3&gt;

&lt;h4&gt;
  
  
  With Compass
&lt;/h4&gt;

&lt;p&gt;Currently, the only method of backing up from the Compass software is to export data at collection level. See the following steps to execute an export.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the database and collection you want to export. For this tutorial, people was used.&lt;/li&gt;
&lt;li&gt; Click the collection dropdown at the top of the window as displayed in Figure 50.&lt;/li&gt;
&lt;li&gt; Click export collection.&lt;/li&gt;
&lt;li&gt; Turn the Export Full Collection toggle on.&lt;/li&gt;
&lt;li&gt; Select JSON or CSV (For this example, JSON was selected)&lt;/li&gt;
&lt;li&gt; Select the path and type a filename where you want to export the data to go to.&lt;/li&gt;
&lt;li&gt; Click the export button, see Figure 51.&lt;/li&gt;
&lt;li&gt; The data will be exported in JSON format.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OOfOjaFj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure50-mongo-compass-collection-dropdown-menu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OOfOjaFj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure50-mongo-compass-collection-dropdown-menu.jpg" alt="figure 50"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 50. Collection dropdown&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T55_4b-H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure51-compass-export-data-example.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T55_4b-H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure51-compass-export-data-example.jpg" alt="figure 51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 51. Export Data Button&lt;/p&gt;

&lt;h4&gt;
  
  
  With MongoDB CLI
&lt;/h4&gt;

&lt;p&gt;Mongo comes out-of-the-box with a special engine to back up the database, but it may be wise to use a third-party tool to do this to prevent affecting performance. Nevertheless, the following steps show how to back up a MongoDB database.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the MongoDB installation /bin folder. For example, C:\Program Files\MongoDB\Server\4.0\bin.&lt;/li&gt;
&lt;li&gt; In this folder, there will be a program called mongodump.exe – This is the engine that will backup the database.&lt;/li&gt;
&lt;li&gt; Open the command line prompt as administrator (Right click -&amp;gt; run as administrator) to make sure the CLI has utmost access to create the backup file).&lt;/li&gt;
&lt;li&gt; Type cd C:\Program Files\MongoDB\Server\4.0\bin — Or replace with your own path.&lt;/li&gt;
&lt;li&gt; Type mongodump –host localhost –port 27017 –db peopledb&lt;/li&gt;
&lt;li&gt; See Figure 52 for the response.&lt;/li&gt;
&lt;li&gt; Check inside the folder C:\Program Files\MongoDB\Server\4.0\bin (or your own path) for a folder named dump, which should have been created and open it&lt;/li&gt;
&lt;li&gt; Open the next folder inside of it, which should be your Database name that you backed up.&lt;/li&gt;
&lt;li&gt; Inside are the backup files from the mongodump command. See an example of the files in this zip file.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Above parameters explained&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  –host = Hostname, e.g.: localhost or remote host address.&lt;/li&gt;
&lt;li&gt;  –port = Port number, e.g.: 27010 or remote port number.&lt;/li&gt;
&lt;li&gt;  –db = Database name, in this case peopledb or alternatively one of your own.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ckuqb2sg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure52-mongocli-mongodump-output.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ckuqb2sg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure52-mongocli-mongodump-output.jpg" alt="figure 52"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 52. mongodump output&lt;/p&gt;

&lt;h3&gt;
  
  
  Restore
&lt;/h3&gt;

&lt;h4&gt;
  
  
  With Compass
&lt;/h4&gt;

&lt;p&gt;Currently, the only method of backing up from the Compass software is to import data at collection level. See the following steps to execute an import.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the database and click create collection – Call it peopleDuplicate.&lt;/li&gt;
&lt;li&gt; Click the peopleDuplicate collection then click the collection dropdown at the top of the window as displayed in Figure 53.&lt;/li&gt;
&lt;li&gt; Click the import data option.&lt;/li&gt;
&lt;li&gt; Select JSON or CSV (For this example, JSON is used).&lt;/li&gt;
&lt;li&gt; Browse to find the file you want to import, in this case, the data that was exported earlier will be used.&lt;/li&gt;
&lt;li&gt; Click the import button, see Figure 53.&lt;/li&gt;
&lt;li&gt; The data will now be imported into the duplicated collection. See Figure 54.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YGJVjftk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure53-compass-import.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YGJVjftk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure53-compass-import.jpg" alt="figure 53"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 53. Collection Dropdown &amp;amp; Import Button&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_H7Ob0Mz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure54-compass-view-after-import.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_H7Ob0Mz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure54-compass-view-after-import.jpg" alt="figure 54"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 54. Collection after import&lt;/p&gt;

&lt;h4&gt;
  
  
  With MongoDB CLI
&lt;/h4&gt;

&lt;p&gt;In this example of restoring with the Mongo engine, the backup that was made with mongodump in the backup tutorial section.&lt;/p&gt;

&lt;p&gt;Alternatively, if you didn’t use the backup section, grab the files here. – Add the files to the MongoDB bin folder in a folder named ‘dump’ and in a subfolder named peopledb. So, for example – C:\Program Files\MongoDB\Server\4.0\bin\dump\peopledb&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the MongoDB installation /bin folder. For example, C:\Program Files\MongoDB\Server\4.0\bin.&lt;/li&gt;
&lt;li&gt; In this folder, there will be a program called mongorestore.exe – This is the engine that will restore a database.&lt;/li&gt;
&lt;li&gt; Open the command line prompt as administrator (Right click -&amp;gt; run as administrator) to make sure the CLI has the utmost access to create the backup file).&lt;/li&gt;
&lt;li&gt; Type cd C:\Program Files\MongoDB\Server\4.0\bin — Or replace with your own path.&lt;/li&gt;
&lt;li&gt; Type the command &lt;code&gt;mongorestore --db peopledbduplicate dump/peopledb&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; See the output response in Figure 55.&lt;/li&gt;
&lt;li&gt; Now connect to mongo with a new command prompt.&lt;/li&gt;
&lt;li&gt; Type use peopledbduplicate&lt;/li&gt;
&lt;li&gt; Type &lt;code&gt;db.people.find()&lt;/code&gt; – See Figure 56 for the documents in the newly restored People collection.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The parameters for mongorestore above&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  –db = Database name for import/restore&lt;/li&gt;
&lt;li&gt;  Dump/exportedFolder = the command to specify the dump folder inside the /bin folder.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aSpEMYuV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure55-mongo-cli-restore.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aSpEMYuV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure55-mongo-cli-restore.jpg" alt="figure 55"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Figure 55. Output/Response after mongorestore&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mp5z2dPe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure56-mongo-cli-after-dump-restore.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mp5z2dPe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure56-mongo-cli-after-dump-restore.jpg" alt="figure 56"&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Figure 56. People collection output after restore from dump&lt;/p&gt;

&lt;h3&gt;
  
  
  Import With mongoimport.exe
&lt;/h3&gt;

&lt;p&gt;With the mongoimport exe available to use within the MongoDB installation, it is possible to import data in CSV, TSV or JSON format. In this example, the data set specified at the beginning of the tutorial will be imported into the mongo database. Note: The data set must be saved as a .csv file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Locate the MongoDB installation /bin folder. For example, C:\Program Files\MongoDB\Server\4.0\bin.&lt;/li&gt;
&lt;li&gt; Make sure that mongoimport.exe exists.&lt;/li&gt;
&lt;li&gt; Open the command line prompt as administrator (Right click -&amp;gt; run as administrator) to make sure the CLI has the utmost access to create the backup file).&lt;/li&gt;
&lt;li&gt; Type cd C:\Program Files\MongoDB\Server\4.0\bin   — Or the path of your bin folder&lt;/li&gt;
&lt;li&gt; Use the following command – mongoimport –db peopledb –collection peopleDuplicate –type csv –headerline –file C:\Users\DWEPr\Desktop\people.csv ( –file will be the full path to your CSV file)&lt;/li&gt;
&lt;li&gt; Press enter. See Figure 57 for the response after import.&lt;/li&gt;
&lt;li&gt; Now connect to mongo with a new command prompt.&lt;/li&gt;
&lt;li&gt; Type use peopledb&lt;/li&gt;
&lt;li&gt; Type &lt;code&gt;db.peopleDuplicate.find()&lt;/code&gt;. See Figure 58 for the documents in the newly restored peopleDuplicate collection.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Parameters for mongoimport explained&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  –db = Database name you want to import into&lt;/li&gt;
&lt;li&gt;  –collection = The name of the collection you want to create/import into.&lt;/li&gt;
&lt;li&gt;  –type = type of file, in this case, CSV&lt;/li&gt;
&lt;li&gt;  –headerline = Instructs the engine to use the first line of the CSV as the field names.&lt;/li&gt;
&lt;li&gt;  –file = the full path to the CSV file for import.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--goxNrGAQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure57-mongo-cli-csv-import.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--goxNrGAQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure57-mongo-cli-csv-import.jpg" alt="figure 57"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 57. Output after import CSV&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---eF0e4aZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure58-mongo-cli-collection-view-after-csv-import.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---eF0e4aZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/12/figure58-mongo-cli-collection-view-after-csv-import.jpg" alt="figure 58"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 58. Collection after CSV import&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced MongoDB CLI Setup (Windows OS Only)
&lt;/h2&gt;

&lt;p&gt;To save time whilst using the command line, you can set an Environment Variable in the form of a path to your mongo engine. This will prevent specifying the full folder path of the engine every time you boot the command prompt and rather just be able to type ‘mongo’. See the following steps to set it up.&lt;/p&gt;

&lt;p&gt;In addition to the ability to use mongo quickly, other engines like mongodump and mongorestore will also be available from the CLI too, simply by typing them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Go to control panel&lt;/li&gt;
&lt;li&gt; Click System and find Advanced System Settings and open it.&lt;/li&gt;
&lt;li&gt; Click environment variables.&lt;/li&gt;
&lt;li&gt; Find the user variables window and look for ‘Path’ if it’s not already there, then you will need to follow these sub-steps

&lt;ol&gt;
&lt;li&gt; Click New&lt;/li&gt;
&lt;li&gt; Enter Path as the variable name&lt;/li&gt;
&lt;li&gt; Enter cd C:\Program Files\MongoDB\Server\4.0\bin as the variable value (or the path to your mongo bin folder).&lt;/li&gt;
&lt;li&gt; Click Ok, then Ok again.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt; If the path does exist, click it and press edit.&lt;/li&gt;
&lt;li&gt; Click new on the right-hand side and enter the following – cd C:\Program Files\MongoDB\Server\4.0\bin (or the path to your bin folder)&lt;/li&gt;
&lt;li&gt; Click Ok, then Ok again.&lt;/li&gt;
&lt;li&gt; Finally, open up the command prompt and type mongo&lt;/li&gt;
&lt;li&gt; You should now be connected to the mongo shell!&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>mongodb</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>HTML Text Input Formatting With Cleave.js</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Fri, 08 Nov 2019 20:48:58 +0000</pubDate>
      <link>https://dev.to/danenglishby/html-text-input-formatting-with-cleave-js-30h5</link>
      <guid>https://dev.to/danenglishby/html-text-input-formatting-with-cleave-js-30h5</guid>
      <description>&lt;p&gt;One of my pet peeves when shopping online is HTML input forms, especially when they’re not properly formatted for you. Usually, many of the giant e-commerce shops will have this functionality, but others, not so much.&lt;/p&gt;

&lt;p&gt;For example, when typing in your phone number in an input form, it will end up looking like a zero-spaced 11 digit number. This is a bit of a nightmare when you're double-checking the number, especially if you’ve just read that number from your phone which is beautifully formatted, for example, 0800 1234 567.&lt;/p&gt;

&lt;p&gt;When properly formatted, an input form should display the numbers like the above example whilst you type it in, spacing it automatically for you.&lt;/p&gt;

&lt;p&gt;This simple user-experience aspect can be fixed with the use of &lt;a href="https://github.com/nosir/cleave.js/"&gt;Cleave.js&lt;/a&gt; – A beautiful text input formatting plugin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cleave.js&lt;/strong&gt; not only formats contact telephone number inputs but go further by formatting some of the following common inputs  –&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Credit Card No. Inputs&lt;/li&gt;
&lt;li&gt;  Date Inputs&lt;/li&gt;
&lt;li&gt;  Time Inputs&lt;/li&gt;
&lt;li&gt;  Numeral Inputs eg, tens and thousands&lt;/li&gt;
&lt;li&gt;  Tel/Mob No Inputs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Some examples of Cleave.js in action
&lt;/h2&gt;

&lt;p&gt;Check out the CodePen demos of default HTML input forms in comparison with Cleave.js inputs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Date Text Input Formatting
&lt;/h3&gt;

&lt;p&gt;Yes, I know, why use a text &lt;code&gt;input&lt;/code&gt; for &lt;code&gt;date&lt;/code&gt; inputs? I don’t know a great reason as of yet, but it’s not to say people would rather use the text type on their websites. This library is brilliant for that specific use case.&lt;/p&gt;

&lt;p&gt;The following example, subtly adds slashes between each part of your date of birth eg, day, month and year. A standard input form of ‘date of birth’ would look similar to the following –&lt;code&gt;01052005&lt;/code&gt;, but with Cleave.js you wind up with &lt;code&gt;01/05/2005&lt;/code&gt;. Test out the examples in the CodePen below –&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/DanEnglishby/embed/ywXjEx?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You may be wondering why the heck the &lt;code&gt;tel&lt;/code&gt; input type is used with these inputs and there is a good reason; Whilst this library is a text-formatting library, rather than use the &lt;code&gt;text&lt;/code&gt; input type, you can use &lt;code&gt;tel&lt;/code&gt; so that mobile users have a much better experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Credit Card Number Text Input Formatting
&lt;/h3&gt;

&lt;p&gt;Next up, is a beautiful example of formatting credit card numbers as users type. Rather it a big long text string of numbers, it will be spaced elegantly, just like it is on your actual credit card! After you type the first four digits of your credit card number, space is added automatically before you start typing the rest of it out.&lt;/p&gt;

&lt;p&gt;See the pre-filled example below, feel free to edit the numbers and try for yourself.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/DanEnglishby/embed/bZRKdK?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Cleave.js goes even further with formatting credit cards too. It has the ability to display highlighted icons dependant on your number, which again is another great user-experience. See the image below –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M2e5AHx_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/03/credit-card-formatter.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M2e5AHx_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/03/credit-card-formatter.gif" alt="cleave.js credit card formatting"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cleave.js Visual Credit Card Formatting&lt;/p&gt;

&lt;h3&gt;
  
  
  Telephone Text Input Formatting
&lt;/h3&gt;

&lt;p&gt;Just like the formatting of a credit card number, Cleave.js does this for telephone numbers too. Splitting the number out into digestible groups, making it easy to read back to yourself and double-check. In the following demo, the format has been set for 3 size groups of 4,4 and 3. Resulting in a formatted number like the following – 0800 1234 567, but this can be customized to suit.&lt;/p&gt;

&lt;p&gt;Check out the example below&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/DanEnglishby/embed/wOebxQ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you wanted to change the way it’s formatted, then check the JS and comments below to understand how it works –&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;cleave&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Cleave&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.cleave-input-telephone&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;delimiters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;// What should be appended after each block&lt;/span&gt;
        &lt;span class="na"&gt;blocks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;// block groups = no. of chars before a delimiter is added.&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Custom Text Formatting
&lt;/h3&gt;

&lt;p&gt;With Cleave.js, you can completely customize formatting to your specific needs, for example, if you need a dollar sign in the middle of text input, it can be done, for what reason, I do not know!&lt;/p&gt;

&lt;p&gt;Here is a demo of customization, which probably serves no purpose to a user but gives you an insight into how it can be specific to your data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;cleave&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Cleave&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.cleave-input-random&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;delimiters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;£&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;£&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;$&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="na"&gt;blocks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above block parameters instruct Cleave to add an ‘A’ after 1 character, a ‘£’ after another character and so on. This will result in the following –&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/DanEnglishby/embed/zbzQeK?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Cleave.js is the perfect plugin to boost user-experience if you have a lot of plain text inputs. The examples in this article show quite common inputs being formatted but is certainly not limited to just that. There are plenty more examples on the &lt;a href="https://nosir.github.io/cleave.js/"&gt;dedicated demo page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also, there are instructions on how to use cleave with React and Angular on the &lt;a href="https://github.com/nosir/cleave.js"&gt;GitHub repo page&lt;/a&gt;, enabling you to quickly get set up and utilize the library.&lt;/p&gt;

&lt;p&gt;Cross Posted from &lt;a href="https://www.codewall.co.uk/html-text-input-formatting-with-cleave-js/"&gt;https://www.codewall.co.uk/html-text-input-formatting-with-cleave-js/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How To Remove Unused CSS From Your Website</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Thu, 07 Nov 2019 19:38:18 +0000</pubDate>
      <link>https://dev.to/danenglishby/how-to-remove-unused-css-from-your-website-4kig</link>
      <guid>https://dev.to/danenglishby/how-to-remove-unused-css-from-your-website-4kig</guid>
      <description>&lt;p&gt;Cross Posted: &lt;a href="https://www.codewall.co.uk/how-to-remove-unused-css-from-your-website/"&gt;https://www.codewall.co.uk/how-to-remove-unused-css-from-your-website/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A cascading style sheet can gradually build up into a bulky file over time. And in most cases, over time, you’ve added lots of new CSS and stopped using some classes that were there before.&lt;/p&gt;

&lt;p&gt;This means two things, your CSS file is messy, and it’s unnecessarily bigger. A bigger CSS file indicates more significant download times, and we don’t want that if it’s not necessary!&lt;/p&gt;

&lt;p&gt;Of course, this isn’t the only scenario to why you may have a larger CSS file, and it could be that you’ve used a pre-built theme and stripped it down a bit. But how do you know what’s required still and whats not? Unless you were super-careful and stripped out each class as you edited the theme.&lt;/p&gt;

&lt;p&gt;In this article, you will see how we reduced CodeWall’s CSS file size by a considerable ratio.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, to recap, who is this article for?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Developers who have downloaded a theme but only need some parts of it&lt;/li&gt;
&lt;li&gt;  Developers who have downloaded a theme and have customized it considerably&lt;/li&gt;
&lt;li&gt;  Developers who have been working on a website for a while and want to get rid of old fluff&lt;/li&gt;
&lt;li&gt;  Developers who, like myself, want to speed up their website in general&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any of the points above is why your reading, then stay tuned!&lt;/p&gt;

&lt;p&gt;In this article, the blog (CodeWall.co.uk) will be the guinea pig, as the CSS file currently stands at a size of &lt;strong&gt;19.2kb&lt;/strong&gt;. I know it’s not super huge, and there will undoubtedly be bigger ones out there, but the concept of this activity can go a long way in most cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s begin
&lt;/h2&gt;

&lt;p&gt;There are already tools available for use with getting rid of old, unused CSS, so I will be utilizing one of them in this tutorial, namely &lt;a href="https://github.com/purifycss/purifycss"&gt;PurifyCSS&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  If you haven’t already got it, you will need to install Node, as this will be used to execute our code. Download and install &lt;a href="https://nodejs.org/en/download/"&gt;Node here&lt;/a&gt; which will include the package manager NPM.&lt;/li&gt;
&lt;li&gt;  You will also need a text editor, and if you haven’t got one, I strongly recommend using &lt;a href="https://code.visualstudio.com/download"&gt;Visual Studio Code&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Understanding how PurifyCSS works
&lt;/h3&gt;

&lt;p&gt;PurifyCSS works by grabbing all HTML files specified for process comparison against any given CSS file. So, the important thing here is not to miss that you most likely can’t just supply your index.html file. This is because you will probably have different HTML and classes on through a range of templates on your website.&lt;/p&gt;

&lt;p&gt;For example, In the case of CodeWall, the following pages are slightly different so they will need to be included.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Homepage&lt;/li&gt;
&lt;li&gt;  Category Page&lt;/li&gt;
&lt;li&gt;  Contact Page&lt;/li&gt;
&lt;li&gt;  Newsletter Page&lt;/li&gt;
&lt;li&gt;  Standard Page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This list of files will then vet against one or more CSS files supplied, like style.css and custom.css. In your case, this will probably be different, so try to think of which pages on your website are using the same layouts and which are not. The more unique pages will need to have their source code compared to the CSS file. Otherwise, you will wind up losing CSS that is required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Heres a diagram of how it works on the virtual level – &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gpRkUigz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/03/purifycss-diagram.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gpRkUigz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/03/purifycss-diagram.jpg" alt="purifycss how it works"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How PurifyCSS Works&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing PurifyCSS
&lt;/h3&gt;

&lt;p&gt;Once you have Node installed, you will have access to its package manager, NPM. PurifyCSS has a ready NPM Package for installation, and you can install it by running the following command in your terminal at the root directory of your project folder –&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D purify-css
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Prepping our files
&lt;/h3&gt;

&lt;p&gt;So, for the purifier to work, we need some input in the form of HTML source code also with some CSS source code, which could be of multiple instances. In our case, the main bulk of our CSS is in the style.css file, which comes with the WordPress theme we use.&lt;/p&gt;

&lt;p&gt;In your root directory, you will need to create an HTML file for each HTML layout you want to process, in our case, it will be of the following templates –&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Homepage&lt;/li&gt;
&lt;li&gt;  Category&lt;/li&gt;
&lt;li&gt;  Contact&lt;/li&gt;
&lt;li&gt;  Newsletter&lt;/li&gt;
&lt;li&gt;  Page&lt;/li&gt;
&lt;li&gt;  Post&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you’ve created the template files to match your site, directly navigate to the actual working template pages of your website, view the source, copy and paste it into the new files you created in your root directory.&lt;/p&gt;

&lt;p&gt;Then to create a .css file or a few if you have more you want to process, in this example, we re-created a style.css file and copied our full live style.css file contents into it.&lt;/p&gt;

&lt;p&gt;So our root directory for the purify tool looks like this –&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  node_modules/&lt;/li&gt;
&lt;li&gt;  category.html&lt;/li&gt;
&lt;li&gt;  contact.html&lt;/li&gt;
&lt;li&gt;  index.html&lt;/li&gt;
&lt;li&gt;  newsletter.html&lt;/li&gt;
&lt;li&gt;  page.html&lt;/li&gt;
&lt;li&gt;  post.html&lt;/li&gt;
&lt;li&gt;  style.css&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Creating the JS Purifier Script
&lt;/h3&gt;

&lt;p&gt;Now go ahead and create a new .js file in the root directory, something like purifyMyCSS.js&lt;/p&gt;

&lt;p&gt;Add the following JS to the file –&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;purify&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;purify-css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// Glob pattern to ref all HTML files from root directory.&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;css&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// Glob pattern to ref all CSS files from root directory.&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Will write purified CSS to this file.&lt;/span&gt;
        &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purified.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Output file name&lt;/span&gt;
        &lt;span class="na"&gt;minified&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Minify boolean&lt;/span&gt;
        &lt;span class="na"&gt;info&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;// Output information on how much reduction was achieved&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nx"&gt;purify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;css&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;purifiedAndMinifiedResult&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;purifiedAndMinifiedResult&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above code is all is needed to initiate the CSS purifying magic. All is left to do now is run the file via node.&lt;/p&gt;

&lt;h3&gt;
  
  
  Purifying
&lt;/h3&gt;

&lt;p&gt;With all the points followed in this article, you are now prepared to drop all your unused CSS. So let’s do it.&lt;/p&gt;

&lt;p&gt;Run the following command in a terminal at the root directory level –&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node purifyMyCss.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And boom, you should get an output similar to the following –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bDHPioau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/03/purifycss-output.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bDHPioau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/03/purifycss-output.jpg" alt="purifyCSS output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you will have a new file in your root directory, named purified.css, and all the unwanted fluff will have vanished. All that is left to do is copy and paste the contents of the purified.css file over your live CSS file, result!&lt;/p&gt;

&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://github.com/purifycss/purifycss"&gt;PurifyCSS GitHub Repo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.npmjs.com/package/glob"&gt;Glob &lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;PurifyCSS helped shed &lt;strong&gt;13kb &lt;/strong&gt;from our CSS file, which was a &lt;strong&gt;70%&lt;/strong&gt; reduction. That CSS was completely unused and unnecessary. As I mentioned before, this doesn’t seem like much but imagine if your CSS file started at &lt;strong&gt;200kb&lt;/strong&gt;, 70% stripped from that is a great deal! PurifyCSS isn’t the only tool JS plugin out there, but it’s certainly a pleasure to use.&lt;/p&gt;

&lt;p&gt;If you have a single page website, then there is an online tool available for just this use case. Check out &lt;a href="https://uncss-online.com/"&gt;https://uncss-online.com/&lt;/a&gt;, which allows you to paste HTML contents in one input and CSS in the other. Hit the button, and your stripped CSS will be appended to an output box!&lt;/p&gt;

&lt;p&gt;Until next time!&lt;/p&gt;

</description>
      <category>css</category>
      <category>node</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Setting Up a NodeJS Web Server On Your Android Phone or Tablet</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Thu, 07 Nov 2019 19:32:06 +0000</pubDate>
      <link>https://dev.to/danenglishby/setting-up-a-nodejs-web-server-on-your-android-phone-or-tablet-3fim</link>
      <guid>https://dev.to/danenglishby/setting-up-a-nodejs-web-server-on-your-android-phone-or-tablet-3fim</guid>
      <description>&lt;p&gt;I came across a really cool app recently, specifically on my Samsung Galaxy S9 Android device. The app is called Dory and it’s capable of installing a full-working NodeJS environment on your device.&lt;/p&gt;

&lt;p&gt;In this article, I will detail how to get your very first NodeJS web server setup on your device and ultimately connect to a web page locally. It won’t take longer than 10 minutes, so just for the cool factor, it’s well worth the time spent.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; Open the Google Play Store on your device and search for ‘Dory’, see Figure 1 so that you know what it looks like when you see it. Alternatively hit the following link – &lt;a href="https://play.google.com/store/apps/details?id=io.tempage.dorynode&amp;amp;hl=en"&gt;Dory – Node.JS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; Hit the install button and await the app to finish downloading and installing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SxusaeUK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/04/dory-nodejs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SxusaeUK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/04/dory-nodejs.jpg" alt="dory app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 1. Dory NodeJS – Play Store Listing&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; Locate the app on your device and launch it.&lt;/li&gt;
&lt;li&gt; As the app launches you will see a notification at the bottom, informing you of both Node and NPM installing.&lt;/li&gt;
&lt;li&gt; After this, another notification will inform you that they have been installed.&lt;/li&gt;
&lt;li&gt; Next, the NodeJS server will boot automatically, you can see this in the notification center, see Figure 2.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zTKXoqF7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/04/dory-nodejs-running.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zTKXoqF7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/04/dory-nodejs-running.jpg" alt="nodejs running notification"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 2. NodeJS Running Notification&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;Time to write some code and serve our first page!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Find the + icon at the bottom right of the app and tap it.&lt;/li&gt;
&lt;li&gt; Then, tap the ‘Eval Script’ button.&lt;/li&gt;
&lt;li&gt; Delete out the &lt;code&gt;console.log('hello world');&lt;/code&gt; code.&lt;/li&gt;
&lt;li&gt; Add the following code block to the file –&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CodeBlock&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
        &lt;span class="c1"&gt;// Set a response type of plain text for the response&lt;/span&gt;
        &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;writeHead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text/plain&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="c1"&gt;// Send back a response and end the connection&lt;/span&gt;
        &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NodeJS Server Online!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// Start the server on port 3000&lt;/span&gt;
    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;localhost&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; Goto the top right settings menu and use the ‘save as’ feature, save it as server.js in your documents folder.&lt;/li&gt;
&lt;li&gt; Navigate back to the home panel and make sure that the widget for the file is present and secondly make sure the ‘Start’ button is greyed out, meaning its active.&lt;/li&gt;
&lt;li&gt; If not, you can hit the + button, add file, and open the file from your documents folder.&lt;/li&gt;
&lt;li&gt; Now you can open up the browser, and navigate to &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; See Figure 3, an example of my Chrome browser loading up the NodeJS Server.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rLf3IvuT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/04/nodejs-server-online.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rLf3IvuT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/04/nodejs-server-online.jpg" alt="node js server online"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 5. NodeJS Server Online&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;This article shows you the basic instructions to get a NodeJS web server set up on your Android device. But, there are many other features this app offers too. The app comes fresh with NPM, has a file downloader and even has the ability to git clone! The app developers also have some other great applications ready for download as well, one of which is MongoDB, you can check them out &lt;a href="https://play.google.com/store/apps/collection/cluster?clp=igM4ChkKEzYwMTg3MzkwNTE5MjY4NDkyNzMQCBgDEhkKE2lvLnRlbXBhZ2UuZG9yeW5vZGUQARgDGAE%3D:S:ANO1ljKmRrU&amp;amp;gsr=CjuKAzgKGQoTNjAxODczOTA1MTkyNjg0OTI3MxAIGAMSGQoTaW8udGVtcGFnZS5kb3J5bm9kZRABGAMYAQ%3D%3D:S:ANO1ljLGLD0"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cross Posted From : &lt;a href="https://www.codewall.co.uk/"&gt;https://www.codewall.co.uk/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>android</category>
    </item>
    <item>
      <title>How To Build A Twitter Hashtag Tweets Viewing Tool Tutorial</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Wed, 06 Nov 2019 20:19:36 +0000</pubDate>
      <link>https://dev.to/danenglishby/how-to-build-a-twitter-hashtag-tweets-viewing-tool-tutorial-4eee</link>
      <guid>https://dev.to/danenglishby/how-to-build-a-twitter-hashtag-tweets-viewing-tool-tutorial-4eee</guid>
      <description>&lt;p&gt;Twitter is an incredible social media platform for end users but, it’s also immense for data analyzers too. Twitter offers an API to conduct informative searches and display these results in your own web tools. From there, the world is your oyster, especially for social media marketers.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will build a simple website that displays tweets with performance indicators like ‘Retweets’ and ‘Favorites’ for any hashtag we desire. The website will be built on NodeJS with ExpressJS, if you’ve already got this then great, if not, you can follow my tutorial here – &lt;a href="https://www.codewall.co.uk/setting-up-a-local-web-server-with-nodejs-expressjs/"&gt;basic NodeJS &amp;amp; ExpressJS setup&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Here is the final result below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZIXWXwpm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/twitter-hashtag-analyzer-1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZIXWXwpm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/twitter-hashtag-analyzer-1.jpg" alt="twitter hashtag analyzer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;The code used in this tutorial will be entirely JavaScript, CSS &amp;amp; HTML, so, all you need in place is the following two points.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Apply for a &lt;a href="https://developer.twitter.com/content/developer-twitter/en.html"&gt;Twitter Developers Account&lt;/a&gt; and wait for approval (This could take up to a couple of weeks)&lt;/li&gt;
&lt;li&gt; A &lt;a href="https://www.codewall.co.uk/setting-up-a-local-web-server-with-nodejs-expressjs/"&gt;basic NodeJS &amp;amp; ExpressJS setup&lt;/a&gt;, you can follow my earlier tutorial to get this up and running in less than 30 mins!&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Installing &amp;amp; Configuring Twit
&lt;/h3&gt;

&lt;p&gt;First up, we need to install the beautiful &lt;a href="https://github.com/ttezel/twit"&gt;Twit&lt;/a&gt; library which allows us to configure our API credentials and also gives us some pre-defined API functionality. Twit is a neat Twitter API client for Node and saves a boatload of time fleshing out all the code yourself.&lt;/p&gt;

&lt;p&gt;Install Twit by running&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install twit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, require the library in your server.js file by adding the following code near to the top of the file –&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;twit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;twit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Lastly, configure a new Twit instance with your API credentials –&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;Twitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;twit&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;consumer_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your_consumer_key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;consumer_secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your_consumer_secret&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;access_token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your_access_token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;access_token_secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your_access_token_secret&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;timeout_ms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// optional HTTP request timeout to apply to all requests.&lt;/span&gt;
            &lt;span class="na"&gt;strictSSL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// optional - requires SSL certificates to be valid.&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Searching for some tweets
&lt;/h3&gt;

&lt;p&gt;Before we make it all beautiful and user-friendly, we can test searching for tweets from a hashtag by running the API call and logging the response to the console. For this example, I used the ‘#100DaysOfCode’ hashtag for the &lt;code&gt;q&lt;/code&gt; parameter, which I like to think stands for ‘Query’.&lt;/p&gt;

&lt;p&gt;Let’s add the code to search tweets on Twitter, just after the Twit instance setup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="nx"&gt;Twitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;search/tweets&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;q&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#100DaysOfCode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;result_type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mixed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
    &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;caught error&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now re-run your server.js file and check out the response in the console, it should look similar to below –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uZCpsPet--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/100daysofcode-tweets.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uZCpsPet--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/100daysofcode-tweets.jpg" alt="100daysofcode tweets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see from the screenshot above, each tweet comes with a lot of useful data, albeit some of it hidden within the console because they are further objects, but still really handy data. The most obvious pieces of data are the &lt;strong&gt;retweet_count&lt;/strong&gt; and &lt;strong&gt;favorite_count&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  So, how do we make this user-friendly and ultimately digestible information?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; Add a single HTML input field to allow submission of hashtags to the backend.&lt;/li&gt;
&lt;li&gt; Configuring the server.js file to handle post data from the HTML form and use it within the API call.&lt;/li&gt;
&lt;li&gt; Return the response to our index file.&lt;/li&gt;
&lt;li&gt; Parse the data and build our beautiful HTML.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s go…&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding an HTML form to the index.ejs file
&lt;/h3&gt;

&lt;p&gt;Add the following code to your index.ejs file, for quickness I’ve used the bootstrap and font awesome CDN.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;
    &lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Twitter Hashtag Viewer&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;
            &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/css/style.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;
            &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form mb-2 mt-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
            &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"post"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"input-group"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"hashtag"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"eg. #100DaysOfCode"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"Analyze!"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;   
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

      &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With the above code inserted into your file, it should look something like below –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LdEuhCQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/search-bar-screenshot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LdEuhCQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/search-bar-screenshot.png" alt="search bar screen shot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring Our server.js to handle Post requests
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Installing and configuring Body-parser
&lt;/h4&gt;

&lt;p&gt;Now we need to write the logic to handle the posting of input values into the form above. First of all, we need to install some middleware which will give us this functionality, namely body-parser. Body-parser has access to the req and res objects giving us the ability to interrogate what data is passed during the post.&lt;/p&gt;

&lt;p&gt;Run the following command to install it –&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    npm install body-parser --save
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then, at the top of your server.js file, require it, and lastly, tell the app to utilize its power.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bodyParser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;body-parser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bodyParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;urlencoded&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;extended&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Adding our post handler
&lt;/h4&gt;

&lt;p&gt;Add the following JS to your server.js file which will handle a simple posting of the hashtag input form with the name ‘hashtag’.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hashtag&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hashtag&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;hashtag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hashtag&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;hashtag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Adjusting the index file to print hashtag variable passed in from the post handler
&lt;/h4&gt;

&lt;p&gt;Add the following EJS markup to your index.ejs file, somewhere that you want the hashtag to print out after it’s been submitted to the server and returned as a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="o"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hashtag&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;All&lt;/span&gt; &lt;span class="nx"&gt;popular&lt;/span&gt; &lt;span class="nx"&gt;tweets&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;%-&lt;/span&gt; &lt;span class="nx"&gt;hashtag&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, if you reboot your server, navigate to the index file and submit a new hashtag, you should see the value printed to the page! See below, I submitted the hashtag ‘code’&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5o4BZrK5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/posted-hashtag-screenshot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5o4BZrK5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/posted-hashtag-screenshot.png" alt="posted hashtag screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Putting it all together and displaying tweets
&lt;/h3&gt;

&lt;p&gt;So, we’ve got our Twitter API client ready, the ability to post data from an HTML form, all is left to do is build the logic for the API call to include the hashtag and return data to the index file. Once that’s done, we can format the data to look good and digestible.&lt;/p&gt;

&lt;p&gt;The next pieces of code will need to be completely changed if you want to build more functionality into the project, but for now, it’s sole purpose is to handle hashtag inputs and query the Twitter API with them.&lt;/p&gt;

&lt;h4&gt;
  
  
  Edit your server.js files post handler
&lt;/h4&gt;

&lt;p&gt;Adjust your Post handler to look the same as below, with your own API credentials –&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hashtag&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

          &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;Twitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;twit&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;consumer_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your_consumer_key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;consumer_secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your_consumer_secret&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;access_token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your_access_token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;access_token_secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your_access_token_secret&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;timeout_ms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// optional HTTP request timeout to apply to all requests.&lt;/span&gt;
            &lt;span class="na"&gt;strictSSL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// optional - requires SSL certificates to be valid.&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="nx"&gt;Twitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;search/tweets&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;q&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hashtag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// use the user posted hashtag value as the query&lt;/span&gt;
            &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;result_type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mixed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 

        &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;caught error&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;hashtag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="c1"&gt;// Render the index page passing in the hashtag and the Twitter API results&lt;/span&gt;
            &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;hashtag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hashtag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                &lt;span class="na"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Edit your index.ejs file to handle the Twitter Data
&lt;/h4&gt;

&lt;p&gt;Adjust your index.ejs file to look similar to below, which does the following –&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Uses font-awesome for like and retweet icons&lt;/li&gt;
&lt;li&gt;  Logic to handle if twitter data is present&lt;/li&gt;
&lt;li&gt;  JavaScript to build and append HTML to the page
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;
    &lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Twitter Hashtag Viewer&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;
            &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/css/style.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;
            &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form mb-2 mt-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
            &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"post"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"input-group"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"hashtag"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"eg. #100DaysOfCode"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"Analyze!"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;   


        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container-fluid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt; &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="na"&gt;hashtag&lt;/span&gt; &lt;span class="err"&gt;!==&lt;/span&gt; &lt;span class="na"&gt;null&lt;/span&gt;&lt;span class="err"&gt;){&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;All popular tweets for &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="na"&gt;-&lt;/span&gt; &lt;span class="na"&gt;hashtag&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt; &lt;span class="err"&gt;}&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"tweets"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt; &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="na"&gt;twitterData&lt;/span&gt; &lt;span class="err"&gt;!==&lt;/span&gt; &lt;span class="na"&gt;null&lt;/span&gt;&lt;span class="err"&gt;){&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;


        &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;twitterData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;%-&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;tweetHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;div class="row"&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statuses&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;createdDateTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statuses&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;created_at&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toUTCString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

                &lt;span class="nx"&gt;tweetHTML&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;div class="col-sm-4"&amp;gt;&amp;lt;div class="card mb-3"&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;div class="card-body"&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;h5 class="card-title"&amp;gt;@&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statuses&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen_name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;/h5&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;h6 class="card-subtitle mb-2 text-muted"&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statuses&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;/h6&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;p class="card-text"&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statuses&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;p class="card-text"&amp;gt;&amp;lt;i class="fa fa-retweet" aria-hidden="true"&amp;gt;&amp;lt;/i&amp;gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statuses&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;retweet_count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &amp;lt;i class="fa fa-heart" style="color:red;" aria-hidden="true"&amp;gt;&amp;lt;/i&amp;gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;twitterData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statuses&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;favorite_count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;

                  &lt;span class="c1"&gt;//  '&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;card-link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Another&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&amp;gt;' &lt;/span&gt;&lt;span class="err"&gt;+
&lt;/span&gt;                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;p class="card-text"&amp;gt;&amp;lt;small class="text-muted"&amp;gt;Created on &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;createdDateTime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &amp;lt;/small&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nx"&gt;tweetHTML&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;tweetsContainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tweets&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;tweetsContainer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;insertAdjacentHTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;beforeend&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;tweetHTML&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt; &lt;span class="err"&gt;}&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;



        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Save both files and reboot your Node server, navigate to the index page and search for a tweet. You should now have a very clean HTML page with all of the popular and latest tweets for that hashtag, see example below for #code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HA5dBg8G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/code-hashtag-tweets-screenshot.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HA5dBg8G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/05/code-hashtag-tweets-screenshot.jpg" alt="code hashtag tweets screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;This tutorial was written to once again show the power of the Twitter API’s many uses, with data like this the information can be forever valuable. Especially to businesses looking for trends. Whatever your ideas, this article gives you a strong foundation to get set up quickly and analyze tweets from within your own project. Check out the &lt;a href="https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html"&gt;Twitter Standard search API documentation&lt;/a&gt; for further reading on the API method used in this article.&lt;/p&gt;

&lt;p&gt;Twitter is an incredible social media platform for end-users but, it’s also immense for data analyzers too. Twitter offers an API to conduct informative searches and display these results in your own web tools. From there, the world is your oyster, especially for social media marketers.&lt;/p&gt;

&lt;p&gt;Cross Posted From : &lt;a href="https://www.codewall.co.uk/"&gt;https://www.codewall.co.uk/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>twitterapi</category>
      <category>api</category>
    </item>
    <item>
      <title>How To Log Like A Pro With Laravel &amp; LogViewer</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Wed, 06 Nov 2019 19:32:09 +0000</pubDate>
      <link>https://dev.to/danenglishby/how-to-log-like-a-pro-with-laravel-logviewer-30ch</link>
      <guid>https://dev.to/danenglishby/how-to-log-like-a-pro-with-laravel-logviewer-30ch</guid>
      <description>&lt;p&gt;Laravel ships with a &lt;a href="https://laravel.com/docs/5.8/logging"&gt;logging system&lt;/a&gt; that is easily utilized, these logs end up .txt log files within your project. Whilst in the text files, they are pretty useless and boring, but if you add a lovely little plugin named &lt;a href="https://github.com/ARCANEDEV/LogViewer"&gt;LogViewer&lt;/a&gt;, things become pretty awesome. LogView works with Laravel 5.0 all the way through to 5.8 so, most likely, you will be able to use it immediately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, let’s see what log viewer gives us.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The following text is generally what you will see in your log files –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fUkjfPHv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-example.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fUkjfPHv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-example.png" alt="log file contents"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From this, with LogViewer, it is transformed into the following –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KUrPQjxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-screenshot1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KUrPQjxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-screenshot1.png" alt="log viewer dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Log Viewer Dashboard&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZJl35SRu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-screenshot3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZJl35SRu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-screenshot3.png" alt="Log Viewer Overview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Log Viewer Overview&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BzOzI3Ny--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-screenshot2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BzOzI3Ny--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-screenshot2.png" alt="log viewer log details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Log Viewer Log Details&lt;/p&gt;

&lt;p&gt;Which, frankly is pretty amazing, considering that all this data is stored in a boring plain text file. So, how can I start using Log Viewer you ask? Simply follow the rest of this tutorial, which will explain how to install the Log Viewer and in addition, go into how you can utilize your own custom logs throughout your code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing LogViewer
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Step 1&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;If you’ve got Laravel 5.8, then run the following command, this will install the LogViewer package and publish it automatically.  Otherwise, check out the version compatibility table to find the matching version located on &lt;a href="https://github.com/ARCANEDEV/LogViewer/blob/master/_docs/1.Installation-and-Setup.md"&gt;this page here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require arcanedev/log-viewer:~4.7.0&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Step 2&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;If your Laravel version &amp;gt; 5.5&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Open your .env file and change the LOG_CHANNEL value to &lt;code&gt;daily&lt;/code&gt; rather than &lt;code&gt;stack&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt; Just to make sure it automatically published run the following command – &lt;code&gt;php artisan log-viewer:publish&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;If your Laravel version &amp;lt;= 5.5&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Open your .env file and add the following full line  &lt;code&gt;APP_LOG=daily&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Add the following line to your config/app providers &lt;code&gt;Arcanedev\LogViewer\LogViewerServiceProvider::class,&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Then run the following command – &lt;code&gt;php artisan log-viewer:publish&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Step 3&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Navigate to your &lt;a href="http://yourrooturl/log-viewer"&gt;http://yourrooturl/log-viewer&lt;/a&gt;, In my case, for this tutorial it’s &lt;a href="http://localhost/LaravelLogger/log-viewer"&gt;http://localhost/LaravelLogger/log-viewer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You should now see the LogViewer dashboard.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Custom Logs
&lt;/h3&gt;

&lt;p&gt;If you’ve only recently installed Laravel, you will notice that you don’t have many logs at all in the dashboard. As you can see from my screenshot earlier, I had a few error logs. (See below)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KUrPQjxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-screenshot1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KUrPQjxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-screenshot1.png" alt="log viewer dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Log Viewer Dashboard&lt;/p&gt;

&lt;p&gt;But notice all of those other potential logs,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Emergency&lt;/li&gt;
&lt;li&gt;  Alert&lt;/li&gt;
&lt;li&gt;  Critical&lt;/li&gt;
&lt;li&gt;  Warning&lt;/li&gt;
&lt;li&gt;  Notice&lt;/li&gt;
&lt;li&gt;  Info&lt;/li&gt;
&lt;li&gt;  Debug&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can easily utilize these logs in your code, there’s actually a lot of documentation on how to use the &lt;a href="https://laravel.com/docs/5.8/logging"&gt;logging system on the Laravel website.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, I will quickly show you how easy it is to start using the logs immediately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To use the logging system, you will need to reference it, add the following at the top of your controller or file of choice –&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    use Illuminate\Support\Facades\Log;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make some logs! For this example, I will simply add the following commands inside one of my controller functions. Specifically, my home controller index function. You can repeat this into the file of choice where you’ve referenced the Log library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    public function index() {

            // Lets add some logs.
            Log::alert("This is a new Alert!");
            Log::critical("This is a critical error message");
            Log::debug("This is a debug message");
            Log::emergency("There is an emergency! Help!?!?!?!");
            Log::error("Houston, we have an error");
            Log::info("An informative message");
            Log::notice("Notice!");
            Log::warning("Be warned, be very warned");
            return view('home.index');
        }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then, load up the page where the logs will be executed and navigate back to the log viewer. See the result below –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LRZv0hPX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/dashboard-full-of-logs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LRZv0hPX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/dashboard-full-of-logs.png" alt="dashboard full of logs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the dashboard is full of logs! Albeit beautifully colorful, we wouldn’t really want to see this all in production!&lt;/p&gt;

&lt;p&gt;If you go into the logs page, you can see each of the logs have incremented by one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jcPYQzY1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-full-logs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jcPYQzY1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/log-viewer-full-logs.png" alt="log viewer full of logs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, we can click into these, for the screenshot below, I clicked into the emergency log to see the detail –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IJbl5mJ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/emergency-logs-detail.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IJbl5mJ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/emergency-logs-detail.png" alt="emergency logs detail"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, I’m just playing around here, but you get the gist of how useful these logs can actually be.&lt;/p&gt;

&lt;h3&gt;
  
  
  Another Example
&lt;/h3&gt;

&lt;p&gt;Add the logs to some try-catch blocks in your code and execute it, this will deliver the exception message to your log viewer –&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    try {
        // some code to throw an exception
        $divisionByZero = 5 / 0; // Divide 5 by zero
    } catch (\Exception $e) {
        Log::emergency("Exception Message: ".$e-&amp;gt;getMessage()  . " File: " . $e-&amp;gt;getFile() . " Line: " . $e-&amp;gt;getLine());
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After executing the above code and going into the log viewer, something like the following will be shown –&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--et6A0SOd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/exception_log.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--et6A0SOd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.codewall.co.uk/wp-content/uploads/2019/09/exception_log.png" alt="exception log"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;LogViewer and Laravel logs have endless possibilities, whether it be an informative log that tells you people are logging off the website, registering, etc. Or of course, the many bugs we catch throughout our development lives. I hope you get as excited to use this as I first did!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Many thanks to &lt;a href="https://github.com/ARCANEDEV/LogViewer"&gt;ARCANEDEV on GitHub&lt;/a&gt; for making logging glorious!&lt;/li&gt;
&lt;li&gt;  Don’t forget to check out the &lt;a href="https://laravel.com/docs/5.8/logging"&gt;logging documentation&lt;/a&gt; on Laravel’s website.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cross Posted From: &lt;a href="https://www.codewall.co.uk/"&gt;https://www.codewall.co.uk/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
    </item>
    <item>
      <title>PHP Date &amp; Strtotime Cheat Sheet with PDF</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Mon, 26 Aug 2019 19:24:00 +0000</pubDate>
      <link>https://dev.to/danenglishby/php-date-strtotime-cheat-sheet-with-pdf-1ni8</link>
      <guid>https://dev.to/danenglishby/php-date-strtotime-cheat-sheet-with-pdf-1ni8</guid>
      <description>&lt;p&gt;If you want to bookmark the original post, feel free with the following link - &lt;a href="https://www.codewall.co.uk/php-date-strtotime-cheat-sheet/"&gt;https://www.codewall.co.uk/php-date-strtotime-cheat-sheet/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you've been developing some projects that are data-rich like me, you will of seen yourself using the &lt;code&gt;Date&lt;/code&gt; function and the &lt;code&gt;Date&lt;/code&gt; function mixed with &lt;code&gt;strtotime&lt;/code&gt;, &lt;code&gt;Date&lt;/code&gt; &amp;amp; &lt;code&gt;strtotime&lt;/code&gt; are very powerful tools, enabling you to set date criteria very swiftly, no matter the scenario. It's simply all about knowing how to do it, as there are a lot of commands you can give these functions that are extremely useful. For example, '-7 days'. This article will be an online cheat sheet, but at the end of the article, there will be a download link with the most popular 'cheats' that can be printed perfectly on an A4 piece of paper. You can download the &lt;a href="https://www.codewall.co.uk/assets/pdfs/date-strtotime-cheat-sheet.pdf"&gt;PDF Here&lt;/a&gt; or at the end of this page.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Current Date &amp;amp; Time Formatting&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  4 Digit Year
&lt;/li&gt;
&lt;li&gt;  2 Digit Year
&lt;/li&gt;
&lt;li&gt;  Month Number
&lt;/li&gt;
&lt;li&gt;  Day Number
&lt;/li&gt;
&lt;li&gt;  2 Digit Year
&lt;/li&gt;
&lt;li&gt;  4 Digit Year
&lt;/li&gt;
&lt;li&gt;  12 &amp;amp; 24 Hour Format Hour
&lt;/li&gt;
&lt;li&gt;  Minutes
&lt;/li&gt;
&lt;li&gt;  Seconds
&lt;/li&gt;
&lt;li&gt;  Date Time Stamp
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom Date &amp;amp; Time Formatting&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Date &amp;amp; Time Manipulation With strtotime&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;*   First day of the month

&lt;ul&gt;
&lt;li&gt;  Last day of the month
&lt;/li&gt;
&lt;li&gt;  Subtract days from date
&lt;/li&gt;
&lt;li&gt;  Add days to date
&lt;/li&gt;
&lt;li&gt;  Subtract months from date
&lt;/li&gt;
&lt;li&gt;  Add months to date
&lt;/li&gt;
&lt;li&gt;  Subtract years from date
&lt;/li&gt;
&lt;li&gt;  Add years to date
&lt;/li&gt;
&lt;li&gt;  Subtract hours from date
&lt;/li&gt;
&lt;li&gt;  Add hours to date
&lt;/li&gt;
&lt;li&gt;  Subtract minutes from date
&lt;/li&gt;
&lt;li&gt;  Add minutes to date
&lt;/li&gt;
&lt;li&gt;  Subtract seconds from date
&lt;/li&gt;
&lt;li&gt;  Add seconds to date
&lt;/li&gt;
&lt;li&gt;  Get yesterdays date
&lt;/li&gt;
&lt;li&gt;  Get tomorrows date
&lt;/li&gt;
&lt;li&gt;  Get next date
&lt;/li&gt;
&lt;li&gt;  Get previous date
&lt;/li&gt;
&lt;li&gt;  Next day name
&lt;/li&gt;
&lt;li&gt;  Last day name
&lt;/li&gt;
&lt;li&gt;  First day of month name
&lt;/li&gt;
&lt;li&gt;  Last day of month name
&lt;/li&gt;
&lt;li&gt;  Noon - Midnight Date
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Current Date &amp;amp; Time Formatting
&lt;/h3&gt;

&lt;p&gt;Let's start with plain old Date formatting, there are hundreds of variations available, but you will probably only ever use a few! &lt;strong&gt;Please Note: &lt;/strong&gt;All examples in this section work with the &lt;strong&gt;Current Date Time, &lt;/strong&gt;meaning the real-time-stamp of your computer at the time of execution!&lt;/p&gt;

&lt;h5&gt;
  
  
  4 Digit Year (#4-digit-year)
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
  &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 2019&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  2 Digit Year
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'y'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 19&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Month Number
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'m'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 08&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Day Number
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'d'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 26&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Date With 2 Digit Year
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'y-m-d'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 19-08-26&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Date With 4 Digit Year
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 2019-08-26&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  12 Hour &amp;amp; 24 Hour Format Hours
&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;Quick note: &lt;/strong&gt;There are 2 ways to access the hour from the date() function, use the following parameters to yield an identical result -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;date('g')&lt;/code&gt; -  (12 Hour Format) or &lt;code&gt;date('G')&lt;/code&gt; - (24 Hour Format)&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;date('h')&lt;/code&gt; -  (12 Hour Format) or &lt;code&gt;date('H')&lt;/code&gt; - (24 Hour Format)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'h'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 11 (am) (12 Hour Format Style)&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'H'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 11 (am) (24 Hour Format Style)&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'g'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 11 (am) (12 Hour Format Style)&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'G'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 11 (am) (24 Hour Format Style)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Minutes
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'i'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// outputs: 08 (Minutes 00-59)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Seconds
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'s'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// outputs: 56 (Seconds 00-59)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Date Time Stamp
&lt;/h5&gt;

&lt;p&gt;Now with all of these parameters in thought, we can produce a proper date-time stamp in the format of &lt;strong&gt;YYYY-MM-DD HH:MM:SS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d h:i:s'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 2019-08-26 09:48:01&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And if we want to do it the other way, swapping the place of the year so that the format is &lt;strong&gt;DD-MM-YYYY HH:MM:SS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'d-m-Y h:i:s'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 2019-08-26 09:48:01&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Custom Date &amp;amp; Time Formatting With strtotime
&lt;/h3&gt;

&lt;p&gt;Using a custom date or date-time with the date function is very straight forward. All's you need to do is pass in the date with the &lt;code&gt;strtotime&lt;/code&gt; function after the formatting parameters is set. See the example below, notice that the passed in date format is &lt;strong&gt;YYYY-MM-DD&lt;/strong&gt; and that the actual output is &lt;strong&gt;DD-MM-YYYY&lt;/strong&gt; because of the specified formatting. &lt;strong&gt;Example 1&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'d-m-Y h:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2018-01-31 00:00:01'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 31-01-2018 12:00:01&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This exact methodology of using the date function will work with all the formatting displayed in the first section of this article, &lt;strong&gt;Example 2&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-26'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// outputs 2019-08-05&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So, the date function will format the &lt;code&gt;strtotime&lt;/code&gt; date passed into whichever format parameters are specified. So another example, to get the day of the month number from the date passed in goes like this - &lt;strong&gt;Example 3&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'d'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-26'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// outputs 05&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Date &amp;amp; Time Manipulation with strtotime
&lt;/h3&gt;

&lt;p&gt;To be honest, &lt;code&gt;strtotime&lt;/code&gt; is an absolute godsend, being able to give it a parameter in a language that you actually speak is awesome. Eg. 'First day of this month' or 'First day of this week' and so on. This can be utilized without a custom date, so basically, the date-time of your server, or a date-time of your specification. In this next section, I will demonstrate both use-cases.&lt;/p&gt;

&lt;h5&gt;
  
  
  First day of the month
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d h:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'first day of this month'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 2019-08-01 19:35:00&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time &lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d h:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'first day of this month'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-12-31 19:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// 2019-12-01 07:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Last day of the month
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d h:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'last day of this month'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 2019-08-31 19:35:00&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time &lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d h:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'last day of this month'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-12-31 19:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// 2019-12-01 07:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Subtract days from date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-7 days'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-19 11:43:59&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time &lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-7 days'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-06 14:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Add days to date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+7 days'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-09-01 11:43:59&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time &lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+7 days'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-20 14:00:00&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Subtract months from date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-7 months'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-01-26 11:56:06&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-7 months'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2020-03-13 14:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Add months to date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+7 months'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2020-03-26 11:56:45&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+7 months'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2020-03-13 14:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Subtract years from date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-5 years'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2014-08-26 11:57:16&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-5 years'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2014-08-13 14:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Add years to date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+7 years'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2024-03-26 11:48:16&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+7 years'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2024-03-13 14:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Subtract hours from date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-12 hours'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-25 23:21:23&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-12 hours'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-13 02:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Add hours to date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+12 hours'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-26 23:21:53&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+12 hours'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-14 02:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Subtract minutes from date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-60 minutes'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-26 10:48:23&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-60 minutes'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-13 02:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Add minutes to date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+60 minutes'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-26 12:30:33&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+60 minutes'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-13 13:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Subtract seconds from date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-300 seconds'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-26 11:40:33&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'-300 seconds'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-13 13:55:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Add seconds to date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+60 seconds'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-26 11:50:58&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'+60 seconds'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-13 14:05:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Get the yesterdays date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'yesterday'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-25 00:00:00&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'yesterday'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-12 00:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Get tomorrows date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'tomorrow'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-27 00:00:00&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'tomorrow'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-14 00:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Get next date
&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: the next parameter works along with &lt;strong&gt;day&lt;/strong&gt;, &lt;strong&gt;month&lt;/strong&gt; and &lt;strong&gt;year&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'next month'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-09-26 20:40:43&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'next year'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2020-08-13 14:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Get previous date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="c1"&gt;// Using server date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'previous month'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-07-26 20:40:43&lt;/span&gt;

    &lt;span class="c1"&gt;//Using custom date-time&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'previous year'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2019-08-13 14:00:00'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2018-08-13 14:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Next day name
&lt;/h5&gt;

&lt;p&gt;Note: short month name or full month name can be used, eg. Sat or Saturday&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'next saturday'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-31 00:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Last day name
&lt;/h5&gt;

&lt;p&gt;Note: short month name or full month name can be used, eg. Sat or Saturday&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'last saturday'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-24 00:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  First day of month name
&lt;/h5&gt;

&lt;p&gt;Note: short month name or full month name can be used, eg. Feb or February&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'first day of February'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-02-01 00:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Last day of month name
&lt;/h5&gt;

&lt;p&gt;Note: short month name or full month name can be used, eg. Feb or February&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'last day of February'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-02-28 00:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Noon And Midnight Date
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'midnight'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-26 00:00:00&lt;/span&gt;

    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strtotime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'noon'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: 2019-08-26 00:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;    &lt;strong&gt;PDF Download&lt;/strong&gt; Feel free to download this compacted cheat-sheet pdf. You can download the &lt;a href="https://www.codewall.co.uk/assets/pdfs/date-strtotime-cheat-sheet.pdf"&gt;PDF Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to bookmark the original post, feel free with the following link - &lt;a href="https://www.codewall.co.uk/php-date-strtotime-cheat-sheet/"&gt;https://www.codewall.co.uk/php-date-strtotime-cheat-sheet/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
    </item>
    <item>
      <title>A Water Filling d3.js Visualization</title>
      <dc:creator>Dan Englishby</dc:creator>
      <pubDate>Tue, 12 Mar 2019 20:30:32 +0000</pubDate>
      <link>https://dev.to/danenglishby/a-water-filling-d3js-visualization-3eog</link>
      <guid>https://dev.to/danenglishby/a-water-filling-d3js-visualization-3eog</guid>
      <description>&lt;p&gt;I stumbled across a really oddball JavaScript visualization that probably doesn't have a whole range of uses. But in the world we live in nowadays, AI technology and home-smart devices, I thought of a perfect use-case.&lt;/p&gt;

&lt;p&gt;Let's imagine your house combi-boiler (this is what they're called in the UK) is linked to your home internet. Then, you actually had access to its data, namely, how much water is currently being pumped through due to the load-request from the taps!&lt;/p&gt;

&lt;p&gt;With this single value of data, you could build the following JavaScript visualization on your own personal Home-Dashboard.&lt;/p&gt;

&lt;h3&gt;Water Load Gauge&lt;/h3&gt;

&lt;p&gt;&lt;b&gt; Hit the switch to turn on the water! &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/DanEnglishby/embed/ZPJQjq?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;By using a little d3.js and an additional community plugin, this brilliant little visualization can be achieved.&lt;/p&gt;

&lt;p&gt;For reference, the JS used to produce this visualization are found in the following links - &lt;/p&gt;

&lt;p&gt;&lt;a href="https://d3js.org/d3.v3.min.js"&gt;d3.js&lt;/a&gt;&lt;br&gt;
&lt;a href="https://bl.ocks.org//raw/5e5ce9beee483220e2f6/4c2e1e4b0ed515d9d9de26d0996519fc16c2ae43/liquidFillGauge.js"&gt;brattonc liquidFillGauge.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And credit to prakash27dec for the toggle switch snippet which can be found here - &lt;br&gt;
&lt;a href="https://bootsnipp.com/snippets/z8b8y"&gt;prakash27dec toggle switch&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enjoy&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>d3</category>
    </item>
  </channel>
</rss>
