npm run scripts on Windows
See original GitHub issuenpm run scripting syntax is slightly different on Windows due to the underlying shell being used. Usually the default is cmd.exe (the old DOS), even though it is possible to override the default.
The key changes required for the testing scripts (p. 315 of the book) are:
    "test-server": "set TEST_DATABASE=mytestdatabase&& npm start",     "test": "mocha --require @babel/register src/**/*.spec.js"
In test-server, there is no space between the variable’s value and && on purpose otherwise trailing spaces would be added to the value (https://stackoverflow.com/questions/25112510/how-to-set-environment-variables-from-within-package-json-node-js#comment58812038_27090755).
Note that TEST_DATABASE=mytestdatabase && npm start will not work in Linux because && starts another shell where the variable is not defined.
In test, single quote are omitted otherwise * are not expanded, or at leasr I think.
Unfortunately there is no way to define cross environment scripts without using external packages.
Issue Analytics
- State:
 - Created 5 years ago
 - Comments:6 (2 by maintainers)
 

Top Related StackOverflow Question
Pmosconi’s solution worked for me on Windows. I think the book should be updated to note this for Windows users as I spent about 2 hours trying to figure out what was going on before coming here. I am guessing there are many readers who have been stuck at this part of the book.
For simple scripts the best solution is using cross-env:
"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"I’m not sure about quote expansion though.