When I am trying to set environment variables using PowerShell in Windows Terminal with the command set test1=value1
, I get no errors. However, when I try to check all environment variables using the set
command, I get the following prompt:
cmdlet Set-Variable at command pipeline position 1
Supply values for the following parameters:
Name[0]:
I read that when using PowerShell you set environment vars using this:
$Env:test1 = "value1";
I want to set the variables so that on my backend in custom-environment-variables.json
I can store a name by which config can extract it using config.get("test").
custom-environment-variables.json
:
{
"test": "test1",
}
But every time I try this, it says Error: Configuration property "test" is not defined
.
Doing the same procedure CMD (either directly or through Windows Terminal) I get no issues whatsoever. Any ideas what might be causing this?
First, the easy part:
That's because the
set
command in PowerShell behaves differently. It's an alias for the PowerShellSet-Variable
cmdlet. You can see this withGet-Alias
.Also, PowerShell variables are not environment variables. As you commented, the proper way to set an environment variable in PowerShell is with:
The equivalent command to
set
(to get a list of all environment variables and their values) in PowerShell is:This access the PowerShell "environment provider", which is essentially (my grossly oversimplified summary) a "virtual drive/filesystem" that PowerShell provides which contains the environment variables. You can also create variables in here.
More reading: about_Environment_Variables from the PowerShell Doc.
As for the core issue with the
config
module, I haven't been able to reproduce that. It works correctly for me in both PowerShell and CMD. So let me run through my results in the hopes that it will help you see what might be different. All tests were performed in Windows Terminal, although as we've determined in the comments, this is more a difference in PowerShell vs. CMD for you:config\default.json
:config\custom-environment-variables.json
:CMD without
test1
variable set:Running
node
in CMD:CMD with
test1
variable set:Exit Node, and back in CMD:
In Node:
PowerShell without
test1
variable set:PowerShell with
test1
variable set:In PowerShell:
In Node: