Sublime Forum

"prompt" throwing error in javascript

#1

I a noob, recently started working with Sublime and it seems incredible. I recently downloaded node.js and chocolatey so i could run .js in Sublime. then i ran the command to add .js to this windows 11 machine

then replaced the shell cmd: make with

{
“cmd”:[“node”, “$file”],
“selector”: “main.js”
}

But when I typed out this start
let name = prompt(“what is your name”);
console.log(name);

get this error
let name = prompt(“what is your name”);

ReferenceError: prompt is not defined?

I can get other simple lines to run like:
let name = “fred”;
console.log(name);

Am i missing a basic library?

0 Likes

#2

Node is not a web browser, it does not have prompt. See https://nodejs.org/en/learn/command-line/accept-input-from-the-command-line-in-nodejs

Note that this website is for support using Sublime Text, not for help programming in JavaScript. There are lots of great online communities dedicated to helping beginner programmers.

1 Like

#3

ahhh, ok. yes the simple script works fine with prompt in a browser I just didnt know if prompt was defined in node.js thank you

0 Likes