I'm trying to run the debugger in VS Code on my nodejs application. I'm using an .env file to store environment variables that I later call with process.env.. When I looked up the VS Code docs for the launch.json, it mentions the envFile option to load the the .envFile. Unfortunately, this is not loading the files when I run the debugger.
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "RegressionTestSuite",
"autoAttachChildProcesses": true,
"program": "node ${workspaceFolder}/node_modules/.bin/cucumber-js",
"args": [
],
"envFile": "${workspaceFolder}/.env"
},
]
}
.env:
export SCREEN_SIZE_WIDTH='1366';
export SCREEN_SIZE_HEIGHT='768';
When I run the VS Code debugger, there are no environment variables from my .env file. How should I be calling the .env file in the launch.json?
I Should add some more infomoarion afetr I got it working:
I ended up making my .env file a list of environment variables
.env file example:
# Standard supported size is width='1366, height=768
SCREEN_SIZE_WIDTH='1366'
SCREEN_SIZE_HEIGHT='768'
EPAY_GUI_AUTOMATION_TEST_DEBUG_MODE='yadda_yadda_yadda'
in my nodejs world constructor, I included
world.js example:
enter code here`enter code here`require('dotenv').config();
process.env.EPAY_GUI_AUTOMATION_TEST_DEBUG_MODE
and in the hook.js I used:
BeforeAll(async function() {
this.browser = await puppeteer.launch({
headless: (process.env.HEADLESS === 'true'),
slowMo: parseInt(process.env.SLOWMO),
defaultViewport: {
width: parseInt(process.env.SCREEN_SIZE_WIDTH),
height: parseInt(process.env.SCREEN_SIZE_HEIGHT)
}
});
.
.
.
I kept the launch.json the same.
I would use the dotenv package to load your .env
file, as it can be used by people who aren't using VS Code as well. If you want to include it in your VS Code config, you could do:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "RegressionTestSuite",
"autoAttachChildProcesses": true,
"program": "node -r dotenv/config ${workspaceFolder}/node_modules/.bin/cucumber-js",
"args": []
},
]
}
Your problem could also be that your .env
file should not contain export
and semi-colons, as it is not a JavaScript file:
SCREEN_SIZE_WIDTH=1366
SCREEN_SIZE_HEIGHT=768
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With