I would just like something simple to read text from a keyboard and store it into a variable. So for:
var color = \'blue\'
I would like the
There are three solution for it on NodeJS platform
Like: ( https://nodejs.org/api/readline.html )
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('What do you think of Node.js? ', (answer) => {
// TODO: Log the answer in a database
console.log(`Thank you for your valuable feedback: ${answer}`);
rl.close();
});
For synchronous use case need, use NPM Package: readline-sync Like: ( https://www.npmjs.com/package/readline-sync )
var readlineSync = require('readline-sync');
// Wait for user's response. var userName = readlineSync.question('May I have your name? '); console.log('Hi ' + userName + '!');
For all general use case need, use **NPM Package: global package: process: ** Like: ( https://nodejs.org/api/process.html )
For taking input as argv:
// print process.argv
process.argv.forEach((val, index) =>
{
console.log(`${index}: ${val}`);
});