How to input data through console in node.js?
up vote
0
down vote
favorite
Although similar questions have already appeared, following theirs instructions I obtain an error. So my code is as follows
var readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
var name;
readline.question(`What's your name?`, (name))
readline.close()
and as a result I have
{ RequestError: Syntax error, permission violation, or other nonspecific error
at StreamEvents.req.once.err
Do you know what is wrong? I'm using npm readline package
node.js readline console.readline
add a comment |
up vote
0
down vote
favorite
Although similar questions have already appeared, following theirs instructions I obtain an error. So my code is as follows
var readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
var name;
readline.question(`What's your name?`, (name))
readline.close()
and as a result I have
{ RequestError: Syntax error, permission violation, or other nonspecific error
at StreamEvents.req.once.err
Do you know what is wrong? I'm using npm readline package
node.js readline console.readline
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Although similar questions have already appeared, following theirs instructions I obtain an error. So my code is as follows
var readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
var name;
readline.question(`What's your name?`, (name))
readline.close()
and as a result I have
{ RequestError: Syntax error, permission violation, or other nonspecific error
at StreamEvents.req.once.err
Do you know what is wrong? I'm using npm readline package
node.js readline console.readline
Although similar questions have already appeared, following theirs instructions I obtain an error. So my code is as follows
var readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
var name;
readline.question(`What's your name?`, (name))
readline.close()
and as a result I have
{ RequestError: Syntax error, permission violation, or other nonspecific error
at StreamEvents.req.once.err
Do you know what is wrong? I'm using npm readline package
node.js readline console.readline
node.js readline console.readline
asked Nov 10 at 19:27
zorro47
1375
1375
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
According to the documentation, the second argument should be a callback function. What you currently have is an uninitialized variable. To fix it, you could do something like this:
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const response = function (name) {
console.log('Hello ' + name);
};
readline.question(`What's your name?`, response(name));
readline.close();
(I'm using const instead of var to adhere to ES6 standards for JavaScript/Node)
add a comment |
up vote
1
down vote
The second argument of question should be a callback function
readline.question('What's your name',(name)=>{
console.log(name)
});
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
According to the documentation, the second argument should be a callback function. What you currently have is an uninitialized variable. To fix it, you could do something like this:
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const response = function (name) {
console.log('Hello ' + name);
};
readline.question(`What's your name?`, response(name));
readline.close();
(I'm using const instead of var to adhere to ES6 standards for JavaScript/Node)
add a comment |
up vote
1
down vote
accepted
According to the documentation, the second argument should be a callback function. What you currently have is an uninitialized variable. To fix it, you could do something like this:
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const response = function (name) {
console.log('Hello ' + name);
};
readline.question(`What's your name?`, response(name));
readline.close();
(I'm using const instead of var to adhere to ES6 standards for JavaScript/Node)
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
According to the documentation, the second argument should be a callback function. What you currently have is an uninitialized variable. To fix it, you could do something like this:
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const response = function (name) {
console.log('Hello ' + name);
};
readline.question(`What's your name?`, response(name));
readline.close();
(I'm using const instead of var to adhere to ES6 standards for JavaScript/Node)
According to the documentation, the second argument should be a callback function. What you currently have is an uninitialized variable. To fix it, you could do something like this:
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const response = function (name) {
console.log('Hello ' + name);
};
readline.question(`What's your name?`, response(name));
readline.close();
(I'm using const instead of var to adhere to ES6 standards for JavaScript/Node)
answered Nov 10 at 19:59
Sahil Makhijani
538
538
add a comment |
add a comment |
up vote
1
down vote
The second argument of question should be a callback function
readline.question('What's your name',(name)=>{
console.log(name)
});
add a comment |
up vote
1
down vote
The second argument of question should be a callback function
readline.question('What's your name',(name)=>{
console.log(name)
});
add a comment |
up vote
1
down vote
up vote
1
down vote
The second argument of question should be a callback function
readline.question('What's your name',(name)=>{
console.log(name)
});
The second argument of question should be a callback function
readline.question('What's your name',(name)=>{
console.log(name)
});
answered Nov 10 at 19:52
gkont
1039
1039
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242640%2fhow-to-input-data-through-console-in-node-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown