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

Nodejs user input

// Importing the module
const readline = require("readline-sync");
  
// Enter the number
let a = Number(readline.question());
let number = [];
for (let i = 0; i < a; ++i) {
  number.push(Number(readline.question()));
}
console.log(number);
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

PREVIOUS NEXT
Code Example
Javascript :: onchange on multiple ids jquery 
Javascript :: getting te value of select multiple value 
Javascript :: JavaScript grouping words by length 
Javascript :: javascript divide string into two parts 
Javascript :: jquery dynamic event binding 
Javascript :: change terminal shortcut vscode 
Javascript :: convert string to object javascript 
Javascript :: jquery: finding all the elements containing the text present in an array 
Javascript :: vuetify open modal based on url anchor or # 
Javascript :: vue js app component 
Javascript :: reactjs framer motion 
Javascript :: convert string to lowercase javascript 
Javascript :: An invalid form control with ... is not focusable. 
Javascript :: vue js hooks 
Javascript :: vue jest run single test 
Javascript :: mongoose connection increase timeout in node js 
Javascript :: return nothing javascript 
Javascript :: modern javascript for loop syntax 
Javascript :: what difference between react func and class components 
Javascript :: office check in 
Javascript :: how to select a class and then change the children of that class with javascript 
Javascript :: gatsby tailwind 
Javascript :: javascript get cell by index 
Javascript :: timing code in javascript 
Javascript :: remove the .cache folder from angular 13 project 
Javascript :: react leaflet disable zoom 
Javascript :: es6 spread 
Javascript :: how to import json data from a local file 
Javascript :: Uncaught TypeError: document.getContext is not a function 
Javascript :: select multiple id in jquery 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =