For example, suppose you have a script called index.js with the following code:
To run the file, you first need to open the integrated VSCode terminal in View > Terminal menu command:
Once inside the terminal, you can then run the code using node name_of_file.js command. The picture below shows the result of running node index.js command on the terminal:
Using Code Runner Extension
But internally, Code Runner also looks for Node.js that’s installed on your local machine, so you need to install Node.js either way.
Save 1000+ hours of research and 10x your productivity
Sebhastian is a site that makes learning programming easy with its step-by-step, beginner-friendly tutorials.
Free Code Snippets Book
Get my FREE code snippets Book to 10x your productivity here
report this ad
For instance, if you were to run a Python script you would type python filename.py or if you wanted to run a C program make filename then ./ filename. How do you do this with .js files?
16 Answers 16
Another answer would be the NodeJS!
Using terminal you will be able to start it using node command.
Note: If you want to exit just type
On older versions of OS X, the jsc command is located at:
You could also run one of your .js script by adding its name as an argument for jsc, like this:
Notice: I use console.log() during development but jsc needs the debug() function instead.
On Ubuntu you have some nice ECMAScript shells at your disposal. Between them it’s worth to mention SpiderMonkey. You can add It by sudo apt-get install spidermonkey
On Windows as other people said you can rely on cscript and wscript directly built on the OS.
UPDATE July 2021: You can also install and use the brilliant QuickJS which on OS X could be installed via brew install quickjs . Then an interactive console will be available at your propmt with qjs
launch.json файл настройки для Visual Studio Code
Если у вас не установлена Visual Studio Code , нужно установить Visual Studio Code . .
Открываем Visual Studio Code
function calculate_sum(a, b)
// calculate sum
var sum = a + b;
Опять запускаем проект т.е. нажимаем Run → Start Debugging и выбираем Chrome .
Появится файл с настройками launch.json .
В параметре url напишем путь к запускаемому файлу.
Запускаем программу в отладчике (debug). Нажимаем Run → Run Debugging или кнопку F5 .
Программа запущена и мы можем смотреть:
• WATCH (значение переменных)
• CALL STACK (стэк вызова функций)
• BREAKPOINTS (ставить, убирать точки остановки)