I think what you mean is basically running the script in the console.

Visual Studio Code has very little to do with this - though it does offer a terminal window(docs) for your convenience, I personally always use the linux terminal(docs). But that's up to you.

So, to run javascript on the machine rather than the browser you need to install node.

  • step 1: install node here are the docs for that.

Now all you need to do is write your script and then run it.

  • step 2: write script

let name = prompt("what is your name");

prompt() (docs)would get you the name prompt and store the input as the script is running in the terminal. so write your script let's say something like:

nameProgram.js;

console.log("Welcome to this awesome software that can tell you your own name!");
let name = prompt("What is your name?");
console.log(`Your name is ${name}! see how cool!`);
  • step 3: run program

open the terminal whichever way you prefer, go to the directory of the script and type in the following command: node nameProgram.js

That's it, your script will run.

Answer from aviya.developer on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › javascript
JavaScript in Visual Studio Code
November 3, 2021 - When you move or rename a file that is imported by other files in your JavaScript project, VS Code can automatically update all import paths that reference the moved file: ... The setting(js/ts.updateImportsOnFileMove.enabled) setting controls this behavior. Valid settings values are: "prompt" - The default.
🌐
YouTube
youtube.com › watch
How to Take Input in JavaScript using Visual Code | How to Run JavaScript in Visual Studio Code - YouTube
#JavaScript#VisualCode#WebDevelopmentHow to Take Input in JavaScript using Visual Code | How to Run JavaScript in Visual Studio CodeCopy Code From below lin...
Published   September 30, 2021
🌐
Visual Studio Code
code.visualstudio.com › docs › nodejs › working-with-javascript
Working with JavaScript
November 3, 2021 - The Babel transpiler turns ES6 files into readable ES5 JavaScript with Source Maps. You can easily integrate Babel into your workflow by adding the configuration below to your tasks.json file (located under the workspace's .vscode folder). The group setting makes this task the default Task: ...
🌐
Reddit
reddit.com › r/learnjavascript › how to run js that involves prompts in vscode?
r/learnjavascript on Reddit: How to run js that involves prompts in VSCode?
October 30, 2024 -

I'm programming a card game to refresh my programming skills but I'm kind of going in blind. I have the code runner extension, which has been great so far, but when I try to prompt a user for input or display a window with text in it, I get "ReferenceError: prompt is not defined."

Based on my my reading it seems like this wouldn't happen if I ran it in a browser, but frankly I don't know how to do that lol.

Is there a way to run this sort of js code in VSCode? If not, how do I run things in my browser (I use firefox)?

🌐
GeeksforGeeks
geeksforgeeks.org › how-to-take-input-in-javascript-in-vs-code-terminal
How to Take Input in JavaScript in VS Code Terminal ? | GeeksforGeeks
March 4, 2024 - Example: The below example uses process.argv to take input in JavaScript in VS Code Terminal. ... const input = process.argv[2]; if (input) { console.log(`Your Name is: ${input}`); } else { console.log('No input provided.'); } ... In this approach, we are using process.stdin, the script uses process.stdout.write to prompt the user with 'Enter Your Name:' and listens for data events on process.stdin to capture the user's input.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-course-javascript-prompt-example
JavaScript Course Prompt Example - GeeksforGeeks
July 11, 2025 - By writing this link in the script tag we are making sure that when we write the ‘SweetAlert’ javascript code it works the way it is supposed to. ... // getting the names and age from user with the // help of prompt let name = prompt('What is your name?'); let age = prompt('What is your age?'); let entryAge = 18; let seniorAge = 60; // printing the age to the console alert(`Your name is ${name} and you are ${age} years old.`); // using conditional if-else if( (age > entryAge) && (age <= seniorAge)){ // console.log('Welcome to La La Land!'); swal({ title: "Great!", text: "Welcome to La La Land!", icon: "success", }); }else if(age > seniorAge){ // console.log('Your ride is free..Have a good Day!'); swal({ title: "Awesome!", text: "Welcome Sir/Mam to La La Land!", icon: "info", }); }else{ //console.log('Sorry..
Find elsewhere
🌐
GitHub
github.com › formulahendry › vscode-code-runner › issues › 42
Why show the error "prompt is not defined"? · Issue #42 · formulahendry/vscode-code-runner
December 19, 2016 - Dear guys: I use Visual Studio Code recently, and I found something strange today. When I use the plugin named "Code Runner" to test my code which involves the function "prompt()&quo...
Author   seiferthan
🌐
npm
npmjs.com › package › @vscode › prompt-tsx
vscode/prompt-tsx
2 weeks ago - Here is an example of using TSX prompts in a Copilot chat participant that suggests SQL queries based on database context: import { renderPrompt } from '@vscode/prompt-tsx'; import * as vscode from 'vscode'; import { TestPrompt } from './prompt'; const participant = vscode.chat.createChatParticipant( 'mssql', async ( request: vscode.ChatRequest, context: vscode.ChatContext, response: vscode.ChatResponseStream, token: vscode.CancellationToken ) => { response.progress('Reading database context...'); const models = await vscode.lm.selectChatModels({ family: 'gpt-4' }); if (models.length === 0) {
      » npm install @vscode/prompt-tsx
    
Published   Mar 18, 2026
Version   0.4.0-alpha.8
Author   Microsoft Corporation
🌐
Stack Overflow
stackoverflow.com › questions › 72510803 › developing-javascript-on-windows-with-vs-code-how-to-handle-prompt
Developing JavaScript on Windows with VS Code: how to handle prompt? - Stack Overflow
June 5, 2022 - I am developing JS on a Windows machine using VS Code as my code editor. I have a fairly simple script that I worked on for the Odin Project: let userInput = parseInt(prompt("Please enter the ...
🌐
Stack Overflow
stackoverflow.com › questions › 70917387 › prompt-problem-in-vs-editor-or-node-js-editor
javascript - prompt problem in VS editor or node js editor - Stack Overflow
VS Code is an editor but doesn't run JS (except through external things) and Node.js isn't an editor, does run JS, but as I said earlier, doesn't implement Web APIs like prompt. ... const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let input = ""; rl.question("input here:\n", function (string) { input = string; console.log("input that was entered: " + input); rl.close(); ... It's a bit more hassle than in other languages. More here: https://www.educative.io/edpresso/how-to-get-user-input-from-command-line-with-javascript
🌐
Codecademy Forums
discuss.codecademy.com › web development
Prompt is not defined? - Web Development - Codecademy Forums
December 1, 2019 - my javascript file has an error my filename=a.js var name = prompt("enter your name"); console.log("hello"+name+"!"); i debugged it in VS CODE and in Node command prompt.Both are showing this error: vs code error …
🌐
Reddit
reddit.com › r/vscode › javascript on vscode: error with prompt command
r/vscode on Reddit: JavaScript on VSCode: Error with Prompt command
March 23, 2024 -

Hi,

I am trying to run the following Javascript code on Visual Studio Code:

try{
    const prompt = require('prompt-sync')({sigint: true});
}catch(err) { 
    console.log(err); 
} 
let person = prompt("Please enter your name", "Harry Potter"); 
if (person != null) { 
    document.getElementById("demo").innerHTML = "Hello " + person + "! How are you today?"; 
}

I am getting the following error:

Error: Cannot find module 'prompt-sync'
Require stack:
d:\Javascript\programs\posNegZero.js     at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)     at Module._load (node:internal/modules/cjs/loader:985:27)     at Module.require (node:internal/modules/cjs/loader:1235:19)     at require (node:internal/modules/helpers:176:18)     at Object.<anonymous> (d:\Javascript\programs\posNegZero.js:3:16)     at Module._compile (node:internal/modules/cjs/loader:1376:14)     at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)     at Module.load (node:internal/modules/cjs/loader:1207:32)     at Module._load (node:internal/modules/cjs/loader:1023:12)     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {   code: 'MODULE_NOT_FOUND',   requireStack: [ 'd:\Javascript\programs\posNegZero.js' ] } d:\Javascript\programs\posNegZero.js:7 let person = prompt("Please enter your name", "Harry Potter");              ^
ReferenceError: prompt is not defined     at Object.<anonymous> (d:\Javascript\programs\posNegZero.js:7:14)     at Module._compile (node:internal/modules/cjs/loader:1376:14)     at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)     at Module.load (node:internal/modules/cjs/loader:1207:32)     at Module._load (node:internal/modules/cjs/loader:1023:12)     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)     at node:internal/main/run_main_module:28:49
Node.js v20.11.1
[Done] exited with code=1 in 0.148 seconds

Somebody, please guide me.

Zulfi

🌐
YouTube
youtube.com › watch
How to Run JavaScript in Visual Studio Code on Windows 11 / Windows 10 | JavaScript in VSCode - YouTube
In this tutorial, we will show you how to run JavaScript in Visual Studio Code on Windows. Visual Studio Code is a popular code editor that supports a wide r...
Published   April 14, 2023
🌐
4Geeks
4geeks.com › how-to › how-to-run-javascript-in-visual-studio-code
How to run Javascript in Visual Studio Code?
June 14, 2025 - Visual Studio Code is ready to be used, but we still need NodeJs to run Javascript locally · Open command prompt · Start menu (Finder if you are using mac). Write cmd (Terminal if you are using mac). And open it. Type on the command windows node -v · If NodeJS is present in the system, you´ll see something like v16.51.1 being that the installed version of Node (It could be other version, no worries).
🌐
Visual Studio Code
code.visualstudio.com › docs › editing › intellisense
IntelliSense
November 3, 2021 - You can trigger IntelliSense in any editor window by typing ⌃Space (Windows, Linux Ctrl+Space) or by typing a trigger character (such as the dot character (.) in JavaScript).
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1626466 › javascript-error-)error-cannot-find-module-prompt
JavaScript Error->Error: Cannot find module 'prompt-sync' - Microsoft Q&A
March 21, 2024 - I wrote the following javascript program on VSCode: try{ const prompt = require("prompt-sync")({sigint: true}) }catch(err){ console.log(err) } I am getting th efollowing error message: Error: Cannot find module 'prompt-sync' Following is…