-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment variables are not being defined while debugging #102
Comments
The "env" attribute is a dictionary of strings. Please pass the PORT number as a string and not as a number. |
Thanks. I saw lower in the launch config that there was another port value which is a number and was copying that instance. Is it possible to define these as numbers? |
Any update per this issue, i am getting undefined for my environment variables while in debug mode |
@montera82 the issue discussed here was a 'user error' and might only be related to your problem if you are using non-string typed values in the "env" section of your launch configuration. If this is the case please fix it as discussed above. If you have a different problem, please create a new issue with the detailed steps and information about your OS and node version. |
hi @weinand , All my environment variables are stored in a file in my root folder named .env ( which has an entry like so Now when running the project from command line, i can do Source .env Then run npm start and the project will be able to resolve the variables. How do i achieve the same when running same project on debug mode. Thanks |
@montera82 you probably have already a launch.json that has a environment variable:
Just add your environment variables to that like this:
Make sure that all env var values are strings. You can find debugging help here: https://code.visualstudio.com/docs/editor/debugging |
Works well, thanks someone will need to add this on the getting started article, i could not find there. |
/cc @gregvanl |
Is there any other route for defining runtime env-vars other than the tasks.json file? For example, something that would be suitable for secrets that shouldn't be in source control? |
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.
The text was updated successfully, but these errors were encountered: