This procedure walks you through running a JavaScript program in Visual Studio Code using the terminal.
🧰 Prerequisites
Set up all three before continuing. The steps below assume they are already in place.
- Node.js installed
- Visual Studio Code installed
- JavaScript project created in VS Code
📋 Steps
-
Open Visual Studio Code with the project folder open.
-
Open the built-in terminal using the menu View → Terminal.
-
Make sure the terminal is in the project folder. The last folder name in the terminal prompt should match the project name. If it is not, navigate to it with
cd ProjectName. -
Run the program with:
node index.js.
🎯 Expected Outcome
The program output appears in the terminal directly below the node index.js command.
⚠️ Mistakes
Running from the wrong folder
node index.js looks for index.js in the current folder. If the terminal is in a parent folder or elsewhere, the command fails with an error like Cannot find module. Use cd ProjectName to move into the folder that contains index.js.
Typing the file name wrong
The command must match the file name exactly, including the .js extension: node index.js, not node index. A mismatch fails with Cannot find module. Check the name in the Explorer if the command does not run.
Expecting the file to run without saving
node runs the file on disk, not the unsaved editor contents. If changes were made but not saved, the previous version runs. Save with Ctrl+S (Windows/Linux) or Cmd+S (Mac) before running.
📚 Resources
- Working with JavaScript in VS Code (external link), official guide
- Node.js command-line reference (external link), official docs