1

when I use chrome, I can use prompt function like

    let name = prompt('What's your name?');

but when I use atom editor which use node.js as a compiler(i'm not sure this is called 'compiler'), the prompt function doesn't work.

I already tried to install 'prompt for node.js' at NPM but it still doesn't work.

Please help me....

1 Answers1

2

Try this:

var prompt = require('prompt');

  //
  // Start the prompt
  //
  prompt.start();

  //
  // Get two properties from the user: username and email
  //
  prompt.get(['username', 'email'], function (err, result) {
    //
    // Log the results.
    //
    console.log('Command-line input received:');
    console.log('  username: ' + result.username);
    console.log('  email: ' + result.email);
  });

This is the result:

enter image description here

I'm using Visual Studio Code, however, the result's properly the same. For more information, see this: https://www.npmjs.com/package/prompt

You Nguyen
  • 9,961
  • 4
  • 26
  • 52