I use VS Code to start a debugging session and in the configuration I define a value for PORT yet it is always undefined. I cannot seem to access these environment variables. Is there another way to access these environment variables?
Below is the launch.json that I am using for a sample project to try to access environment variables. I'd like to be able to use launch configurations to create multiple configurations with different environment variables.
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch server.js",
// Type of configuration.
"type": "node",
// Workspace relative or absolute path to the program.
"program": "server.js",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
"runtimeArgs": ["--nolazy"],
// Environment variables passed to the program.
"env": {
"NODE_ENV": "development",
"PORT" : 8005
},
// Use JavaScript source maps (if they exist).
"sourceMaps": false,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": null
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858,
"sourceMaps": false
}
]
}
I use VS Code to start a debugging session and in the configuration I define a value for PORT yet it is always undefined. I cannot seem to access these environment variables. Is there another way to access these environment variables?
var port = process.env.PORT || 8001;Below is the launch.json that I am using for a sample project to try to access environment variables. I'd like to be able to use launch configurations to create multiple configurations with different environment variables.