Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSahil Kapoor
8,932 PointsHow to get input in the console in node.js
To produce output in the workspaces or command prompt we use "console.log()" so how can we take input using them in node.js?
1 Answer
Andrew Hickman
Full Stack JavaScript Techdegree Student 10,013 PointsHere is a neat little module that I didn't know about: readline-sync. Assuming you don't need something asynchronous, this might be your golden ticket. Works great for me. Found it from this Stack Overflow question: https://stackoverflow.com/questions/19718669/nodejs-how-to-take-in-text-input-from-a-keyboard-and-store-it-into-a-variable-i
# npm install readline-sync
var readline = require('readline-sync');
var name = readline.question("What is your name?");
console.log("Hi " + name + ", nice to meet you.");
Sahil Kapoor
8,932 PointsSahil Kapoor
8,932 PointsThanks for the solution this is really a lot simple than some other methods that were over my head..... Thanks a lot.