- Visual Studio Code: The software can be downloaded for free from the official Microsoft website;
Let’s start with the installation process:
- Download and install Visual Studio Code from the official Microsoft website;
- Download and install Node.js from the official Node.js website;
- Ensure you’ve successfully installed both of these tools before proceeding.
Open VS Code.
- Click on “File” on the top menu bar, then click “New File” or use the shortcut Ctrl+N to create a new file;
- Save this file with a .js extension (for example, myfile.js). You can do this by clicking on “File” -> “Save As”, then entering the file name and selecting the destination.
This script simply prints the text “Hello, World!” to the console.
- Open the Terminal in VS Code. This can be done by clicking on “Terminal” in the top menu bar, then clicking on “New Terminal”, or using the shortcut Ctrl+ ` (Ctrl + backtick);
- Your output will appear in the Terminal window. For the example we used above, the Terminal should print:
- Click on the Debugging icon in the Activity Bar on the side, or use the shortcut Ctrl+Shift+D;
- At the top of the Debug view, click on “create a launch.json file”. A dropdown will appear, from which you should select “Node.js”;
- VS Code will open a new file called launch.json with some predefined configurations. For now, we can use the default configuration;
- Now, you can run the debugger by pressing F5 or by clicking on the “Start Debugging” green triangle at the top of the Debug view;
- The code execution will stop at your breakpoint, and you can inspect variables, step through your code, and make use of many other debugging features.
This error means that Node.js is not installed, or it is not added to your PATH. Make sure you’ve installed Node.js and added it to your system’s PATH.
When you’re debugging, you can see the console output in the “Debug Console” tab. To open this tab, use the shortcut Ctrl+Shift+Y or click on “View” -> “Output”.