<?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: Matthew Caseres</title>
    <description>The latest articles on DEV Community by Matthew Caseres (@matthewcaseres).</description>
    <link>https://dev.to/matthewcaseres</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%2F541987%2F9bc9a983-8b8e-4f93-8b59-3b571f7348ca.png</url>
      <title>DEV Community: Matthew Caseres</title>
      <link>https://dev.to/matthewcaseres</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matthewcaseres"/>
    <language>en</language>
    <item>
      <title>Build a Command-Line Pomodoro Timer in Node.js</title>
      <dc:creator>Matthew Caseres</dc:creator>
      <pubDate>Tue, 16 Feb 2021 02:41:01 +0000</pubDate>
      <link>https://dev.to/matthewcaseres/build-a-command-line-pomodoro-timer-in-node-js-45g4</link>
      <guid>https://dev.to/matthewcaseres/build-a-command-line-pomodoro-timer-in-node-js-45g4</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vBBBdfKl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vpzrogmp5sbcy7shnpgl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vBBBdfKl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vpzrogmp5sbcy7shnpgl.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the source code - &lt;a href="https://github.com/Open-EdTech/node-pomodoro"&gt;https://github.com/Open-EdTech/node-pomodoro&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Motivations
&lt;/h2&gt;

&lt;p&gt;When I started learning about task execution systems like Pomodoro, I thought putting together a CLI myself would be a great way to create a sense of ownership and pride in my work. Also, it would let me ship the features I needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Tracks progress towards completing a given number of hours of work&lt;/li&gt;
&lt;li&gt;Sets goals for continuous work block and break lengths&lt;/li&gt;
&lt;li&gt;Looks nice so productivity streamers can use it&lt;/li&gt;
&lt;li&gt;Emits logs for analysis at a future date&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Design
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Classes vs. Functional
&lt;/h3&gt;

&lt;p&gt;Originally I just made a countdown timer and built off of that. I usually don't write classes, but having a mutable internal state was a really easy way of thinking about the problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Start Small, Build Up
&lt;/h3&gt;

&lt;p&gt;I'm not very experienced with node.js, so I started by displaying a simple countdown to get my feet wet. The general idea is to use setInterval to set a 1000 millisecond delay between each second on the clock. Originally I used &lt;code&gt;process.stdout.write&lt;/code&gt; but once I found a library for displaying progress bars I realized that the progress bars would be a great way of displaying information about your study goals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using npm libraries
&lt;/h3&gt;

&lt;p&gt;I used &lt;a href="https://www.npmjs.com/package/enquirer"&gt;enquirer&lt;/a&gt; to take the user input. &lt;br&gt;
Here's what it looks like -&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1R57IQZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c30xmvw0air7po5wo8wo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1R57IQZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c30xmvw0air7po5wo8wo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The display is simply the multi-progress bar from the &lt;a href="https://www.npmjs.com/package/cli-progress"&gt;CLI-progress&lt;/a&gt; library. This is way better than writing to the console yourself. Here's the block I'm on right now - &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xs0aA49i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wg5yivbljtzqalp4npq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xs0aA49i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wg5yivbljtzqalp4npq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Write to a file
&lt;/h2&gt;

&lt;p&gt;The code writes to a file in the &lt;code&gt;sessions&lt;/code&gt; folder of the project. The filename is the ending time of the session. The contents look like this - &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sp1VuhcR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3dgnjpbhpo624ir69q57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sp1VuhcR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3dgnjpbhpo624ir69q57.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way I can perform an analysis at a later date to track the time I spend contributing to open-source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thanks for reading!
&lt;/h2&gt;

&lt;p&gt;If you give it a try be sure to read the readme. &lt;a href="https://github.com/Open-EdTech/node-pomodoro"&gt;https://github.com/Open-EdTech/node-pomodoro&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
