How do I add environment variables to launch.json in VSCode

Working with the new VSCode editor on a node.js project. I am attempting to configure my "Launch" profile for debugging by editing the launch.json file. I need to setup a connectionstring as an environment variable. According to the comments in the launch.json file:

// Environment variables passed to the program.
"env": { }

I have tried adding my environment variable like so:

"env":
{
"CONNECTION_STRING": "Data Source=server;Initial Catalog=catalog;User ID=uid;Password=pwd;MultipleActiveResultSets=true"
}

This causes an error when I try to launch my app; "OpenDebug process has terminated unexpectedly". I have not yet found any log files, etc. that might explain what the issue is.

I know this app works correctly when I setup the environment variable and launch my app from the standard command prompt. The app also runs as expected if I comment out my variable in the launch.json file; I just can't connect to the database.

I am assuming that I am using the wrong format in the launch.json file, but I have not yet found any way to make this work.

Any ideas?


Solution 1:

I'm successfully passing them using the env property in launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "pwa-node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "program": "${workspaceFolder}/index.js",
      "env": {
        "TEST_VAR": "foo"
      }
    }
  ]
}

Solution 2:

this is working

enter image description here

just add the following

"env": { "NODE_ENV": "development" }

"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program", //TODO: cmd as launch program
        "skipFiles": [
            "<node_internals>/**"
        ],
        "program": "${workspaceFolder}\\index.js",
        "env": {
            "NODE_ENV": "development"
        }
    }
]

Solution 3:

There seems to be a problem with environment variables on Windows (and probably on linux). It does work on OS X. We are investigating. Expect a fix soon.

Update (June 2, 2015): Visual Studio Code 0.3.0 contains a fix for this.

Solution 4:

Like this, under your OS:

        "osx": {
            "MIMode": "lldb",
            "environment": [{"name": "DYLD_LIBRATY_PATH", "value": "/Users/x/boost_1_63_0/stage/lib/"}]
        },