Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
How to read user input directly in Node.js

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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"].

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!