Skip to content

sklinkusch/node-walkthrough

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-walkthrough

This command-line application was created by Stefan Klinkusch at Digital Career Institute in Berlin, Germany. It is a recapture of the node-worldtime repository and consumes the World Time API.

Features

It has three main modes:

  • showing a thank you message
  • showing a list of timezones
  • showing the current time for a given timezone

Techniques

  • JavaScript
  • Node.js

Manual

Setup of the package

  1. Clone the repository using git clone git@github.com:sklinkusch/node-walkthrough.git (SSH) or git clone https://github.com/sklinkusch/node-walkthrough (HTTPS).
  2. Move into the directory node-walkthrough and run npm install or yarn.

Making requests

Showing help text

Type: node index.js --help. The output is

Thank you for using this app.

Showing list of timezones

Type node index.js --option. The output is a list of timezones:

{ area: 'Africa', city: 'Abidjan' }
{ area: 'Africa', city: 'Accra' }
{ area: 'Africa', city: 'Algiers' }
{ area: 'Africa', city: 'Bissau' }
{ area: 'Africa', city: 'Cairo' }
...
{ area: 'Pacific', city: 'Tarawa' }
{ area: 'Pacific', city: 'Tongatapu' }
{ area: 'Pacific', city: 'Wake' }
{ area: 'Pacific', city: 'Wallis' }
{ area: 'WET', city: undefined }

Showing current time for a given timezone

Type node index.js $AREA $CITY with $AREA as a continent/area from the list and $CITY as a matching city from the list (area and city should appear as a pair), e.g. node index.js europe berlin. The app is not sensitive to the case. The output should look like

11.07.2019 10:46:39

Task

  1. In a new file called index.js write a CLI application that accepts a user parameter and logs it to the console.

  2. Push your result to a new GitHub repo called node-walkthrough and post the link to #exercises on Slack. We're going to do this after each exercise because fearlessness is built from backups. Here's a workflow that works for me:

    a) At the start of each exercise, checkout a new branch and commit working code at each step as you complete it.

    b) checkout master and merge your feature branch. push once you finish each one to help me keep an eye on progress as you go.

    c) Test that your code definitely works on master, then delete unused branches.

  3. In a new file called messaging.js write a new function called showHelp.

    a) This function should print information to the console if the term --help appears anywhere in the argument list.

    b) Connect this function to index.js using CommonJS Module syntax. Think about your control flow before writing code.

    Remember: Git is your friend.

  4. In a new file called formatting.js write a new function called removeWhitespace. This function should take a string as a parameter and:

    a) Trim whitespace from the beginning and end of the param

    b) Collapse spaces (ensure only one space appears at a time, no doubles)

    Example output:

    • ' sao tome' => 'sao tome'
    • 'kuala lumpur ' => 'kuala lumpur'

Tip: Use console.log to check your output as you go. Remove any test calls to console.log once you're happy with the output.

Remember: Do the Git dance.

  1. Still in formatting.js write a new function called capitalizeInitial. This function should take a string as a parameter, and return it with only the first letter capitalized.

    Example output:

    • 'europe' => 'Europe'
    • 'BERLIN' => 'Berlin'
    • 'aSIa' => 'Asia'

Remember: Have you committed lately?

  1. Still in formatting.js write a new function called prepareString that puts an input string through capitalizeInitial and removeWhitespace then replaces any spaces with underscores.

    Example output:

    • 'kuala lumpur' => 'Kuala_Lumpur'
    • ' puerto rico' => 'Puerto_Rico'
    • ' tokyo' => 'Tokyo'

There are a million other ways we should sanitize user input before using it in a production app, but this will do for now.

Remember: Hmmm end of the exercise. Wasn't there something to remember...?

  1. Start a new file called client.js to handle your API call (similar to what we did yesterday).

Remember: Did you remember on your own this time?

  1. Write a function to format the API response before presenting it to the user, so it's easier to read. (To decide where to write this function, think about how your control flow will go through your files and functions between input and ouput).

Remember: What happens before the next exercise?

  1. Handle common errors with helpful messages for the user

Remember: You know the drill.

  1. Pick another endpoint to be handled by the same app. At which points will your existing control flow need to change to accommodate this? Go through the steps of preparing input, performing the call and formatting output. Keep committing as you complete small steps toward this.

About

recapture of node-worldtime (https://github.com/sklinkusch/node-worldtime)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors