-2

So far I've been learning JS (basics) and I've been coding in Sublime. And I used to run the code in the browser. I decided (had to) to switch to VSCode and I am pretty unfamiliar with it. I set up Node and now I am trying to find alternative to prompt().

I used to code like this:

 let x = prompt();

but now I can't use prompt in node. I read some threads about it, but I could not find the answer.

What is the alternative way and how can I use it? For example if I want to store the line I typed in a variable.

I just saw some example in c++. I've been looking for something like cin

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • 1
    Is this what you're looking for? [How to take in text input from a keyboard and store it into a variable in javascript?](https://stackoverflow.com/questions/19718669/nodejs-how-to-take-in-text-input-from-a-keyboard-and-store-it-into-a-variable-i) – Baboo Aug 25 '18 at 13:04
  • not sure what are you asking about... about input in node or vs or what? – Flash Thunder Aug 25 '18 at 13:05
  • Maybe you want something that looks like this? [How can I take console input from a user in node.js?](https://stackoverflow.com/questions/26683734/how-can-i-take-console-input-from-a-user-in-node-js) – Andi Domi Aug 25 '18 at 13:06
  • Possible duplicate of [Reading value from console, interactively](https://stackoverflow.com/questions/8128578/reading-value-from-console-interactively) – KarlR Aug 25 '18 at 13:06
  • I just saw some example in c++. I've been looking for something like "cin". @AndiDomi, i saw the example but now the 'answer' does not live outside 'rl.question'. @'FlashThunde'r Well, about the input in node (i guess). My general idea is not putting the value of the variable in the actual code but after the execution of it. – Nayden Stoykov Aug 25 '18 at 13:43

1 Answers1

1

Welcome to Stackoverflow.

JavaScript running on the browser has access to the Window object and can use the Window.prompt() function.

However, when your code runs on Node, there is no Window. It does not run on the browser. It runs on a command-line. If you want to understand how to pass arguments to a Node command line app, please check this out.

Andre Pena
  • 56,650
  • 48
  • 196
  • 243