Node js Input
JoshuaKing1 (71)

I have tried many about 15 different things for getting users input. Most of them end with nil before I get to respond (see #3 in my repl). Could somebody help me?

You are viewing a single comment. View All
Answered by mwilki7 (1105) [earned 5 cycles]
View Answer
malvoliothegood (732)

Link to your repl thanks!

malvoliothegood (732)

The problem is the environment that node is running in on If you had node installed on your computer you could create a file called test.js -with the following code in it:

process.argv.forEach(function (val, index, array) {
  console.log(index + ': ' + val);

You could then run it using the command line/terminal like so:

$ node test.js one two=three four

If you ran it from, for example, /Users/mjr/work/node/, then the output would be something like:

0: node
1: /Users/mjr/work/node/test.js
2: one
3: two=three
4: four

Note how the arguments are "picked up" and stored in the process.argv array and that they can be iterated over.

I suggest if you want to use all the features of node then you need to install it on your computer and work with it from there.