In vscode using node.js, ctrl+F5 always asks for “select environment”. This didn't happen a few weeks ago

Viewed 1492

Whenever I press F5 or Ctrl+F5, vscode asks me to "select Environment". I have to choose Node.js every time. Somebody has given this solution: Run > Add Configuration > select Environment. It works for that particular folder. However, when I change folders the problem persists. How can I set up configurations globally? The worst part is that this problem started appearing since 4-5 weeks. Before that vscode was automatically debugging & running my files on node.js

3 Answers

The type key is missing in /.vscode\launch.json (Access it from the top left gear icon or open it in vscode), please see @Andy's answer:

{
"version": "0.2.0",
"configurations": [
    {
        "type": "node", // to avoid the environment Select
        "request": "launch",
        "name": "Debug File",
        "program": "${file}"
    }
]

}

If the type key is not there, Vscode asks you about the type.

There is actually an official solution for this and there is no need to install other extensions, as Visual Studio Code comes with support of Node.Js

The configuration file for running and debugging is in .vscode\launch.json, which can be found in the Run panel.↓

enter image description here

Then you can change the configuration file to the desired effect. If you want to run or debug the current file directly, the configuration is like this

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug File",
            "program": "${file}"
        }
    ]
}

it is also possible to run the index.js file in the current working directory.

"program": "${workspaceFolder}/src/index.js"

More information:

https://go.microsoft.com/fwlink/?linkid=830387

Debugging current file in VS Code

Related