How to run npm variables during run time (process.env.SERVER) on a windows machine using Cmder?

I have created a NodeJs, Selenium and webdriverio framework, but struggling to run npm variables during rune time (The same setup works on a mac).

My wdio file:

if(process.env.SERVER == "prod") {
    baseUrl = 'http://www.google.com';
}

exports.config = {

Running the following command in Cmder:

SERVER=prod npm test

However I get the following message:

'SERVER' is not recognized as an internal or external command,
operable program or batch file.

Operating system: Window 10 pro Bash console: Cmder.

Any ideas ?

1 answer

  • answered 2018-10-11 20:27 Stock Overflaw

    The closest behavior seems to be SET SERVER=prod && npm test. SET /? claims that it:

    Displays, sets, or removes cmd.exe environment variable

    I guess that should be accessible through Node.

    However, contrary to usual shells, setting a variable seems to be a command in itself, hence requiring an explicit separator before the next command: here && to one-line it, you could also just hit Enter before calling npm - and ; doesn't seem to work.