Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 814 Bytes

lesson2.md

File metadata and controls

40 lines (27 loc) · 814 Bytes

Lesson 2 - Running a JS script in the command line

Exercise 2.1

  1. Create a new file called lesson2.js

  2. Add this content into the file:

    const readline = require('readline');
    
    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });
    
    rl.question('What is your name? ', (answer) => {
      console.log('Your name is ' + answer + '!');
    
      rl.close();
    });
  3. Save the file.

  4. Open up your Terminal (or Command Prompt in Windows).

  5. Change directory to the folder where you kept the file.

  6. Type:

    node lesson2.js
  7. See what happens.

Further Reading


Next: Lesson 3 - Intro to NPM ≫