Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Sahil Kapoor8,932 Points
How 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?
Here 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.");