简体   繁体   中英

Make VS code choose Node.js environment by default when debugging js code

I am using VS code v1.45 to debug a simple nodejs file.

I am testing out a simple node.js file.

var msg = 'Hello World';
console.log(msg);

When I press F5, I get prompted to choose the environment. See screenshot below.

在此处输入图像描述

This is a hassle. How do I make VS code choose Node.js environment by default without prompting?

My node.js is installed at C:\Program Files\nodejs\node.exe

I will answer my own question.

在此处输入图像描述

Click on "create a launch.json file" on the debug panel found on left-hand side. Then, click Node.js when prompted. Subsequently, Node.js will be the default environment.

Credit goes to someone by the name of drunktimelord.

I will build on answer by user3848207

Delete any existing launch.json file first. Otherwise, no effect when you click on "create a launch.json file" on the debug panel.

Now, click on "create a launch.json file" on the debug panel found on left-hand side. Then, click Node.js when prompted. Subsequently, Node.js will be the default environment.

Manually edit launch.json such that "program": "${file}" . Otherwise, when you press F5, it will run on specific js file and not on actively open file.

launch.json should look like this.

在此处输入图像描述

This answer works on VS code v1.45

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM