Run Javascript code in VS Code

Asked

Viewed 9,026 times

0

I am unable to execute js code through VS code.

Using the recommendation of a post installed the Code Runner using the Control+Alt+N or F1. Always had the following message :

[Running] Node "c: Users thiag Onedrive Documents Udemy Development-Web-udemy Section 8 - Javascript 163 - activities-to-fix-the-content 1.js" 'Node' is not recognized as an Internal or External command, operable program or batch file.

[Done] exited with code=1 in 0.207 Seconds

So I installed the Quokka.js. The above message was replayed and the code was not executed.

Can someone help me ?

Code :

console.log('Teste')
  • 1

    I didn’t understand it very well, but if you create an html file that calls or runs this file in the browser, it wouldn’t solve you?

  • Yes, but the wish was to run straight in vs code.

  • Maybe this link will help you: https://stackoverflow.com/questions/31778413/run-javascript-in-visual-studio-code

  • It was one of the links I left in the question. I’ve read this post.

2 answers

3


Friend, by error message you should not have nodejs installed on your machine.
Javascript is a language originally created to run on the client side, but with nodejs you can use it as a server-side script.
In order to run your . js files on the terminal as if they were a script you need to install the Node.js.

0

As the colleague said, the prerequisite is to install the Node. However, do not need to install any additional extension. Go to the Run > Add Configuration menu, "select the Node.js option (in the command pallet) and save the file (created), without the need for additional settings". This will create a Launch.json file for the project (in a hidden ".vscode" subfolder), which is exclusively used by VS Code, preventing it from always asking which Environment or interpreter you want to use. Source: Duarte, Luiz. Web programming with Node.js: Complete, from Front-end to Back-end . Luiztools. Kindle Edition - Amazon.

To run, type Ctrl+F5 or F5. To debug step-by-step, type F10.

Another practical alternative would be to install the "Node Exec" extension and just run F8.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.