Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do you create launch json in Visual Studio Code?

To create a launch. json file, click the create a launch. json file link in the Run start view. If you go back to the File Explorer view (Ctrl+Shift+E), you'll see that VS Code has created a .

How do I launch a json file in Visual Studio?

js Apps with Visual Studio Code. Click on Run and Debug in the Activity Bar (⇧⌘D (Windows, Linux Ctrl+Shift+D)) and then select the create a launch. json file link to create a default launch. json file.


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.


Like this, under your OS:

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

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",
  ...
}

Since late 2016 you can also use the envFile for Node.js projects:

The VS Code Node debugger now supports to load environment variables from a file and passes them to the node runtime. https://github.com/Microsoft/vscode/issues/15964

Also see: Load environment variables from external file (node):

To use this feature, add an attribute envFile to your launch configuration and specify the absolute path to the file containing the environment variables:

For Asp.Net Core projects, this feature isn't supported natively by vscode but it has recently been added to the omnisharp vscode extension. This feature is available since September 10, 2018 via v1.16.0.