Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

getting user input in node js

//Make sure you have Node and NPM installed
//Run "npm install prompt-sync" in the terminal
const prompt = require('prompt-sync')();

const name = prompt('What is your name?');
console.log(`Hey there ${name}`);
Comment

get input in terminal nodejs

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

readline.question('Who are you?', name => {
  console.log(`Hey there ${name}!`);
  readline.close();
});
Comment

how to take input from user nodejs

const prompt = require("prompt-sync")();

const input = prompt("What is your name? ");

console.log(`Oh, so your name is ${input}`);
Comment

node js get input from console

--------------- easiest method I found---------------------------
  
Run npm install prompt-sync in the terminal
const prompt = require('prompt-sync')();

var name = prompt('what is your name?');

console.log(name);

--------------------------------------------------------------
Comment

node command line input

process.stdin.on('data', (data) => {
	console.log(`You typed ${data}`);
})
Comment

get user input Node js console

// first install prompt-sync:
// npm install prompt-sync

const prompt = require("prompt-sync")({ sigint: true });

const age = prompt("How old are you? ");
console.log(`You are ${age} years old.`);
Comment

input from terminal node js

// npm i readline-sync
import readlineSync from 'readline-sync';

const text = readlineSync.question('enter text:');

const password = readlineSync.question('password:', {
  hideEchoBack: true // The typed text on screen is hidden by `*` (default).
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: ajax add header 
Javascript :: add font awesome to vue 
Javascript :: sleep function javascript 
Javascript :: nextauth dynamic redirect after login 
Javascript :: javascript show div 
Javascript :: remove duplicate value from map react js 
Javascript :: change placeholder javascript 
Javascript :: @editorjs/list window not defined 
Javascript :: #react native shadow 
Javascript :: int to octal javascript 
Javascript :: react/ionic ion-app undefined 
Javascript :: switch browser to fullscreen 
Javascript :: javascript getPersons error 
Javascript :: queryselector with ul and not selecting particular li with id 
Javascript :: jquery check if element has child 
Javascript :: javascript get div x y position 
Javascript :: socket io https 
Javascript :: javascript group by sum array reduce 
Javascript :: codewars playing with digits js 
Javascript :: html to pdf node js background color 
Javascript :: negative reciprocal javascript 
Javascript :: react native memo styles 
Javascript :: React Navigation back() and goBack() not working 
Javascript :: remove backslash in json array javascript 
Javascript :: chrome-doesnt-scale-below-x-500px 
Javascript :: onclick focus out jquery 
Javascript :: js class method called when page loads 
Javascript :: js take last item in array 
Javascript :: js add to local storage 
Javascript :: object to json string android 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =