Visual Studio Code to use node version specified by NVM

In VS Code:

  • go to your launch.json file
  • add the runtimeVersion attribute inside configurations as shown below

In this example, we are assuming 4.8.7 is already installed using nvm:

{
"version": "<some-version>",
"configurations": [
    {
        "type": "node",
        "runtimeVersion": "4.8.7", // If i need to run node 4.8.7
        "request": "launch",
        "name": "Launch",
        "program": "${workspaceFolder}/sample.js"
    }
]}

The solution is to set alias default. In the OS terminal run -

nvm alias default 7.8.0

Open vscode, now running node -v returns 7.8.0

It seems vscode takes up this (alias default) value and not the node version that is set by nvm use X.X.X

Restart VS code for it to pick up the changes.


add runtimeExecutable to your .vscode/launch.json like this

{
  "type": "node",
  "request": "launch",
  "name": "App",
  "program": "${workspaceRoot}/index.js",
  "runtimeExecutable": "${env:HOME}/.nvm/versions/node/v6.9.2/bin/node"
}