Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

enter image description here

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

like image 538
user3848207 Avatar asked Jan 25 '23 01:01

user3848207


2 Answers

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.

enter image description here

This answer works on VS code v1.45

like image 176
guagay_wk Avatar answered Jan 28 '23 09:01

guagay_wk


I will answer my own question.

enter image description here

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.

like image 32
user3848207 Avatar answered Jan 28 '23 10:01

user3848207