Node Timer Lab

Objectives

  1. Implement a Node CLI timer app which works from CLI (take time and counts down like a kitchen timer)
  2. Implement taking the CLI arguments: number of seconds or minutes
  3. Implement the asynchronous sleep function so that the app knows when the time is up
  4. Implement the current countdown so that the users can see how much time is left

Introduction

Imagine you've been hired to implement a timer app. The app must run on the super secret NASA server so it must be a command-line program. It must be flexible enough to accept different time intervals. This app will be used by astronauts to cook food on a clandestine black ops mission.

In this project, we'll be using process and timer functions to build a command-line interface application which takes the number of second or minutes and counts them down.

By now you should know how to access CLI arguments and use setTimeout(). Let's get to building the Timer app!

Instructions

  1. Create a CLI app which takes number of seconds in the following format: ns for n seconds, e.g., and 5s for five seconds. The command for 5 seconds must look like node timer 5s.
  2. Implement the timer in timer.js by printing the number of seconds left on a new line. For example, if you passed 10s as your argument, you should see the text "Left: 10s", "Left: 9s", etc. printed to the console.
  3. Use global objects global.setInterval() and global.clearInterval()
  4. Enhance the app by adding minutes in the following format nmin, e.g., 1min for 1 minute. The command for 1 minute must look like node timer 1min.
  5. Utilize process.exit() to exit when there's an error and when there's no error but the time is up.
  6. Use process to access arguments from the command line.
  7. Test Timer with npm test

Extra Info

You might want to consider using setInterval() and clearInterval() from Node Timers API which is identical to browser timer API. Most of front-end developers are already familiar with setInterval() so we won't duplicate and explain it here. But here are the links if you need a refresher:

View node-timer-lab on Learn.co and start learning to code for free.

View Node CLI Timer App on Learn.co and start learning to code for free.

Unlock your future in tech
Learn to code.

Learn about Flatiron School's Mission

With a new take on education that falls somewhere between self-taught prodigy and four-year computer science degree, the Flatiron School promises to turn students with little programming experience into developers.

In the six months since the Manhattan coding school was acquired by WeWork, it has spawned locations in Washington, D.C., Brooklyn, and London. Now, WeWork is opening a fourth Flatiron School location, this time in Houston.

Adam Enbar, Flatiron School's cofounder, believes now is the time to grow. "How the world is changing has impacted working and learning in very similar ways. We think education fundamentally is about one thing: enabling people to pursue a better life."

Learn. Love. Code.
Students come to Flatiron School to change their lives. Join our driven community of career-changers and master the skills you need to become a software engineer or a data scientist.
Find Us