Skip to content
← Back to Community
problem with prompt in node
Profile icon
blonkm

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

Voters
Profile icon
manolov
Profile icon
blonkm
Comments
hotnewtop
Profile icon
teacherniels2

prompt is something REPLit adds to its Node.js runtime environment. It's not part of Node.js itself.

Profile icon
mwilki7

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:
image

Profile icon
zplusfour

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