Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i pass environment params inline on windows cmd

i need to run a script with node on windows like:

HOST=www.host.com node index.js

but this showme a error like "HOST" no se reconoce como un comando interno o externo*


*English Translation: "HOST" is not recognized as an internal or external command

like image 467
Rodrigo Chable Avatar asked Oct 27 '25 11:10

Rodrigo Chable


1 Answers

What you want is to run both the set command to set your Host environment variable in the same line that you run your script with node. Running two commands one after an other is possible in the command line with the & and && operators.

From ss64

commandA &  commandB      Run commandA and then run commandB
commandA && commandB      Run commandA, if it succeeds then run commandB 

Here, since you likely don't want to continue to executing your node script if you are unable to set the environment variable, you would likely want to opt for the && operator for this use case.


Final Code:

set "HOST=www.host.com" && node index.js

Note:

SET in this context will never return an error. As such, both & and && are functionally identical for this use case.

like image 128
Spyre Avatar answered Oct 29 '25 00:10

Spyre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!