Git Product home page Git Product logo

node-arguments-lab-dumbo-web-100719's Introduction

Node Arguments Lab

Objectives

  1. Implement a CLI app which generates random passwords
  2. Use two CLI arguments as the input of the app: one for length of the password and another for the number of randomly generated passwords.

Introduction

You've been hired to enhance security at a major US bank amidst the breach in their database. As a security expert you know that offering users randomly generated passwords will make it hard for pesky hackers to brute force the attack. This app must use this command-line interface and be flexible to be used for passwords of different length and for various numbers of passwords.

In this lab, you will pass and access command-line arguments to implement a CLI app which generates random passwords.

Knowing how to pass and access command-line arguments is important in building CLI tools or small programs like the program which gives a random number.

Instructions

  1. Implement a Node script password.js which takes 2 CLI arguments and prints random passwords based on the arguments.
  2. Use two arguments: length (first) and a number of passwords (second) to print, so that node password 2 2 and node password 10 3 are valid commands. The former will print 2 passwords with the length of 2 and the latter 3 passwords with the length of 10.
  3. Optional: implement generatePassword() function in the password.js to get random passwords. The name of the function doesn't matter. You don't even have to have a separate function, you can just implement the code in the file without a function. If it's too hard, look up the implementation online. The password generation is not the focus of this lab, so we won't test your passwords on strength or randomness. Just do your best not to hard code them. ;)
  4. Optional: Output error messages when the type of CLI arguments is wrong or when there's only 1 argument instead of 2.
  5. Finish program with process.exit(0)
  6. Run npm test to test

Extra Info

In the tests, you'll see child_process. It's a super easy core module which allows you to start any other programs/processes from within your Node app. We use it in the tests to verify that your app is actually taking in the CLI argument and not using some hard-coded values. To use child_proccess, all you do is pass parameters to its spawn() method:

process = childProcess.spawn(command, [scriptName, cliArgument1, cliArgument2])

Node's child_process.spawn is similar to how you run multiple processes with Ruby with Process.spawn.

In this lab, we are using child_process.spawn to start your password.js script with arguments 140 and 1. The 140 is the length of the password and the 1 is the number of password we need. The snippet goes like this:

passwordAppProcess = cp.spawn('node', ['password', '140', '1'])
passwordAppProcess.stdout.on('data', (data) => {
  // data is the output of the password.js  script
  passwordAppProcess.kill() 
})

kill() is the command to terminate the child process (your password.js program).

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

View Node Arguments Lab on Learn.co and start learning to code for free.

node-arguments-lab-dumbo-web-100719's People

Contributors

azat-co avatar annjohn avatar victhevenot avatar franknowinski avatar

Watchers

 avatar Mohawk Greene avatar  avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar  avatar  avatar Matt avatar Antoin avatar  avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Kaeland Chatman avatar Lisa Jiang avatar Vicki Aubin avatar Maxwell Benton avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.