<?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: Philip Obosi</title>
    <description>The latest articles on DEV Community by Philip Obosi (@worldclassdev).</description>
    <link>https://dev.to/worldclassdev</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%2F37337%2Fad3f533b-a532-436b-ad9f-625af9f5a1fd.png</url>
      <title>DEV Community: Philip Obosi</title>
      <link>https://dev.to/worldclassdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/worldclassdev"/>
    <language>en</language>
    <item>
      <title>How to subtitle videos using the VEED API</title>
      <dc:creator>Philip Obosi</dc:creator>
      <pubDate>Tue, 30 Mar 2021 00:46:17 +0000</pubDate>
      <link>https://dev.to/worldclassdev/how-to-subtitle-videos-using-the-veed-api-4152</link>
      <guid>https://dev.to/worldclassdev/how-to-subtitle-videos-using-the-veed-api-4152</guid>
      <description>&lt;p&gt;In modern times, captioning videos has become a major way to make your content standout as it makes it easier to follow along with the dialogue as viewers watch a video.&lt;/p&gt;

&lt;p&gt;Another, not so obvious reason to add captions to your videos is acessibility and improved SEO on video platforms like youtube.&lt;/p&gt;

&lt;p&gt;In this article, we will walk through the steps required to subtitle videos automatically via the VEED API.&lt;/p&gt;

&lt;p&gt;Let’s get into it!&lt;/p&gt;

&lt;h1&gt;
  
  
  Installation &amp;amp; setup
&lt;/h1&gt;

&lt;p&gt;To get started, we will set up the project, install all necessary dependencies  and prepare to get our final result in 4 simple steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Signup and get your API Key
&lt;/h2&gt;

&lt;p&gt;Follow the link to  &lt;a href="https://www.veed.io/signup"&gt;signup for your free Veed account&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you finish signup, you should see your &lt;strong&gt;Workspace Dashboard&lt;/strong&gt;. This is your home for managing your video editing activity on Veed.&lt;/p&gt;

&lt;p&gt;On your &lt;strong&gt;Workspace Dashboard&lt;/strong&gt;, click on the &lt;strong&gt;Settings&lt;/strong&gt; tab on the side menu. This will open up a section as shown below. At the bottom of the page, you will find a button that reads “&lt;strong&gt;&lt;em&gt;Enable API&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;”&lt;/em&gt;. Click on that button to enable the API section of your dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hmN7jd6U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545049240_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hmN7jd6U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545049240_image.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once, you have done that, you will be taken to the section shown below. Here, you can copy your API keys which will be required for all interactions with the API. You will also notice that an &lt;strong&gt;API tab&lt;/strong&gt; has now been added to your side menu for easy access subsequently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GuBcdGv2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545089746_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GuBcdGv2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545089746_image.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
Make sure to use the test key &lt;code&gt;key_test_XXXXXXXXXXXXXX&lt;/code&gt; while in development and switch to the production key &lt;code&gt;key_live_XXXXXXXXXXXXXX&lt;/code&gt; for your deployment environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Install Node and NPM
&lt;/h2&gt;

&lt;p&gt;Make sure you have &lt;code&gt;npm&lt;/code&gt; installed on your system:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v &amp;amp;&amp;amp; npm -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You should see the respective version numbers printed to the console. If not, you can go to the official &lt;a href="https://nodejs.org/en/"&gt;Node.js site&lt;/a&gt; to get installation instructions for your platform.&lt;/p&gt;

&lt;p&gt;Now that you have node and NPM installed, run the commands below to setup the project directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Setup project directory
&lt;/h2&gt;

&lt;p&gt;Create project directory.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir subtitle-video-app 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Enter the directory you just created and initalize the project.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd subtitle-video-app &amp;amp;&amp;amp; npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will create a &lt;code&gt;package.json&lt;/code&gt; file which holds configurations pertaining to the project but most importantly, it will contain the dependencies for this project.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Install dependencies
&lt;/h2&gt;

&lt;p&gt;For this project, the only dependency we need to install is the VEED API Node library. To do so, execute the command below in your terminal.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @veedstudio/veed-node --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now that we have successfully installed the necessary dependencies, for the final step we need to setup our webhook.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Setting up your webhook
&lt;/h2&gt;

&lt;p&gt;Instead of polling the API each time in order to know when our render is complete, the VEED API provides support for a webhook so that users can receive events from time to time when an action worthy of note occurs e.g a render has started, a render has completed e.t.c&lt;/p&gt;

&lt;p&gt;To get a webhook URL for this purpose, head over to &lt;a href="https://webhook.site/"&gt;https://webhook.site/&lt;/a&gt; to retrieve your webhook URL. Copy your unique URL and head over to your Workspace dashboard. On the API tab, you’d see an input labeled &lt;code&gt;Webhook URL&lt;/code&gt;, paste the URL you had copied earlier in there and click “Save”.&lt;/p&gt;

&lt;p&gt;Now that we have done all that, we are ready to start subtitling videos.&lt;/p&gt;

&lt;h1&gt;
  
  
  Subtitling the video
&lt;/h1&gt;

&lt;p&gt;We will break the steps involved in subtitling a video into two as shown below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Upload and transcribe video&lt;/li&gt;
&lt;li&gt;Subtitle video&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Upload and transcribe video
&lt;/h2&gt;

&lt;p&gt;First we need to create the transcription. &lt;strong&gt;Video transcription&lt;/strong&gt; is the process of translating your &lt;strong&gt;video's&lt;/strong&gt; audio into text.&lt;br&gt;
To transcribe a video with the VEED API, you need to create an asset (check out our &lt;a href="https://veed.readme.io/docs/managing-media-assets"&gt;managing media assets guide&lt;/a&gt; for more info on how to do this). As you are creating the asset, you will need to pass the &lt;code&gt;transcribe: true&lt;/code&gt; option as a body parameter. &lt;/p&gt;

&lt;h2&gt;
  
  
  Subtitle video
&lt;/h2&gt;

&lt;p&gt;Once you have your asset uploaded and processed (with the transcription), we can start constructing the render object request for the subtitles.&lt;/p&gt;

&lt;p&gt;First we need to add uploaded asset as a video element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "elements": [
    {
      "type": "video",
      "params": {
        "source": {
          "asset_id": "28a510a8-6690-4cdc-b319-e0e02ebf1a2e" 
        },
      }
    }    
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next step is to create a subtitle element, making sure it references the correct &lt;code&gt;asset_id&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "elements": [
    {
      "type": "video",
      "params": {
        "source": {
          "asset_id": "28a510a8-6690-4cdc-b319-e0e02ebf1a2e" 
        },
      }
    },
    {
      "type": "subtitles",
      "params": {
        "source": {
          "asset_id": "28a510a8-6690-4cdc-b319-e0e02ebf1a2e" 
        },
      }
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now you are ready to send the request. Save the above as a &lt;code&gt;render.json&lt;/code&gt; file, and run this command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-X POST \
  --header "Authorization: veed_test_oEnZhnd3vg0LEoTs6Z9Ij" \
  --data @render.json \
  https://api.veed.io/api/render
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Make sure to use your own API key. You should get a response that looks like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "id": "b477e483-592a-4bc6-a22b-563ef7f48e25",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Getting the result
&lt;/h1&gt;

&lt;p&gt;We recommend using a &lt;a href="https://veed.readme.io/reference#working-with-webhooks"&gt;Webhook&lt;/a&gt; to process all your rendering events, but for this example we'll be polling the API (you can find more info on polling the API here, under '&lt;a href="https://veed.readme.io/docs/making-first-render#getting-the-final-render"&gt;Getting the final render&lt;/a&gt;'):&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl \
  --header "Authorization: veed_test_oEnZhnd3vg0LEoTs6Z9Ij" \
  https://api.veed.io/api/render/b477e483-592a-4bc6-a22b-563ef7f48e25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You should get a &lt;code&gt;RENDER_SUCCESS&lt;/code&gt; response, once the rendering is done:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "type": "RENDER/SUCCESS",
    "payload": {
      "id": "b477e483-592a-4bc6-a22b-563ef7f48e25",
      "progress": 100,
      "url": "https://cdn.veed.dev/R1vqZ0KfPp5y2z7ddiTyt.mp4"
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can use the &lt;code&gt;url&lt;/code&gt;in the response to download the render and enjoy your new video, with hardcoded subtitles!&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting the subtitled video
&lt;/h1&gt;

&lt;p&gt;There are several ways to get the subtitled video. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. Using the webhook
&lt;/h2&gt;

&lt;p&gt;Return to the &lt;a href="https://webhook.site"&gt;https://webhook.site&lt;/a&gt; page where you had copied the webhook URL that you added to the dashboard. You will notice that the several events are being sent to this URL as the render proceeds.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--24cKa6i6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614592144526_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--24cKa6i6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614592144526_image.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the list of events received on the left. You can click on any them to see the data that was sent in each payload. You would notice the the render starts out from progress &lt;code&gt;percentage&lt;/code&gt; &lt;code&gt;0&lt;/code&gt;, up until &lt;code&gt;100&lt;/code&gt; when the render is completed. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "type": "RENDER/PROGRESS",
  "payload": {
    "render_id": "17cf9aad-807d-4f68-98b7-f748b8d67c22",
    "percentage": 0
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;On completion, you get a &lt;code&gt;RENDER/SUCCESS&lt;/code&gt; event which contains the URL to the subtitled video as requested.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "type": "RENDER/SUCCESS",
  "payload": {
    "render_id": "e52aad52-5ab0-465d-8341-fdabd6302cf1",
    "progress": 100,
    "url": "https://storage.googleapis.com/veed-prod-video-bucket/veedapi%2Frenders%2Fe52aad52-5ab0-465d-8341-fdabd6302cf1%2Foutput%2Fh5PIjzgDpai~x1srAbH1X.mp4?X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;amp;X-Goog-Credential=prod-api%40veed-prod-server.iam.gserviceaccount.com%2F20210228%2Fauto%2Fstorage%2Fgoog4_request&amp;amp;X-Goog-Date=20210228T210416Z&amp;amp;X-Goog-Expires=9000&amp;amp;X-Goog-SignedHeaders=host&amp;amp;X-Goog-Signature=4ce2e4664470fb81f450e91fe63bdcd29e1077eed756a94eb3923b5740acbbc4618a91b148a5cd4b3540db615a95f0842893cc013aa965a8099d671724de058852816ec795bd17d483a51b944b8cc461a7b3bf0e3f51b5ed702dde0a5bbada3bb68fcc1de3d6fd1bcb8262f3199b28218d2de0dd9a4b2eaee5583b0ccbd52022e5a99a49f71972ed1c0ba28a9ae2d93f0e1b88f2b1308f8ff6375ad3ae31c80c42a9968d7ee572cfab03c0e153ac3ee67a4cdf9f8f8b4dca3fa42ae4240e01e259aa4808973607a71df681bee691e64d663436600b0b95852d26aa857dfc6d74e571207c93d201f31d0e1505dbc374d36076bf5caccd6a38281771af50017892"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  2. Poll the API
&lt;/h2&gt;

&lt;p&gt;Without the webhook, there is no way to tell at what exact time a render is complete. Hence, another approach will be to poll the API. You can use the VEED package for this. Simply replace &lt;code&gt;veed.render.create(renderOptions)&lt;/code&gt; with &lt;code&gt;veed.render.get({id:'YOUR_RENDER_ID_GOES_HERE'})&lt;/code&gt;. Run the script again. You should see the response printed to the console. If the render is completed and the download URL is ready, you will get a response like the one below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  id: '540ba741-bead-42cd-bcbe-dcd2d0663d8d',
  workspace_id: '78c897c9-810d-4a33-97e2-15c796a05161',
  data: { elements: [ [Object], [Object] ] },
  latest_event: {
    type: 'RENDER/SUCCESS',
    payload: {
      render_id: '540ba741-bead-42cd-bcbe-dcd2d0663d8d',
      progress: 100,
      url: 'https://storage.googleapis.com/veed-prod-video-bucket/veedapi%2Frenders%2F540ba741-bead-42cd-bcbe-dcd2d0663d8d%2Foutput%2FzBG_du_k~qL5dLS9YT6Oa.mp4?X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;amp;X-Goog-Credential=prod-api%40veed-prod-server.iam.gserviceaccount.com%2F20210301%2Fauto%2Fstorage%2Fgoog4_request&amp;amp;X-Goog-Date=20210301T084032Z&amp;amp;X-Goog-Expires=9001&amp;amp;X-Goog-SignedHeaders=host&amp;amp;X-Goog-Signature=7b9dd8d71a055867a1cc0947f24050ec145b863be3c787963f820ff218d9a55201c45b509cbdb48c8460a71c2f3c433c4809c55ffa610c5964d07e7fdcee3f19f3bb2cde93b104b7b66930fde8ccbc278c0a33afac5ad671d6265ab2e6e9ae0a96ddf6103ba7028f3508dfd1fb35aef37dc6a0cf28d245fcfc8d4ef825a3656aec6f0cee6f25c69422351e84d56226129b9168ce364d394bbffd8682b37efdd438b90b259aa964e41b714660343885020b3a4664db37c35019b82f397d270085881098a1ece6a7e2bc4c055d4db6b3ea3137fbd2c7576eb140b8ef1cb2d6479d36094450b2ee82335a84514b5ec14c28ef770eb0c4188e8fde6321ff68ee28a9'
    }
  },
  created_at: 1614588003775,
  modified_at: 1614588032628
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can now copy the &lt;code&gt;url&lt;/code&gt; and paste it into your browser. Hit &lt;code&gt;enter&lt;/code&gt; and the download should start automatically.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Congratulations, you have successfully learnt how to transcribe and subtitle videos in Node using the VEED API. You are encouraged to explore the API further using the documentation and build out your own application or API that utilizes this API in a more clever way and share in the comment section below. &lt;/p&gt;

&lt;p&gt;I’d love to see the magic you create. See you in the next one!&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.veed.io/"&gt;Our website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.veed.io/api"&gt;More about our API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://documentation.veed.io/reference#getting-started"&gt;Our API Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>videoapi</category>
      <category>subtitlevideoapi</category>
      <category>videoeditingapi</category>
      <category>veed</category>
    </item>
    <item>
      <title>How to watermark Videos &amp; Images in Node using the Veed API</title>
      <dc:creator>Philip Obosi</dc:creator>
      <pubDate>Mon, 29 Mar 2021 22:30:39 +0000</pubDate>
      <link>https://dev.to/worldclassdev/how-to-watermark-videos-images-in-node-using-the-veed-api-1lgd</link>
      <guid>https://dev.to/worldclassdev/how-to-watermark-videos-images-in-node-using-the-veed-api-1lgd</guid>
      <description>&lt;p&gt;Watermarking videos is a basic and efficient way to brand your content as in individual or business. The VEED API provides support for doing this automatically which you can very easily take advantage.&lt;/p&gt;

&lt;p&gt;In this article, we walkthrough the steps involved in doing so using Node JS.&lt;/p&gt;

&lt;p&gt;Let’s get right into it!&lt;/p&gt;

&lt;h1&gt;
  
  
  Installation &amp;amp; setup
&lt;/h1&gt;

&lt;p&gt;To get started, we will set up the project, install all necessary dependencies  and prepare to get our final result in 4 simple steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Signup and get your API Key
&lt;/h2&gt;

&lt;p&gt;Follow the link to  &lt;a href="https://www.veed.io/signup"&gt;signup for your free Veed account&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you finish signup, you should see your &lt;strong&gt;Workspace Dashboard&lt;/strong&gt;. This is your home for managing your video editing activity on Veed.&lt;/p&gt;

&lt;p&gt;On your &lt;strong&gt;Workspace Dashboard&lt;/strong&gt;, click on the &lt;strong&gt;Settings&lt;/strong&gt; tab on the side menu. This will open up a section as shown below. At the bottom of the page, you will find a button that reads “&lt;strong&gt;&lt;em&gt;Enable API&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;”&lt;/em&gt;. Click on that button to enable the API section of your dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hmN7jd6U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545049240_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hmN7jd6U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545049240_image.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once, you have done that, you will be taken to the section shown below. Here, you can copy your API keys which will be required for all interactions with the API. You will also notice that an &lt;strong&gt;API tab&lt;/strong&gt; has now been added to your side menu for easy access subsequently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GuBcdGv2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545089746_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GuBcdGv2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545089746_image.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
Make sure to use the test key &lt;code&gt;key_test_XXXXXXXXXXXXXX&lt;/code&gt; while in development and switch to the production key &lt;code&gt;key_live_XXXXXXXXXXXXXX&lt;/code&gt; for your deployment environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Install Node and NPM
&lt;/h2&gt;

&lt;p&gt;Make sure you have &lt;code&gt;npm&lt;/code&gt; installed on your system:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v &amp;amp;&amp;amp; npm -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You should see the respective version numbers printed to the console. If not, you can go to the official &lt;a href="https://nodejs.org/en/"&gt;Node.js site&lt;/a&gt; to get installation instructions for your platform.&lt;/p&gt;

&lt;p&gt;Now that you have node and NPM installed, run the commands below to setup the project directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Setup project directory
&lt;/h2&gt;

&lt;p&gt;Create project directory.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir watermark-video-app 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Enter the directory you just created and initalize the project.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd watermark-video-app &amp;amp;&amp;amp; npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will create a &lt;code&gt;package.json&lt;/code&gt; file which holds configurations pertaining to the project but most importantly, it will contain the dependencies for this project.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Install dependencies
&lt;/h2&gt;

&lt;p&gt;For this project, the only dependency we need to install is the VEED API Node library. To do so, execute the command below in your terminal.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @veedstudio/veed-node --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now that we have successfully installed the necessary dependencies, for the final step we need to setup our webhook.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Setting up your webhook
&lt;/h2&gt;

&lt;p&gt;Instead of polling the API each time in order to know when our render is complete, the VEED API provides support for a webhook so that users can receive events from time to time when an action worthy of note occurs e.g a render has started, a render has completed e.t.c&lt;/p&gt;

&lt;p&gt;To get a webhook URL for this purpose, head over to &lt;a href="https://webhook.site/"&gt;https://webhook.site/&lt;/a&gt; to retrieve your webhook URL. Copy your unique URL and head over to your Workspace dashboard. On the API tab, you’d see an input labeled &lt;code&gt;Webhook URL&lt;/code&gt;, paste the URL you had copied earlier in there and click “Save”.&lt;/p&gt;

&lt;p&gt;Now that we have done all that, we are ready to start watermarking videos.&lt;/p&gt;

&lt;h1&gt;
  
  
  Watermarking the video
&lt;/h1&gt;

&lt;p&gt;Now we are going to write the piece of code that does the actual watermarking. To get started, open the folder we created earlier in your favourite IDE and create a file called &lt;code&gt;index.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Copy and paste the code below into this file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const API_KEY = 'YOUR_API_KEY_HERE';
const veed = require("@veedstudio/veed-node")(API_KEY);

const FILE_URL = 'https://storage.googleapis.com/veed-docs/sample-video.mp4'

const renderOptions = {
    "elements":[
        {
            "type":"video",
            "params":{
                "source":{
                    "url": FILE_URL
                }
            }
        },
        {
            "type":"text",
            "params":{
                "value":"WATERMARK",
                "style":{
                    "font":"Helvetica",
                    "size":48.0,
                    "display":"normal",
                    "color":"#FFFFFF",
                    "secondary_color":"#ffffff",
                    "align":"center",
                    "line_height":0.0,
                    "letter_spacing":0.0,
                },
                "position":{
                    "origin":"bottom left",
                    "x":0.5,
                    "y": 1.0
                },
                "z_index":1
            }
        }
    ]
}

veed.render.create(renderOptions).then((result)=&amp;gt;{
    console.log(result)
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Above, we start by importing the VEED package and initalizing it inline by passing the &lt;code&gt;API_KEY&lt;/code&gt; from our dashboard as an argument.&lt;/p&gt;

&lt;p&gt;Next we declare a variable called &lt;code&gt;FILE_URL&lt;/code&gt; which holds the URL to a sample video to be used for this demo.&lt;/p&gt;

&lt;p&gt;After that, we move on to constructing &lt;strong&gt;the render object&lt;/strong&gt;. The render object is a set of instructions in the form of object properties, that describes which edits should be applied to your media asset. It is typically comprised of render elements and render parameters. In the code snippet above, notice that elements is an array, suggesting that you can add as many elements as you want along with their configurations to achieve your desired outcome.&lt;/p&gt;

&lt;p&gt;Above, we have added one &lt;code&gt;video&lt;/code&gt; element and specified it’s source using the &lt;code&gt;source&lt;/code&gt; parameter . We have also added a &lt;code&gt;text&lt;/code&gt; element that is used specify the watermark to be added as well as it’s configurations.&lt;/p&gt;

&lt;p&gt;Finally, we used the VEED package to create a new render while passing the &lt;code&gt;renderOptions&lt;/code&gt; to it as an argument.&lt;/p&gt;

&lt;p&gt;Now we can run the script from the terminal using the command below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; node index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;On success, you should find a payload containing the render ID as shown below printed on the console.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ id: '163688fb-4626-4f12-a165-12576fe54023' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Getting the watermarked video
&lt;/h1&gt;

&lt;p&gt;There are several ways to get the watermarked video. &lt;/p&gt;
&lt;h2&gt;
  
  
  1. Using the webhook
&lt;/h2&gt;

&lt;p&gt;Return to the &lt;a href="https://webhook.site"&gt;https://webhook.site&lt;/a&gt; page where you had copied the webhook URL that you added to the dashboard. You will notice that the several events are being sent to this URL as the render proceeds.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--24cKa6i6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614592144526_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--24cKa6i6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614592144526_image.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the list of events received on the left. You can click on any them to see the data that was sent in each payload. You would notice the the render starts out from progress &lt;code&gt;percentage&lt;/code&gt; &lt;code&gt;0&lt;/code&gt;, up until &lt;code&gt;100&lt;/code&gt; when the render is completed. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "type": "RENDER/PROGRESS",
  "payload": {
    "render_id": "17cf9aad-807d-4f68-98b7-f748b8d67c22",
    "percentage": 0
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;On completion, you get a &lt;code&gt;RENDER/SUCCESS&lt;/code&gt; event which contains the URL to the watermarked video as requested.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "type": "RENDER/SUCCESS",
  "payload": {
    "render_id": "e52aad52-5ab0-465d-8341-fdabd6302cf1",
    "progress": 100,
    "url": "https://storage.googleapis.com/veed-prod-video-bucket/veedapi%2Frenders%2Fe52aad52-5ab0-465d-8341-fdabd6302cf1%2Foutput%2Fh5PIjzgDpai~x1srAbH1X.mp4?X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;amp;X-Goog-Credential=prod-api%40veed-prod-server.iam.gserviceaccount.com%2F20210228%2Fauto%2Fstorage%2Fgoog4_request&amp;amp;X-Goog-Date=20210228T210416Z&amp;amp;X-Goog-Expires=9000&amp;amp;X-Goog-SignedHeaders=host&amp;amp;X-Goog-Signature=4ce2e4664470fb81f450e91fe63bdcd29e1077eed756a94eb3923b5740acbbc4618a91b148a5cd4b3540db615a95f0842893cc013aa965a8099d671724de058852816ec795bd17d483a51b944b8cc461a7b3bf0e3f51b5ed702dde0a5bbada3bb68fcc1de3d6fd1bcb8262f3199b28218d2de0dd9a4b2eaee5583b0ccbd52022e5a99a49f71972ed1c0ba28a9ae2d93f0e1b88f2b1308f8ff6375ad3ae31c80c42a9968d7ee572cfab03c0e153ac3ee67a4cdf9f8f8b4dca3fa42ae4240e01e259aa4808973607a71df681bee691e64d663436600b0b95852d26aa857dfc6d74e571207c93d201f31d0e1505dbc374d36076bf5caccd6a38281771af50017892"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  2. Poll the API
&lt;/h2&gt;

&lt;p&gt;Without the webhook, there is no way to tell at what exact time a render is complete. Hence, another approach will be to poll the API. You can use the VEED package for this. Simply replace &lt;code&gt;veed.render.create(renderOptions)&lt;/code&gt; with &lt;code&gt;veed.render.get({id:'YOUR_RENDER_ID_GOES_HERE'})&lt;/code&gt;. Run the script again. You should see the response printed to the console. If the render is completed and the download URL is ready, you will get a response like the one below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  id: '540ba741-bead-42cd-bcbe-dcd2d0663d8d',
  workspace_id: '78c897c9-810d-4a33-97e2-15c796a05161',
  data: { elements: [ [Object], [Object] ] },
  latest_event: {
    type: 'RENDER/SUCCESS',
    payload: {
      render_id: '540ba741-bead-42cd-bcbe-dcd2d0663d8d',
      progress: 100,
      url: 'https://storage.googleapis.com/veed-prod-video-bucket/veedapi%2Frenders%2F540ba741-bead-42cd-bcbe-dcd2d0663d8d%2Foutput%2FzBG_du_k~qL5dLS9YT6Oa.mp4?X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;amp;X-Goog-Credential=prod-api%40veed-prod-server.iam.gserviceaccount.com%2F20210301%2Fauto%2Fstorage%2Fgoog4_request&amp;amp;X-Goog-Date=20210301T084032Z&amp;amp;X-Goog-Expires=9001&amp;amp;X-Goog-SignedHeaders=host&amp;amp;X-Goog-Signature=7b9dd8d71a055867a1cc0947f24050ec145b863be3c787963f820ff218d9a55201c45b509cbdb48c8460a71c2f3c433c4809c55ffa610c5964d07e7fdcee3f19f3bb2cde93b104b7b66930fde8ccbc278c0a33afac5ad671d6265ab2e6e9ae0a96ddf6103ba7028f3508dfd1fb35aef37dc6a0cf28d245fcfc8d4ef825a3656aec6f0cee6f25c69422351e84d56226129b9168ce364d394bbffd8682b37efdd438b90b259aa964e41b714660343885020b3a4664db37c35019b82f397d270085881098a1ece6a7e2bc4c055d4db6b3ea3137fbd2c7576eb140b8ef1cb2d6479d36094450b2ee82335a84514b5ec14c28ef770eb0c4188e8fde6321ff68ee28a9'
    }
  },
  created_at: 1614588003775,
  modified_at: 1614588032628
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can now copy the &lt;code&gt;url&lt;/code&gt; and paste it into your browser. Hit &lt;code&gt;enter&lt;/code&gt; and the download should start automatically.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Congratulations, you have successfully learnt how to watermark videos in Node using the VEED API. You are encouraged to explore the API further using the documentation and build out your own application or API that utilizes this API in a more clever way and share in the comment section below. &lt;/p&gt;

&lt;p&gt;I’d love to see the magic you create. See you in the next one!&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.veed.io/"&gt;Our website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.veed.io/api"&gt;More about our API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://documentation.veed.io/reference#getting-started"&gt;Our API Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>videoapi</category>
      <category>videoeditingapi</category>
      <category>watermarkvideoapi</category>
      <category>veed</category>
    </item>
    <item>
      <title>How to trim videos in Node using the Veed API</title>
      <dc:creator>Philip Obosi</dc:creator>
      <pubDate>Sun, 21 Mar 2021 12:13:04 +0000</pubDate>
      <link>https://dev.to/worldclassdev/how-to-trim-videos-in-node-using-the-veed-api-2h8o</link>
      <guid>https://dev.to/worldclassdev/how-to-trim-videos-in-node-using-the-veed-api-2h8o</guid>
      <description>&lt;p&gt;In this age where media has become mainstream, numerous applications have a growing need to manipulate media files e.g video, audio and images programatically. A common use case is being able to trim portions of videos  programatically and get back the clip of the trimmed portion.&lt;/p&gt;

&lt;p&gt;In this article, we will learn how to programatically trim videos in Node JS using the VEED API. &lt;a href="https://veed.io" rel="noopener noreferrer"&gt;VEED.io&lt;/a&gt;  is a simple but powerful online video editor that allows users edit videos ONLINE and for FREE. VEED makes it easy for you to do things  like resize videos, trim videos, crop videos, transcribe and subtitle videos, add filters to videos and lots more. There is also a &lt;a href="https://veed.io/api" rel="noopener noreferrer"&gt;video editing API&lt;/a&gt; that allows you access these functionalities programatically.&lt;/p&gt;

&lt;p&gt;Without further ado, let’s get started.&lt;/p&gt;

&lt;h1&gt;
  
  
  Installation &amp;amp; setup
&lt;/h1&gt;

&lt;p&gt;To get started, we will set up the project, install all necessary dependencies  and prepare to get our final result in 4 simple steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Signup and get your API Key
&lt;/h2&gt;

&lt;p&gt;Follow the link to  &lt;a href="https://www.veed.io/signup" rel="noopener noreferrer"&gt;signup for your free Veed account&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you finish signup, you should see your &lt;strong&gt;Workspace Dashboard&lt;/strong&gt;. This is your home for managing your video editing activity on Veed.&lt;/p&gt;

&lt;p&gt;On your &lt;strong&gt;Workspace Dashboard&lt;/strong&gt;, click on the &lt;strong&gt;Settings&lt;/strong&gt; tab on the side menu. This will open up a section as shown below. At the bottom of the page, you will find a button that reads “&lt;strong&gt;&lt;em&gt;Enable API&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;”&lt;/em&gt;. Click on that button to enable the API section of your dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545049240_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545049240_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once, you have done that, you will be taken to the section shown below. Here, you can copy your API keys which will be required for all interactions with the API. You will also notice that an &lt;strong&gt;API tab&lt;/strong&gt; has now been added to your side menu for easy access subsequently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545089746_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614545089746_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
Make sure to use the test key &lt;code&gt;key_test_XXXXXXXXXXXXXX&lt;/code&gt; while in development and switch to the production key &lt;code&gt;key_live_XXXXXXXXXXXXXX&lt;/code&gt; for your deployment environment.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Install Node and NPM
&lt;/h2&gt;

&lt;p&gt;Make sure you have &lt;code&gt;npm&lt;/code&gt; installed on your system:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v &amp;amp;&amp;amp; npm -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;You should see the respective version numbers printed to the console. If not, you can go to the official &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js site&lt;/a&gt; to get installation instructions for your platform.&lt;/p&gt;

&lt;p&gt;Now that you have node and NPM installed, run the commands below to setup the project directory.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Setup project directory
&lt;/h2&gt;

&lt;p&gt;Create project directory.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir trim-video-app 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Enter the directory you just created and initalize the project.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd trim-video-app &amp;amp;&amp;amp; npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This will create a &lt;code&gt;package.json&lt;/code&gt; file which holds configurations pertaining to the project but most importantly, it will contain the dependencies for this project.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Install dependencies
&lt;/h2&gt;

&lt;p&gt;For this project, the only dependency we need to install is the VEED API Node library. To do so, execute the command below in your terminal.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @veedstudio/veed-node --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now that we have successfully installed the necessary dependencies, for the final step we need to setup our webhook.&lt;/p&gt;
&lt;h2&gt;
  
  
  5. Setting up your webhook
&lt;/h2&gt;

&lt;p&gt;Instead of polling the API each time in order to know when our render is complete, the VEED API provides support for a webhook so that users can receive events from time to time when an action worthy of note occurs e.g a render has started, a render has completed e.t.c&lt;/p&gt;

&lt;p&gt;To get a webhook URL for this purpose, head over to &lt;a href="https://webhook.site/" rel="noopener noreferrer"&gt;https://webhook.site/&lt;/a&gt; to retrieve your webhook URL. Copy your unique URL and head over to your Workspace dashboard. On the API tab, you’d see an input labeled &lt;code&gt;Webhook URL&lt;/code&gt;, paste the URL you had copied earlier in there and click “Save”.&lt;/p&gt;

&lt;p&gt;Now that we have done all that, we are ready to start trimming videos.&lt;/p&gt;
&lt;h1&gt;
  
  
  Trimming the video
&lt;/h1&gt;

&lt;p&gt;Now we are going to write the piece of code that does the actual trimming. To get started, open the folder we created earlier in your favourite IDE and create a file called &lt;code&gt;index.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Copy and paste the code below into this file.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const API_KEY = 'YOUR_API_KEY_HERE';
const veed = require("@veedstudio/veed-node")(API_KEY);

const FILE_URL = 'https://storage.googleapis.com/veed-docs/sample-video.mp4'

const renderOptions = {
    "elements": [
        {
            "type": "video",
            "params": {
                "source": {
                    "url": FILE_URL
                },
                "trim": {
                    "from": 2.0,
                    "to": 5.0
                }
            }
        }
    ]
}

veed.render.create(renderOptions).then((result)=&amp;gt;{
    console.log(result)
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Above, we start by importing the VEED package and initalizing it inline by passing the &lt;code&gt;API_KEY&lt;/code&gt; from our dashboard as an argument.&lt;/p&gt;

&lt;p&gt;Next we declare a variable called &lt;code&gt;FILE_URL&lt;/code&gt; which holds the URL to a sample video to be used for this demo.&lt;/p&gt;

&lt;p&gt;After that, we move on to constructing &lt;strong&gt;the render object&lt;/strong&gt;. The render object is a set of instructions in the form of object properties, that describes which edits should be applied to your media asset. It is typically comprised of render elements and render parameters. In the code snippet above, notice that elements is an array, suggesting that you can add as many elements as you want along with their configurations to achieve your desired outcome.&lt;/p&gt;

&lt;p&gt;For our use case, we have added one &lt;code&gt;video&lt;/code&gt; element. As part of the &lt;code&gt;params&lt;/code&gt;, we specify the &lt;code&gt;source&lt;/code&gt; of the video which points to our sample video and the trim configuration which specifies what point the trimming starts &lt;code&gt;from&lt;/code&gt; and where it ends using the &lt;code&gt;to&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;Finally, we used the VEED package to create a new render while passing the &lt;code&gt;renderOptions&lt;/code&gt; to it as an argument. &lt;/p&gt;

&lt;p&gt;Now we can run the script from the terminal using the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; node index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On success, you should find a payload containing the render ID as shown below printed on the console.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ id: '163688fb-4626-4f12-a165-12576fe54023' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Getting the trimmed video
&lt;/h1&gt;

&lt;p&gt;There are several ways to get the trimmed video. &lt;/p&gt;
&lt;h2&gt;
  
  
  1. Using the webhook
&lt;/h2&gt;

&lt;p&gt;Return to the &lt;a href="https://webhook.site" rel="noopener noreferrer"&gt;https://webhook.site&lt;/a&gt; page where you had copied the webhook URL that you added to the dashboard. You will notice that the several events are being sent to this URL as the render proceeds.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614592144526_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_D366B4D15E6DE887648DB4FE9841A41FEF1A84B6DBBCBBF79F869F7B8C8F0D7A_1614592144526_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the list of events received on the left. You can click on any them to see the data that was sent in each payload. You would notice the the render starts out from progress &lt;code&gt;percentage&lt;/code&gt; &lt;code&gt;0&lt;/code&gt;, up until &lt;code&gt;100&lt;/code&gt; when the render is completed. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "type": "RENDER/PROGRESS",
  "payload": {
    "render_id": "17cf9aad-807d-4f68-98b7-f748b8d67c22",
    "percentage": 0
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;On completion, you get a &lt;code&gt;RENDER/SUCCESS&lt;/code&gt; event which contains the URL to the trimmed video as requested.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "type": "RENDER/SUCCESS",
  "payload": {
    "render_id": "e52aad52-5ab0-465d-8341-fdabd6302cf1",
    "progress": 100,
    "url": "https://storage.googleapis.com/veed-prod-video-bucket/veedapi%2Frenders%2Fe52aad52-5ab0-465d-8341-fdabd6302cf1%2Foutput%2Fh5PIjzgDpai~x1srAbH1X.mp4?X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;amp;X-Goog-Credential=prod-api%40veed-prod-server.iam.gserviceaccount.com%2F20210228%2Fauto%2Fstorage%2Fgoog4_request&amp;amp;X-Goog-Date=20210228T210416Z&amp;amp;X-Goog-Expires=9000&amp;amp;X-Goog-SignedHeaders=host&amp;amp;X-Goog-Signature=4ce2e4664470fb81f450e91fe63bdcd29e1077eed756a94eb3923b5740acbbc4618a91b148a5cd4b3540db615a95f0842893cc013aa965a8099d671724de058852816ec795bd17d483a51b944b8cc461a7b3bf0e3f51b5ed702dde0a5bbada3bb68fcc1de3d6fd1bcb8262f3199b28218d2de0dd9a4b2eaee5583b0ccbd52022e5a99a49f71972ed1c0ba28a9ae2d93f0e1b88f2b1308f8ff6375ad3ae31c80c42a9968d7ee572cfab03c0e153ac3ee67a4cdf9f8f8b4dca3fa42ae4240e01e259aa4808973607a71df681bee691e64d663436600b0b95852d26aa857dfc6d74e571207c93d201f31d0e1505dbc374d36076bf5caccd6a38281771af50017892"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  2. Poll the API
&lt;/h2&gt;

&lt;p&gt;Without the webhook, there is no way to tell at what exact time a render is complete. Hence, another approach will be to poll the API. You can use the VEED package for this. Simply replace &lt;code&gt;veed.render.create(renderOptions)&lt;/code&gt; with &lt;code&gt;veed.render.get({id:'YOUR_RENDER_ID_GOES_HERE'})&lt;/code&gt;. Run the script again. You should see the response printed to the console. If the render is completed and the download URL is ready, you will get a response like the one below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  id: '540ba741-bead-42cd-bcbe-dcd2d0663d8d',
  workspace_id: '78c897c9-810d-4a33-97e2-15c796a05161',
  data: { elements: [ [Object], [Object] ] },
  latest_event: {
    type: 'RENDER/SUCCESS',
    payload: {
      render_id: '540ba741-bead-42cd-bcbe-dcd2d0663d8d',
      progress: 100,
      url: 'https://storage.googleapis.com/veed-prod-video-bucket/veedapi%2Frenders%2F540ba741-bead-42cd-bcbe-dcd2d0663d8d%2Foutput%2FzBG_du_k~qL5dLS9YT6Oa.mp4?X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;amp;X-Goog-Credential=prod-api%40veed-prod-server.iam.gserviceaccount.com%2F20210301%2Fauto%2Fstorage%2Fgoog4_request&amp;amp;X-Goog-Date=20210301T084032Z&amp;amp;X-Goog-Expires=9001&amp;amp;X-Goog-SignedHeaders=host&amp;amp;X-Goog-Signature=7b9dd8d71a055867a1cc0947f24050ec145b863be3c787963f820ff218d9a55201c45b509cbdb48c8460a71c2f3c433c4809c55ffa610c5964d07e7fdcee3f19f3bb2cde93b104b7b66930fde8ccbc278c0a33afac5ad671d6265ab2e6e9ae0a96ddf6103ba7028f3508dfd1fb35aef37dc6a0cf28d245fcfc8d4ef825a3656aec6f0cee6f25c69422351e84d56226129b9168ce364d394bbffd8682b37efdd438b90b259aa964e41b714660343885020b3a4664db37c35019b82f397d270085881098a1ece6a7e2bc4c055d4db6b3ea3137fbd2c7576eb140b8ef1cb2d6479d36094450b2ee82335a84514b5ec14c28ef770eb0c4188e8fde6321ff68ee28a9'
    }
  },
  created_at: 1614588003775,
  modified_at: 1614588032628
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can now copy the &lt;code&gt;url&lt;/code&gt; and paste it into your browser. Hit &lt;code&gt;enter&lt;/code&gt; and the download should start automatically.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;We have successfully learnt how to trim videos in Node using the VEED API. While this is merely a demo showcasing what’s possible, feel free to take things further by building out your own application or API that utilizes this API in a more clever way and share in the comment section below. &lt;/p&gt;

&lt;p&gt;I’d love to see the magic you create. See you in the next one!&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.veed.io/" rel="noopener noreferrer"&gt;Our website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.veed.io/api" rel="noopener noreferrer"&gt;More about our API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://documentation.veed.io/reference#getting-started" rel="noopener noreferrer"&gt;Our API Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>videoapi</category>
      <category>videotrimmingapi</category>
      <category>videoeditingapi</category>
      <category>veed</category>
    </item>
    <item>
      <title>Get started editing videos with the VEED API.</title>
      <dc:creator>Philip Obosi</dc:creator>
      <pubDate>Sat, 20 Mar 2021 21:43:46 +0000</pubDate>
      <link>https://dev.to/worldclassdev/get-started-editing-videos-with-the-veed-api-4ked</link>
      <guid>https://dev.to/worldclassdev/get-started-editing-videos-with-the-veed-api-4ked</guid>
      <description>&lt;p&gt;VEED is a simple yet powerful online video editor. Through the VEED API, you are able to build automation workflows and robust video editing applications without sweating the &lt;strong&gt;"hard"&lt;/strong&gt; stuff.&lt;/p&gt;

&lt;p&gt;This means that you'll be able to integrate features like transcoding, transcribing and subtitling, trimming, cropping as well as add elements like text, progress bars, audio waves, and media elements( audio, video and images) to videos programmatically&lt;/p&gt;

&lt;p&gt;If this is something that interests you, you may follow the steps below to set up your account so you can start making awesome video edits with the VEED API.&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Signup for your Veed account
&lt;/h1&gt;

&lt;p&gt;To use our API, first you need to &lt;a href="https://www.veed.io/signup" rel="noopener noreferrer"&gt;signup for your free Veed account&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you finish signup, you should see your &lt;strong&gt;Workspace Dashboard&lt;/strong&gt;. This is your home for managing your video editing activity on Veed.&lt;/p&gt;

&lt;p&gt;On the Free plan, you are able to edit videos of maximum duration 10 minutes. You will not be charged for this unless you choose to &lt;a href="https://www.veed.io/pricing" rel="noopener noreferrer"&gt;upgrade&lt;/a&gt; for more editing power.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F81ebda5-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F81ebda5-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Get your API Access Key
&lt;/h1&gt;

&lt;p&gt;On your &lt;strong&gt;Workspace Dashboard&lt;/strong&gt;, click on the &lt;strong&gt;Settings&lt;/strong&gt; tab on the side menu. This will open up a section as shown below. At the bottom of the page, you will find a button that reads *&lt;em&gt;Enable API&lt;/em&gt;. Click on that button to enable the API section of your dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fe7986c3-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fe7986c3-2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once, you have done that, you will be taken to the section shown below. Here, you can copy your API keys which will be required for all interactions with the API. You will also notice that an &lt;strong&gt;API tab&lt;/strong&gt; has now been added to your side menu for easy access subsequently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
Make sure to use the test key as shown below while in development.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;key_test_XXXXXXXXXXXXXX
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Remember to switch to your live keys when taking you application live.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;key_live_XXXXXXXXXXXXXX
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fdbe7290-3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fdbe7290-3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Adding your Webhook URL(Optional).
&lt;/h1&gt;

&lt;p&gt;If you would like to make use of Webhooks(recommended) instead of poll the API in order to keep track of the status of renders, make sure to add your webhook URL in the field provided(See image below).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fc89dd5c-4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fc89dd5c-4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may learn more about working with webhooks &lt;a href="https://documentation.veed.io/reference/working-with-webhooks" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Authenticating API Requests
&lt;/h1&gt;

&lt;p&gt;For authenticating requests, the VEED API uses API Keys. These keys can be retrieved and managed via your &lt;a href="https://www.veed.io/workspaces/" rel="noopener noreferrer"&gt;&lt;strong&gt;Workspace dashboard&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;During development, make sure to use the test secret key which have the prefix &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;key_test_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For your production environment, make use of the production secret key with the prefix &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;key_live_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;.&lt;br&gt;
At the moment, your API keys carry administrative privileges and can carry out any action enabled on the API, so be sure to keep them secure. Do not share your keys in publicly accessible places like Github, on client-side code, documentations, tutorials and so forth.&lt;/p&gt;

&lt;p&gt;To make use of the API keys, attach them to the &lt;code&gt;Authorization&lt;/code&gt; request header for your request(See example below).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --request GET \
  --url https://api.veed.io/api/assets \
  --header 'Authorization: veed_test_xxxxxxxxxxxxxxxxxxxxxxxx'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;🚧 Note:&lt;/strong&gt;&lt;br&gt;
You should make all API calls over HTTPS and always authenticate every request&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Now that we are now familiar with the VEED API, our next set of articles will dive into specific applications and use cases for which you should be able to utilize the API in your applications. Until then feel free to learn more about VEED via the resources below.&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.veed.io/" rel="noopener noreferrer"&gt;Our website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.veed.io/api" rel="noopener noreferrer"&gt;More about our API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://documentation.veed.io/reference#getting-started" rel="noopener noreferrer"&gt;Our API Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>videoediting</category>
      <category>videoeditingapi</category>
      <category>veed</category>
      <category>videoautomation</category>
    </item>
    <item>
      <title>UI Snippets: Say NO to Ugly Check-boxes! </title>
      <dc:creator>Philip Obosi</dc:creator>
      <pubDate>Thu, 09 Aug 2018 23:56:21 +0000</pubDate>
      <link>https://dev.to/worldclassdev/ui-snippets-say-no-to-ugly-check-boxes--5881</link>
      <guid>https://dev.to/worldclassdev/ui-snippets-say-no-to-ugly-check-boxes--5881</guid>
      <description>&lt;p&gt;Okay!!! I'm not exactly a front-end guru but it really just doesn't sit right with me when i visit certain websites and find poorly designed check-boxes being used on them. Trust me it hurts even more when the checkbox still holds its default look. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclaimer&lt;/em&gt;: Please note that this project is just a showcase of how we can improve the aethetics of checkboxes. It doesn't claim to abide by the best practices and principles of acessibility. Just a CSS Stunt!&lt;/p&gt;

&lt;p&gt;So i did a little Codepen to start the war against ugly check-boxes. Take a look and let me know what you think about it in the comment section. &lt;/p&gt;

&lt;p&gt;Do well to share your own beautifully designed checkboxes too. We all could learn a thing or two.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6igz788bcvvbvtukyioy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6igz788bcvvbvtukyioy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Codepen URL:&lt;/em&gt; &lt;a href="https://codepen.io/worldclassdev/full/xJmrax/" rel="noopener noreferrer"&gt;https://codepen.io/worldclassdev/full/xJmrax/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect with me on twitter will you? &lt;a href="http://twitter.com/worldclassdev" rel="noopener noreferrer"&gt;@worldclassdev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Gracias!&lt;/p&gt;

</description>
      <category>css</category>
      <category>checkboxes</category>
      <category>frontend</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Javascript Algorithms #2: Palindromes</title>
      <dc:creator>Philip Obosi</dc:creator>
      <pubDate>Wed, 01 Aug 2018 15:29:31 +0000</pubDate>
      <link>https://dev.to/worldclassdev/javascript-algorithms-2-palindromes-48g3</link>
      <guid>https://dev.to/worldclassdev/javascript-algorithms-2-palindromes-48g3</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XEasNYZM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7qe4349ug4cqz8ndfdcu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XEasNYZM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7qe4349ug4cqz8ndfdcu.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Palindromes! Palindromes!! Palindromes!!! Ooooh boy. I'm pretty sure that by now you are wondering what these are. You know personally as a software developer when someone utters words like this while communicating with me i gesture awkwardly and give a pretty obnoxious smirk to indicate some level of disinterest. I'm really not a fan of confusing people.&lt;/p&gt;

&lt;p&gt;Seat belts on? Let's do justice to the big word. Shall we?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yP4ivGRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/a3aakwl0pcjijhs28rnq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yP4ivGRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/a3aakwl0pcjijhs28rnq.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A palindrome is a word, number, or other sequence of characters which reads the same backward as forward, such as "madam" or "racecar". Using a bit of programmer's speak we could say it's a string of text that doesn't change when re-arranged in reverse(the opposite direction).&lt;br&gt;
So much for the big word huh?&lt;/p&gt;
&lt;h1&gt;
  
  
  The Challenge
&lt;/h1&gt;

&lt;p&gt;Given a string of text, return true or false indicating whether or not the text is a palindrome. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PS:&lt;/strong&gt; I remember taking this challenge once during Andela's test.&lt;/p&gt;
&lt;h1&gt;
  
  
  Algorithmic Logic
&lt;/h1&gt;

&lt;p&gt;The challenge says "given a string of text" which implies that our function would have a string-typed parameter which we may call "text". Next, we are to evaluate if the string is a palindrome. To do this, we'll have to reverse the string first and then compare it with the string that was passed in as an argument. &lt;br&gt;
To avoid issues with letter casing, it seems reasonable to convert text to a single case type, be it upper or lower. Finally, we are to "return true or false" depending on the result of our evaluation. True for when it is a palindrome and false for otherwise.&lt;br&gt;
All said! You shall now proceed to the Code Dojo.&lt;/p&gt;
&lt;h1&gt;
  
  
  Code Implementation
&lt;/h1&gt;

&lt;p&gt;There's quite a handful of approaches to implementing a palindrome checker and this mostly due to the fact that there are several ways to reverse a string and several ways to loop through a string. Hence, there's a couple of stunts and combos one could pull off. However we'd consider two unique ways to implement this below:&lt;/p&gt;
&lt;h2&gt;
  
  
  The Intuitive Approach
&lt;/h2&gt;

&lt;p&gt;Okay, i must confess the title sounds a bit misguiding. This isn't exactly the first thing everyone would do if they are presented with this challenge. It's really just a direct approach to solving the problem. How direct? You'd see.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
The Intuitive Approach: This is mostly a direct
approach that most would follow. We split the
string into characters, reverse the array of characters,
join the characters back to form a string, and then
test the created string against what was originally received.
*/&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;palindrome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// Split, reverse and join string to get reversed text&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;reversedText&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&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;return&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;reversedText&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;I'm sure there's someone thinking "this really isn't direct at all". Oh well! Let's unveil the "mysteries", shall we?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First our function accepts a parameter which is the string of text which is to be tested.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, we convert all letters of the string to lowercase, then call the .split() method on the string that is received and pass it an empty string in order to spread the characters into and array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, we call .reverse() on the array to re-order its elements in reverse.&lt;br&gt;
After that we call .join() on the reversed array to form a string once again.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Voila! we have a reversed string. Notice how we chained all these methods in succession making our code concise yet functional. This is one of the reasons i love Javascript. Elegant syntax!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At the end we return the result of our comparison which is a boolean indicating if the string that was passed in equals the reversed string we created. This tells us if the text that was passed in is a palindrome.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Capiche!!! That was easy wasn't it?&lt;br&gt;
Let's try something slightly more complex.&lt;/p&gt;
&lt;h2&gt;
  
  
  Looping through and Comparing Characters
&lt;/h2&gt;

&lt;p&gt;Hmmmmmm! I did call this a slightly complex implementation. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer: This could be a bit more confusing than you expected. But i'll break it down to the best of my ability. So, fear not!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Following this approach we try to loop through the string as it was passed in and compare each character with the character currently in the position it'd have taken if the string was reversed. &lt;/p&gt;

&lt;p&gt;For example if we were testing the string "developer", we would compare "d" with "r" because if the string was reversed "d" would take "r"s position. Weird punctuation, I know! &lt;em&gt;smiles&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Correspondingly we'd compare "e" in position 2 with "e" in position 2 from the end as well. If the string were a palindrome, all of these would test true.&lt;br&gt;
Alright now! Let the code speak for itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
Looping and Comparing using .every(): This approach allows us to
split the sting into an array of characters and then loop through
the characters comparing them with the characters in their
corresponding positions from the right.
*/&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;palindrome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// Split text into array of characters&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;charArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&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;// Loop through every character and compare with the&lt;/span&gt;
&lt;span class="c1"&gt;// character in its corresponding position if the string&lt;/span&gt;
&lt;span class="c1"&gt;// was reversed. Then store the result&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;charArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;every&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;letter&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;letter&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;charArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;charArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&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;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;span class="c1"&gt;// Return the result of the evaluation&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&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;Dramatic sound effect here&lt;/strong&gt;…lol… I'm really just too playful.&lt;/p&gt;

&lt;p&gt;Well, i'm sure you must've noticed that learning to do amazing things with core Javascript is a fun and adventurous process. Alright let's do the review thing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We converted all letters of the string to lowercase, then used .split() once again to spread the characters of the string into an array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next we use a special array method .every() to loop through the array an perform our check. Basically, the .every() method tests whether all elements in the array pass the test implemented by the provided function. The provided function in our case accepts the current letter and its index in the array as parameters. Then we return the result of the comparison between the letter and the letter currently occupying the position this letter would assume if the string was reversed. Learn more about .every() &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cumulatively, the .every() method would evaluate to true if the test passes in all cases and false if it didn't. The result of that evaluation is what we store in the variable "result" and that's what our function returns as an indication that the string failed or passed the palindrome check.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rUisXHQN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/psh88tycfkqoba9hb6ve.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rUisXHQN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/psh88tycfkqoba9hb6ve.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Perhaps you noticed too? There's something intrinsically wrong with our second implementation performance-wise. Maybe try identifying it by yourself before you proceed with the rest of the article?&lt;/p&gt;

&lt;p&gt;Okay, here it is. We loop through the entire string and compare every letter with the corresponding letter in its position in reverse. Maybe take out a pen and paper and try to do this manually, then you'd notice that once you loop beyond the string holding the middle position, you are intrinsically repeating comparisons you've already gone through in the first half of the iteration. That's redundant, don't you think?&lt;/p&gt;

&lt;p&gt;In order to fix this, we'd add a check to ensure that we stop looping once we get to the mid-point of the string. I'd really like you to try your hands on optimizing this. I'll be posting the solution in the comment section and on twitter after seeing what you could come up with.&lt;br&gt;
Have fun while at it!&lt;/p&gt;

&lt;h1&gt;
  
  
  Evaluation &amp;amp; Summary
&lt;/h1&gt;

&lt;p&gt;We've now examined two ways to implement a palindrome checker in Javascript. Both implementations are okay and could help you pass that coding interview.&lt;/p&gt;

&lt;p&gt;However as is our concern in this case, we need to determine which has higher performance characteristics as we take a look at their pros and cons.&lt;/p&gt;

&lt;p&gt;In my next article i will explore more ways to implement this algorithm as we consider other stricter variations of palindromes, then we'd run a performance test to determine the most highly performant.&lt;/p&gt;




&lt;p&gt;Feel free to implement this in other ways and explore the pros and cons of using each method. Also share them with everyone in the comment section (possibly a link to your pen). We look forward to seeing them. Ask questions as well. I'm sure we'd be able find the answers somehow.&lt;/p&gt;

&lt;p&gt;Please share this article with other's too if you found it helpful. You received freely, give freely. I also won't mind a round of applause you know (&lt;strong&gt;&lt;em&gt;winks&lt;/em&gt;&lt;/strong&gt;).&lt;br&gt;
Clap so others get to enjoy this too!&lt;/p&gt;

&lt;p&gt;Connect with me on twitter will you? &lt;a class="mentioned-user" href="https://dev.to/worldclassdev"&gt;@worldclassdev&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;SUBSCRIBE &lt;a href="https://medium.com/dev-process"&gt;HERE&lt;/a&gt; FOR UPDATES &amp;amp; STAY TUNED FOR THE NEXT ARTICLE ON THE SERIES.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>showdev</category>
      <category>explainlikeimfive</category>
      <category>performance</category>
    </item>
    <item>
      <title>Javascript Algorithms #1: Counting the Vowels in a String Of Text</title>
      <dc:creator>Philip Obosi</dc:creator>
      <pubDate>Thu, 26 Jul 2018 04:58:53 +0000</pubDate>
      <link>https://dev.to/worldclassdev/javascript-algorithms-1-counting-the-vowels-in-a-string-oftext-5ejl</link>
      <guid>https://dev.to/worldclassdev/javascript-algorithms-1-counting-the-vowels-in-a-string-oftext-5ejl</guid>
      <description>

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhbob503neidlrlyrq93m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhbob503neidlrlyrq93m.png" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
Over the years, Javascript has continued to gain lots of attention as its increasingly vast capabilities continue to expand. It has grown from being just a client-side scripting language for making cool interactive web interfaces to being used extensively on the server-side, for mobile applications, desktop applications, embedded systems, IOT, and so on.&lt;/p&gt;

&lt;p&gt;However, it's become clear that despite the wide range of frameworks available to enhance the strengths of a Javascript developer, it eventually all boils down to understanding the basics. The ability to manipulate vanilla Javascript to do things in the most efficient way is what makes the difference. There's really so many Javascript developers out there these days and it makes me wonder how many of us really know our stuff.&lt;/p&gt;

&lt;p&gt;In this series, we will be implementing various algorithms using Vanilla Javascript. We will explore various solutions and examine the pros and cons of each approach. We'd also be posting links to a CodePen show-casing these implementations. It'll benefit you most when you try to re-create these solutions on your own as well as make an attempt to improve them.&lt;/p&gt;

&lt;p&gt;We'd recommend that you try to do it yourself first and only refer to the code to get pointed in the right direction, confirm your solutions, and study other approaches. The algorithms will range from writing basic to advance algorithms hence, some of these challenges would be indeed very challenging. Do not be discouraged. That's the point of it all and that's how you get to grow as a developer.&lt;br&gt;
So sit tight and enjoy the ride. Let's all grow together!&lt;/p&gt;
&lt;h1&gt;
  
  
  The Challenge
&lt;/h1&gt;

&lt;p&gt;Basically, we want to be able to receive a string of text of any length and return the number of vowels found within the text.&lt;/p&gt;
&lt;h1&gt;
  
  
  Algorithmic Thinking
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FSBgHo3lCTfubIHmEo7Or_0_w9ZqNj9KDG3zkYus.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FSBgHo3lCTfubIHmEo7Or_0_w9ZqNj9KDG3zkYus.jpeg" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Men! This isn't as easy as i thought" by Tim Gouw on UnsplashReading through the challenge statement above, you'd notice the statement** "receive a string of text"**. If you're quite used to programming in general, this should bring the idea of functions to mind. We could write a function that'd have a parameter called "text". Text would be a string of any length which would be passed to the function as an argument when it is called.&lt;/p&gt;

&lt;p&gt;Next, within the function we have to &lt;strong&gt;go through the text and search for occurrences of the English vowels&lt;/strong&gt; (a,e,i,o,u).&lt;/p&gt;

&lt;p&gt;The function then &lt;strong&gt;returns the total number of matches(vowels) found&lt;/strong&gt;. This should bring "return statements" to mind as they basically stop the execution of a function and return a value from that function.&lt;/p&gt;
&lt;h1&gt;
  
  
  Code Implementation
&lt;/h1&gt;

&lt;p&gt;Oooooohhh yeah!!! We got the boring stuff out of the way. These algorithms won't write themselves, would they?&lt;br&gt;
We'd explore two ways to implement this. First we'd follow an Iterative approach and then the use of Regular Expressions.&lt;/p&gt;
&lt;h2&gt;
  
  
  An Iterative Approach
&lt;/h2&gt;

&lt;p&gt;In the iterative approach, we would have to loop through each letter of the string passed and then check to see if they match any of the vowels. Before running through the text we would have a counter initialized and assigned a value of zero. In a case where there's a match, we would increment the counter. Pretty simple right?&lt;/p&gt;

&lt;p&gt;Well here's our implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
An iterative approach to counting the number of vowels in a
string of text.
*/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;vowels&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;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="s2"&gt;e&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;i&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;o&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;u&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="nf"&gt;countVowelsIterative&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// Initialize counter&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;counter&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="c1"&gt;// Loop through text to test if each character is a vowel&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;letter&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&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;vowels&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nx"&gt;counter&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="c1"&gt;// Log formatted response to console&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`The text contains &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; vowel(s)`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="c1"&gt;// Return number of vowels&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/* 
    ============== Test Case ===================
*/&lt;/span&gt;
&lt;span class="nf"&gt;countVowelsIterative&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am a world-class developer using iterations&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Logs "The text contains 16 vowel(s)" to the console&lt;/span&gt;
&lt;span class="c1"&gt;// returns 16&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Well, that was pretty self explanatory right? Let's go over some key points.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, we declared a constant "vowels" which contained an array of the five English vowels.&lt;/li&gt;
&lt;li&gt;Next, we make use of a for…of loop to iterate through each letter of the text. If you're not conversant with this, a for…of loop basically creates a loop iterating over &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol" rel="noopener noreferrer"&gt;iterable objects&lt;/a&gt;. Iterable objects could be strings, arrays, maps, sets etc. You can learn more &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Notice how we convert all letters of the text to lowercase within the loop. This is because, we don't want to miss the cases of uppercase vowels within the passed text (trust me that wasn't intentional).&lt;/li&gt;
&lt;li&gt;Next within the loop, we use an if statement to check if the selected letter is included in the array of vowels we defined earlier. Fittingly, we call the includes() method on the array of vowels to determine whether the array includes the selected letter, returning true or false as appropriate. Learn more about how includes() works&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes" rel="noopener noreferrer"&gt; here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;If the condition evaluates to true, we increment the counter.&lt;/li&gt;
&lt;li&gt;After looping through we log a formatted message to the console telling us the number of vowels and then return the counter which is equivalent to the number of vowels found.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wheeewww!!! That felt good. Now let's consider a slightly more advanced yet concise approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Regular Expressions
&lt;/h2&gt;

&lt;p&gt;Regular Expressions are quite a bit of a trouble for most developers in my experience. Usually, we don't get to understand the syntax and its application. Hence, we mostly get some snippets online when we need to make use of them. Okay then! Let's try to change that!&lt;/p&gt;

&lt;p&gt;Basically regular expressions help us find patterns or characters/ character combinations within strings. See why this is relevant to us? They'll help us find the desired characters within the text passed. By extension, regular expressions can help us to do way more remarkable things such us the implementation of content filters. However, my favorite thing about Regular Expressions is the fact that the basics stay same across all languages.&lt;/p&gt;

&lt;p&gt;Without further ado, let's examine the solution. If you'd love to learn more about Regular Expressions in Javascript, go through the Mozilla Developer Network's documentation&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions" rel="noopener noreferrer"&gt; here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here's our implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
    Using Regular Expressions to count the number of vowels in a 
    string of text.

*/&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;countVowelsRegex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Search text with Regex and store all matching instances &lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;matchingInstances&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;aeiou&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/gi&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Check if matching instances exist then calculate length&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;matchingInstances&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Log formatted response to console &lt;/span&gt;
         &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`The text contains &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;matchingInstances&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="s2"&gt; vowel(s)`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

         &lt;span class="c1"&gt;// Return number of vowels&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;matchingInstances&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="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/* 
    ============== Test Case ===================
*/&lt;/span&gt;
&lt;span class="nf"&gt;countVowelsRegex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am a world-class developer uisng Regex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Logs "The text contains 13 vowel(s)" to the console&lt;/span&gt;
    &lt;span class="c1"&gt;// returns 13&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I guess you won't need a review of this one, would you? Okay! Okay! Let's look at the solution.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first thing we did within the function was to call thematch() method on the text which returns an array of the matches found after matching the regular expression passed as an argument against the text. Learn more about how match() works &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The regular expression specifies the letters to be looked for within the brackets[]. For simple patterns, Regular expressions are usually defined within a pair of slashes. Notice the characters "gi" trailing the closing slash?&lt;/li&gt;
&lt;li&gt;"g" stands for a global search which does not return after the first match, restarting the subsequent searches from the end of the previous match.&lt;/li&gt;
&lt;li&gt;"i" stands for case insensitive search which makes the whole expression case-insensitive (for example /xyz/i would match XyZ).&lt;/li&gt;
&lt;li&gt;Next we use a conditional to check if any matching instances were found. The .match() method used above returns an array of the matched items if matches were found and "null" if they weren't. Hence in the conditional, if "matchingInstances"evaluates to a truthy value(that is an array of matches found), we log a formatted message showing the number of vowels which is same as the length of the array. Then we return the number as well. On the other hand if it evaluates to a falsy value, we return 0 as it means no matches were found.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Evaluation &amp;amp; Summary
&lt;/h1&gt;

&lt;p&gt;We have now successfully implemented an algorithm that counts the number of vowels in a string of text in Javascript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FDd99tsKRaKtALNXDvjQn_0_OikT1OG_q9MPkOQ3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FDd99tsKRaKtALNXDvjQn_0_OikT1OG_q9MPkOQ3.jpeg" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's evaluate both methods used. The iterative approach although not as concise as the other is an easier and somewhat more logical approach especially for beginners. However as the result below shows, the Regex method is better optimized.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FIpJeMXs1TIaK9KGUZOqH_1_RWbGd1aYfPpjTlM6SdRckQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FIpJeMXs1TIaK9KGUZOqH_1_RWbGd1aYfPpjTlM6SdRckQ.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;a href="https://jsperf.com/vowel-counter" rel="noopener noreferrer"&gt;here&lt;/a&gt; to run these tests by yourself.&lt;/p&gt;

&lt;p&gt;Perhaps we could say the Regex method wins? Nevertheless, both approaches work and could be used in an interview situation.&lt;/p&gt;




&lt;p&gt;Was this exciting for you? Let me know in the comment section below. It really was for me. We were able to successfully examine two approaches to implementing an algorithm that helps us count the number of vowels within a given piece of text. In the process, we've learnt about some Javascript methods and regular expressions. These tools are very important items in a Modern Javascript Developer's toolbox.&lt;/p&gt;

&lt;p&gt;Feel free to implement this in other ways and explore the pros and cons of using each method. Also share them with everyone in the comment section (possibly a link to your pen). We look forward to seeing them. Ask questions as well. I'm sure we'd find the answers somehow.&lt;/p&gt;

&lt;p&gt;Please share this article with other's too if you found it helpful. You received freely, give freely. I also won't mind a round of applause you know (&lt;strong&gt;&lt;em&gt;winks&lt;/em&gt;&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Connect with me on twitter will you? &lt;a href="http://twitter.com/worldclassdev" rel="noopener noreferrer"&gt;@worldclassdev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://medium.com/dev-process" rel="noopener noreferrer"&gt;SUBSCRIBE FOR UPDATES HERE&lt;/a&gt; &amp;amp; STAY TUNED FOR THE NEXT ARTICLE ON THE SERIES.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>performance</category>
    </item>
    <item>
      <title>Leveraging the Power of the Javascript Console in Development</title>
      <dc:creator>Philip Obosi</dc:creator>
      <pubDate>Tue, 06 Feb 2018 06:36:52 +0000</pubDate>
      <link>https://dev.to/worldclassdev/leveraging-the-power-of-the-javascript-console-in-development-24ap</link>
      <guid>https://dev.to/worldclassdev/leveraging-the-power-of-the-javascript-console-in-development-24ap</guid>
      <description>&lt;p&gt;As a software developer, you are most likely overwhelmed by the endless list of development tools out there. Even I struggled for a while trying to choose which ones best suited my development workflow. In most cases i ended up cluttering my developmment environment with tools i either never got to use or tools that remained mostly under-utilized as all they did was sit there.&lt;/p&gt;

&lt;p&gt;After years of inefficient development and constantly re-inventing the wheel, i discovered a very powerful tool that i had ignored. One that every software developer and internet user alike had by default &lt;strong&gt;"The Javascript Console".&lt;/strong&gt; "Thats &lt;strong&gt;console.log&lt;/strong&gt; right? I'm quite familiar with the console." But are you?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In this article, we will carefully explore the extensive array of applications in which the console could be of help to a software developer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is the Console?
&lt;/h2&gt;

&lt;p&gt;The javascript console is an in-built feature in modern browers that comes with out-of-the-box development tools in a shell-like interface that allows a developer to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  View a log of errors and warnings that occur on a web page.&lt;/li&gt;
&lt;li&gt;  Interact with the web page using javascript commands.&lt;/li&gt;
&lt;li&gt;  Debug applications and traverse the DOM directly in the browser.&lt;/li&gt;
&lt;li&gt;  Inspect and analyze network activity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically, it empowers you to write, manage and monitor Javascript right within your browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  Launching the Console in your Browser
&lt;/h3&gt;

&lt;p&gt;The javascript console comes in-built and can be accessed with ease via the following keyboard shortcuts in the following browsers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  For Mozilla Firefox&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;For MAC users:&lt;/strong&gt; &lt;em&gt;COMMAND + OPTION + K&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Windows and Linux users:&lt;/strong&gt; &lt;em&gt;CTRL + SHIFT + K&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;  For Google Chrome&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;For MAC users:&lt;/strong&gt; &lt;em&gt;COMMAND + OPTION + J&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Windows and Linux users:&lt;/strong&gt; &lt;em&gt;CTRL + SHIFT + J&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;  For Google Chrome&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;For Windows users:&lt;/strong&gt; &lt;em&gt;F12&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;  For Safari&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;For MAC users:&lt;/strong&gt; &lt;em&gt;COMMAND + OPTION + C&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;  For Opera mini&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;For MAC users:&lt;/strong&gt; &lt;em&gt;COMMAND + OPTION + I&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Windows and Linux users:&lt;/strong&gt; &lt;em&gt;CTRL + SHIFT + I&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;You should have an interface like this one, most likely docked to the bottom&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FAX9TO2AQUOQq7t4mlGdq_console.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FAX9TO2AQUOQq7t4mlGdq_console.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Exploring the Console API
&lt;/h2&gt;

&lt;p&gt;During development, it is very important for developers to master the art of &lt;strong&gt;consoling&lt;/strong&gt; themselves through the debugging process. Let's explore some of the perks of working with the Console API. There’s a lot of untapped potential in there☺&lt;/p&gt;

&lt;h3&gt;
  
  
  Console.log
&lt;/h3&gt;

&lt;p&gt;This is probably the most used method of them all. It displays a message in the console. When you pass one or more objects to this method. Each object is evaluated and concatenated into a space-delimited string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The current time is:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&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;This would print out the corresponding message to the console as shown below:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FLsLFpdZTG2tampKsSEFe_consoledotlog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FLsLFpdZTG2tampKsSEFe_consoledotlog.png"&gt;&lt;/a&gt; &lt;br&gt;
This similar to &lt;strong&gt;console.debug()&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Console.group
&lt;/h3&gt;

&lt;p&gt;This method helps you group the logs made to the console. All console output that occurs after console.group() and before console.groupEnd() is visually grouped together. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&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="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Country Profile&lt;/span&gt;&lt;span class="dl"&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="nf"&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;name: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&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="nf"&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;continent: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;continent&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="nf"&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;type: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&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="nf"&gt;groupEnd&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;name&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;Nigeria&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;continent&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;Africa&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;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="s2"&gt;Democratic&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;In a situation where you have many log groups, make a call to console.groupCollapsed instead of console.group. This will display the groups in a collapsed default mode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The output should look like this&lt;/strong&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FSJwmdadwRJevQzXizryd_consoledotgroup.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FSJwmdadwRJevQzXizryd_consoledotgroup.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Console.trace
&lt;/h3&gt;

&lt;p&gt;This method simply prints a stack trace from the point where it was called. This helps you track the execution of your code. As this is beyond the scope of this article, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/console#Stack_traces" rel="noopener noreferrer"&gt;you can learn more about stack traces and how they work via this link&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Console.table
&lt;/h3&gt;

&lt;p&gt;Basically, this helps you display tabular data (usually an array) as a table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;food&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Rice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;carbohydrate&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;class&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;protein&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Beans&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;food&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;The output:&lt;/strong&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FCZBgP7uaRMiKDRstst9Q_consoledottable.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FCZBgP7uaRMiKDRstst9Q_consoledottable.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Console.error
&lt;/h3&gt;

&lt;p&gt;This method outputs an error message. Unlike the message from &lt;strong&gt;console.log()&lt;/strong&gt;,it styles the message like an error, and includes a stack trace from where the method was called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error: can't identify file type&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;This is similar to &lt;strong&gt;console.exception()&lt;/strong&gt; and &lt;strong&gt;console.warn()&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Console.count
&lt;/h3&gt;

&lt;p&gt;This counts and outputs the number of times that count() has been invoked on the same line and with the same label. It is able to recognize the label anywhere within the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;city&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="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;registered&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;The output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FUyPB0ArLRKagyZeY7CGn_consoledotcount.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FUyPB0ArLRKagyZeY7CGn_consoledotcount.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Console.time and Console.timeEnd
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Console.time&lt;/strong&gt; starts a timer with a name specified as an input parameter and can run up to 10,000 simultaneous timers on a given page. Once initiated, we use a call to console.timeEnd() to stop the timer and print the elapsed time to the Console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;total&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;init arr&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;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10000&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="nf"&gt;timeEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;init arr&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;var&lt;/span&gt; &lt;span class="nx"&gt;i&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;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&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;i&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="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Object&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="nf"&gt;timeEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;total&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// init arr: 0.0546875ms&lt;/span&gt;
    &lt;span class="c1"&gt;// total: 2.5419921875ms&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Console.clear
&lt;/h3&gt;

&lt;p&gt;This clears the console&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nf"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Console.assert
&lt;/h3&gt;

&lt;p&gt;This method logs a message and stack trace to console if the evealuated expression is false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;lesserThan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&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="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;b&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;message&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;a is not lesser than b&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;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;lesserThan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&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;The output:&lt;/strong&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FyxhQeMeTQ8yp7cTJgQL7_consoledotassert.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.scotch.io%2F57596%2FyxhQeMeTQ8yp7cTJgQL7_consoledotassert.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Common operations carried out with the Console
&lt;/h2&gt;

&lt;p&gt;The console comes in handy for a large range of functions in development. These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Diagnosing and logging to console&lt;/li&gt;
&lt;li&gt;Time and monitor executions&lt;/li&gt;
&lt;li&gt;Handle exceptions and errors&lt;/li&gt;
&lt;li&gt;Monitor events&lt;/li&gt;
&lt;li&gt;Evaluate expressions&lt;/li&gt;
&lt;li&gt;Comparison of data objects&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The countless number of operations that can be carried out effectively via the javascript console makes it a good tool to integrate into your development workflow. Its better to master a few tools than have so many under-utilized tools clogging your workspace.&lt;/p&gt;

&lt;h2&gt;
  
  
  Helpful Resources
&lt;/h2&gt;

&lt;p&gt;Continue learning about leveraging this awesome technology via the links below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://developers.google.com/web/tools/chrome-devtools/console/" rel="noopener noreferrer"&gt;Google Developer Docs on Chrome Dev Tools&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Console" rel="noopener noreferrer"&gt;Mozilla Developer Network Web Docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-use-the-javascript-developer-console#working-with-the-console-in-a-browser" rel="noopener noreferrer"&gt;Digital Ocean Community Tutorials&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>console</category>
      <category>debugging</category>
    </item>
  </channel>
</rss>
