5

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

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! Manually edit launch.json such that "program": "${file}" - this helped.
this should be the selected answer
4

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.

2 Comments

Not a good answer. When you look at the launch.json file created, it works only specifically on a particular js file. You'll be prompted again when you try with a new js file.
@guagay_wk you can make the launch.json affect all the files by using "program": "${file}" instead of the explicit file path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.