Ask coding questions

← Back to all posts
problem with prompt in node
blonkm (24)

When I use prompt("...") in a nodejs repl, it works.

When my students use prompt("...") in a nodejs assignment in my course, it doesn't work

The error I get is:
ReferenceError: prompt is not defined

mwilki7 (1136)

I remember this not working for one of my nodejs repls.
I solved it by requiring readline-sync:

var readline = require('readline-sync');

You can get user input like this:

var name = readline.question("What is your name?");

If this doesn't work you might need to install it from the package manager first:

zplusfour (890)

prompt is to take input
and in node.js to make variables you should write let or var before writing the name of the variable