Most people land here with VSCode already open and a .js file sitting in it, and nothing happens when they try to run it. The fix is usually small. Install Node.js LTS, open the integrated terminal with Ctrl+`, and type node app.js.
VSCode doesn’t execute anything on its own. It passes the file to a runtime, which is Node.js when you run from the terminal, Code Runner or the debugger, and a browser when the code touches the DOM.
Microsoft’s VS Code documentation (updated November 2026) describes a JavaScript Debug Terminal that debugs any Node.js process started inside it. I reach for it more than launch.json these days, since you get breakpoints without writing a config file.
What Does VSCode Need Before It Can Run JavaScript?

You have to install a JavaScript runtime yourself, because the editor doesn’t ship with one.
Beginners get caught by this a lot. It makes sense once you know what VSCode actually is, though. It’s an editor with a debugger attached, not an engine that executes code.
Node.js runs .js files outside the browser, and the terminal, Code Runner and debugger methods all go through it. Scripts that use document, window or anything else from the DOM need a browser instead, usually served through Live Server.
Pick the Node.js LTS release rather than the newest build. The Node.js release page (November 2026) lists v22 Jod, v24 Krypton and v26 Lithium as LTS lines, and LTS typically guarantees critical bug fixes for a total of 30 months. On a machine you’re learning on, I wouldn’t bother chasing the current line.
Once it’s installed, check it from inside VSCode:
node -vA version number back means you’re set. If you get “command not found” or “not recognized” instead, Node.js is missing from the PATH variable (the fix is further down).
Save your first file inside a workspace folder (File, then Open Folder). The terminal and the debugger both anchor to that folder.
You don’t need any extensions at this point.
How to Run a JavaScript File in the Integrated Terminal

This is the method I’d start everyone on. Output prints right below the command you type.
- Open the project folder with File, then Open Folder.
- Create a file named app.js and add
console.log("Hello"); - Save it with Ctrl+S.
- Press Ctrl+` to open the integrated terminal.
- Type
node app.jsand press Enter. - Read the result in the terminal.
If you’d rather use the menu or pick a different shell, there’s a guide to opening the terminal in VSCode.
The terminal opens at the root of your workspace. You can point it somewhere else with the terminal.integrated.cwd setting, though I’ve rarely needed to. For a script inside a subfolder, give node the relative path, as in node js/script.js.
One thing trips people up constantly. Node executes the file saved on disk, so an unsaved edit never runs. When a fix “does nothing”, check the tab for the unsaved dot before anything else.
Running JavaScript with Code Runner and Quokka.js
Code Runner runs the current file with Ctrl+Alt+N or the Run Code button and prints to the Output panel. Quokka.js works differently. There’s no run step at all, and values show up inline while you type.
You’ll find both in the Marketplace. Once the basics work, the wider pool of VSCode extensions is worth a browse.
Code Runner
The Visual Studio Marketplace lists 42,876,279 installs for Code Runner, with Ctrl+Alt+N as the Run Code shortcut. Popular, sure, but it doesn’t remove the runtime requirement. The extension needs Node.js installed on your machine to run JavaScript.
By default, results go to the Output window. The code-runner.runInTerminal setting is false by default and only supports running a whole file, not an untitled file or a snippet. To turn it on, edit settings.json:
"code-runner.runInTerminal": trueThe appeal is easy to see. There’s no configuration and it’s one shortcut. It also runs code files in multiple programming languages, which helps if you bounce between JavaScript and Python, and selected snippets run in the default Output mode.
The downsides are real, though. It does not use the integrated terminal by default, which limits input and output for complex scripts, so anything waiting on user input just sits there. Terminal mode fixes that but refuses snippets. And you still need Node.js anyway.
Quokka.js
Quokka is a scratchpad, not a runner.
As you type, runtime values update next to your code. You get inline reporting plus an Output and Details view for digging into nested values, and it reads JavaScript and TypeScript files.
There’s a free Community edition. The Pro edition is paid, and the docs mark its advanced features with a “Pro Feature” badge, which makes it easy to see what you won’t get before you try something.
| Fits | Does not fit |
|---|---|
| Testing a regex or an array method in seconds | Running a full app with real arguments |
| Watching a value change line by line | Anything needing the Pro features without paying |
| Learning syntax with instant feedback | Replacing a proper node run before shipping |
How to Run and Debug JavaScript with launch.json

With a JavaScript file open, F5 runs it under the debugger and Ctrl+F5 runs it without debugging. On Windows and Linux, Ctrl+Shift+D opens the Run and Debug view.
A plain file often needs no configuration at all. VSCode asks which environment to use and starts the run.
Set up launch.json
Sometimes you do need the file. The VS Code documentation (updated 10/28/2026) says to create a launch.json configuration when your app needs a specific entry point, arguments or environment variables.
It lives in the .vscode folder of the workspace. Click Add Configuration and you’ll get snippets such as Launch Program.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app.js"
}
]
}Get the path in the program field wrong and the launch stops before a single line runs. It’s usually a typo or a file that got moved.
For breakpoints, the Node.js debugging documentation covers conditional, hit count and triggered breakpoints, plus logpoints. Logpoints are underrated, honestly. VS Code also offers inline, function and data breakpoints, but which of those work depends on the debugger, so test them before relying on them.
During a session, the Debug Console (Ctrl+Shift+Y) works as a REPL for evaluating expressions.
Techniques past breakpoints are collected in a separate piece on debugging JavaScript.
Skip the file with the JavaScript Debug Terminal
Any Node.js process you run inside the JavaScript Debug Terminal gets debugged. Open one with the Debug: Create JavaScript Debug Terminal command, or from the terminal dropdown.
Auto Attach does the same job for the regular terminal. You set it through debug.javascript.autoAttachFilter, which takes smart, always or onlyWithFlag. After toggling Auto Attach, restart the terminal or open a new one, otherwise nothing changes.
The debugger supports Node 8.x and above, plus recent Chrome and Edge versions, so any current LTS release works.
How to Run Browser JavaScript from VSCode
Here the output never comes back to VSCode. You serve the HTML file with Live Server and read the results in the browser’s DevTools console. If you want breakpoints, attach the debugger to Chrome or Edge through launch.json instead.
By browser JavaScript I mean a script linked from an HTML page:
<script src="app.js"></script>Live Server
The Visual Studio Marketplace lists 83,811,748 installs for Live Server, which makes it the default route for HTML and JavaScript pages.
The quickest way to start it is Go Live in the status bar. You can also right-click an HTML file and choose Open with Live Server, or press Alt+L, Alt+O if you like shortcuts. The browser refreshes whenever you change the page.
The port is customizable, and since version 5.6.0 the extension falls back to a random port when the chosen one is busy. Server-side pages such as PHP need the separate Live Server Web Extension. CORS is disabled by default too.
Output goes to the browser console (F12), never to the VSCode terminal. Almost everyone looks in the wrong place on their first page. I did.
Web work pulls in more tooling over time, and a list of extensions for web development saves you some trial and error.
Debugging in Chrome or Edge
Browser breakpoints go through the same launch.json file as Node.js. Only the type changes.
The documentation (page dated 10/28/2026) names msedge and chrome as the launch.json types for Edge and Chrome, plus editor-browser for debugging inside the integrated browser of VS Code.
The url field is the page to open at launch. webRoot sets the source root for source maps and defaults to the workspace folder, so most of the time you can leave it alone. If you’d rather skip the server, the file field debugs a single HTML file directly.
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Open index.html",
"url": "http://127.0.0.1:5500/index.html",
"webRoot": "${workspaceFolder}"
}
]
}Match the url to the address Live Server shows, then press F5.
The Debug: Open Link command skips the config file entirely. It picks Edge when that’s your default browser and looks for Chrome otherwise.
Already have the browser running? Launch it with the –remote-debugging-port flag and add an attach configuration with the matching port.
Which Method Fits Your Script?
The integrated terminal handles quick runs. Reach for Run and Debug when you need breakpoints, Code Runner or Quokka.js for one-click tests, and Live Server for anything that touches the DOM.
| Method | Runtime | Output appears in | Fails when |
|---|---|---|---|
| Integrated terminal | Node.js | Terminal | File unsaved, wrong folder |
| Code Runner | Node.js | Output panel | Script waits for input |
| Run and Debug | Node.js, Chrome, Edge | Debug Console | Wrong program path |
| Live Server | Browser | DevTools console | Page needs a PHP backend |
Look at the runtime column for a second. Code Runner, the debugger and the terminal all lean on Node.js, and only the browser routes skip it. So Node.js is the single point of failure, and a broken install takes down 3 of the 4 methods at once.
Decision rules
For a one-off test, the terminal or Quokka.js is plenty. A bug you can’t see needs Run and Debug, with a breakpoint on the suspect line.
If the script asks for input, run it in the terminal, not Code Runner’s default Output panel. Anything with document or window goes to Live Server first, then Chrome or Edge debugging once you need to step through it.
My pick for most people is the plain terminal. It needs no extension, behaves the same on every machine, and teaches the exact command that CI servers run later.
The other cost is remembering shortcuts. A VSCode workflow cheat sheet keeps Ctrl+Alt+N, F5 and Ctrl+Shift+D in one place.
Why Does JavaScript Fail to Run in VSCode?
It’s nearly always the same short list. Node.js is missing from the PATH variable, or the terminal sits in the wrong folder. Sometimes browser code gets run through Node.js. Or the file just isn’t saved.
| Symptom | Cause | Fix |
|---|---|---|
| node is not recognized | Node.js not on PATH | Reinstall with the PATH option, restart VSCode |
| Cannot find module | Terminal in the wrong folder | Run pwd, then cd to the project |
| document is not defined | Browser code run through Node.js | Serve the page with Live Server |
| Code Runner prints nothing | Output panel hidden, or file unsaved | Save, then open View, Output and pick the Code channel |
| Old output after an edit | Previous run still showing | Save and run again |
Fixing a PATH problem

A quick note on the “document is not defined” row first. Node.js runs the V8 engine outside the browser, so browser objects such as document and window do not exist in it. There’s no code fix for that one, only a different runtime.
Now PATH. A terminal reads the PATH variable when it starts, so one opened before the Node.js install never sees the new entry. Close VSCode completely, not just the panel.
To confirm it worked, run where node on Windows or which node on macOS and Linux.
WSL adds a catch. A Node.js install on Windows is invisible inside a WSL distribution, and the reverse holds too.
PowerShell blocking npm
This one looks like a Node.js problem and isn’t. A Microsoft Learn answer dated 2026-04-24 shows the typical message: npm.ps1 cannot be loaded because running scripts is disabled on this system.
The blocked file is a PowerShell wrapper. That’s why npm commands fail while the node command itself can run.
Microsoft’s own documentation disagrees with itself on the cause. The current about_Execution_Policies page lists RemoteSigned as the default for Windows computers, yet the same page also says the effective policy is Restricted for Windows clients when no scope sets one. The PowerShell 7.4 Set-ExecutionPolicy page likewise calls Restricted the default for Windows client computers.
The symptom is consistent across all of it, at least. Check your own setting with Get-ExecutionPolicy before changing anything.
The usual fix is setting the execution policy to RemoteSigned for the current user scope. If you’d rather not touch the policy, run Terminal: Select Default Profile, or set the terminal.integrated.defaultProfile.windows setting, and switch to a shell without the restriction. A full walkthrough of the VSCode terminal covers the profile picker.
Running JavaScript in VSCode FAQ
How do I stop a running script in VSCode?
In the integrated terminal, Ctrl+C ends a node process.
Under Run and Debug it’s Shift+F5, or the red square in the debug toolbar.
Can I run JavaScript in VSCode without installing Node.js?
Only for browser code. A browser is the runtime for DOM scripts, and the documentation shows the file field debugging an HTML file without a server.
Plain .js files run through the terminal, Code Runner or the debugger still need Node.js.
How do I switch Node.js versions inside VSCode?

You’ll want a version manager such as nvm (nvm-windows on Windows). In the integrated terminal, run nvm use with the version number, then confirm with node -v.
If VSCode keeps reporting the old version, restart the terminal.
Does VSCode run import and export syntax?
It does, through Node.js. Files ending in .mjs are read as ES modules, and so are .js files when package.json contains “type”: “module”.
In Node.js 22.7 and later (and 20.19 and later), a .js file with no “type” field is also checked for ES module syntax, so a plain import statement runs without extra setup. Setting “type”: “module” explicitly avoids the detection cost. Older Node.js versions, or a package.json with “type”: “commonjs”, fail with “Cannot use import statement outside a module”.
How do I pass command-line arguments to a script?
Put them after the file name in the terminal, as in node app.js first second, and read them from process.argv.
In launch.json, the same values go in an args array.
Setting Up a Project That Starts with One Command
Running JavaScript in VSCode on a real project comes down to package.json for the command line and launch.json for the debugger. Both stay small.
- Run npm init -y in the project folder.
- Add a start entry under scripts, such as “start”: “node app.js”.
- Point the program field in launch.json at app.js.
The start script goes first because it proves the entry file runs before the debugger configuration depends on it.
The catch is that the entry file name now lives in two places. Rename the file and npm start and F5 break separately, which is annoying the first time you hit it.
If you hand-edit package.json, remember the comma after the preceding entry. JSON rejects a missing one.
Per-project preferences such as the default shell sit in settings.json, and a guide to VSCode settings covers the rest.
- PyCharm vs VS Code for Python: Speed, Debugging, Cost - December 1, 2026
- How to Choose a Digital Transformation Consulting Partner - November 30, 2026
- Is Notepad++ Safe? Official Download, Updates, CVEs - November 29, 2026



