Sunday, 15 June 2014

javascript - "prompt not defined" using node from command line? -



javascript - "prompt not defined" using node from command line? -

i'm trying run simple javascript programme command line , getting unexpected error. prompt seems simple javascript command; not sure why it's not defined.

my test.js file:

console.log("i inquire name."); var name = prompt("enter name"); console.log("hello ".concat(name, ". how you"));

i'm running this:

c:\directory\node test.js inquire name. c:\directory\test.js:2 var name = prompt("enter name"); reference error: prompt not defined

i think might interested in code :

console.log("i inquire name."); process.stdin.setencoding('utf8'); var name; process.stdin.on('readable', function() { name = process.stdin.read(); if (name !== null) { console.log("hello ".concat(name, ". how you")); process.exit(); } });

this node.js way of doing need do. hope helps!

javascript node.js

No comments:

Post a Comment