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

Version 1.49.1

You can add env variables by using the env property in your launch.json file or by using the envFile property with the value being the location of your .env file.

Warning: If you already have a .env file it auto includes it. (per denislexic comment)

env example:

{
  ...
   "env": { "PORT": "4000" }
  ...
}

envFile example:

{
  ...
  "envFile": "${workspaceFolder}/server/.env",
  ...
}

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"
      }
    }
  ]
}

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"
        }
    }
]

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.