I am surprised this has not been mentioned yet:
Simply open the .js file in question in VS Code, switch to the 'Debug Console' tab, hit the debug button in the left nav bar, and click the run icon (play button)!
Requires nodejs to be installed!
Answer from tenwest on Stack OverflowI am surprised this has not been mentioned yet:
Simply open the .js file in question in VS Code, switch to the 'Debug Console' tab, hit the debug button in the left nav bar, and click the run icon (play button)!
Requires nodejs to be installed!
This is the quickest way for you in my opinion;
- Open integrated terminal on visual studio code (
View > Integrated Terminal) - type
'node filename.js' - press enter
note: node setup required. (if you have a homebrew just type 'brew install node' on terminal)
note 2: homebrew and node highly recommended if you don't have already.
have a nice day.
Videos
So I am actually a beginner in the coding world. I learn python some months ago and now I want to learn JavaScript but i don't know where to begin with. I read throughout the internet like download node.js and all but I didn't some how understood that can you correct me in the next lines if i am lacking some information:
To type javascript in VS code I need to download node.js
Then I have to open the VS code and fetch the file extension with js And anyone correct me and guide me after 2nd step
Or is there any other way to start with js without much hustle Like someone had written that you just need a browser to learn js and can be performed in console section of the browser
Open launch.json
Then paste this entire chunk if empty, or add the single object to an existing list.
{
"version": "0.2.0",
"configurations": [
{
"name": "Node: Current File",
"type": "node",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
Now when you click on the Debug menu (the bug > button) on the side panel (or press F5), You'l have a Node: Current File as a run time dropdown option that will execute your JS via Node, and display the results in the attached VSC terminal.
Click the green triangle (my first image) to start debugging (or press F5) and pay attention to the terminal output (in VS code).
NOTE:
If you attach break points, by clicking on the line numbers, indicated with red dots, you can use the Debug Console (left of Terminal tab)as a namespace environment to check variables etc (much like Quokka), during control flow evaluation.
I took this snippet from the VS Code documentation. It's a solid read.
I just want to add to this. I had this working as accepted answer with the "Chrome debugger" plugin, which is now deprecated and the built-in js-debug is referenced as the replacement. I spent a good 2 hours for this to work with Angular yesterday. I tried both using the node configuration and also the chrome and edge type like the documentation says should work. Didn't get it to work.
What actually solved it for me was:
ng servein the terminal to bring up the angular dev server on https://localhost:4200 (I have added a localhost certificate to use SSL/TLS, out of the box, dev server runs on http)- open chrome and go to https://localhost:4200
- using
ctrl+shift+P>Debug: Open Linkand then typing the url https://localhost:4200 to my dev chrome instance
It is now attached properly and the debug console is reflecting that it is actually attached. I can set break points and debug the code.
I should add that I am running WSL and using vs code remote to point to my WSL instance, where my code also resides, within the wsl filesystem.
Typescript debugging documentation, Angular
Most websites online recommend executing a JS file via 'node myfile.js' in visual studio code.
Is there a simple extension (e.g. without browser) where I can execute JS code line by line? Like a jupyter notebook, mark code then press CTR/Shift-enter to execute selected lines?