-1

From the following code I can read and console.log the line

const readline = require('readline');
const { stdin: input, stdout: output } = require('process');

const rl = readline.createInterface({ input, output });

rl.question('What is your name? ', (answer) => {
  console.log(`Hi ${answer}!`);

  rl.close();
});

But I am trying to read user input like this Input: node app.js John Ouput: Hi John!

How can I achieve this in node?

1

1 Answer 1

0

To achieve that you can use the following:

process.argv

process.argv is an array containing all arguments that were used when invoking you programm. Image you called your programm like that: node index.js "John", process.argv would look like this: ["node", "path/to/index.js", "John"].

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.