fullstack-apollo-express-postgresql-boilerplate icon indicating copy to clipboard operation
fullstack-apollo-express-postgresql-boilerplate copied to clipboard

npm run scripts on Windows

Open pmosconi opened this issue 5 years ago • 6 comments

npm 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.

pmosconi avatar Jan 01 '19 11:01 pmosconi

Thanks for reporting this @pmosconi Need to check how to fix this! Any help on it is very much appreciated if anyone else runs into this 👍

rwieruch avatar Jan 02 '19 07:01 rwieruch

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.

pmosconi avatar Jan 02 '19 09:01 pmosconi

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.

tmstani23 avatar Jan 15 '19 14:01 tmstani23

Thank you for confirming @tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!

In the end, did you use

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", 
"test": "mocha --require @babel/register src/**/*.spec.js"

or

"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"

or both and both worked for you?

Thank you again!

rwieruch avatar Jan 16 '19 01:01 rwieruch

I used:

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/**/*.spec.js"

I haven't tried cross-env. I'm wondering if that's a library or a part of node? Thanks for the response. I've really been enjoying the book so far and learning so much!

Regards, Timothy Stanislav

On Tue, Jan 15, 2019 at 7:02 PM Robin Wieruch [email protected] wrote:

Thank you for confirming @tmstani23 https://github.com/tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!

In the end, did you use

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/**/*.spec.js"

or

"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"

or both and both worked for you?

Thank you again!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/issues/44#issuecomment-454611212, or mute the thread https://github.com/notifications/unsubscribe-auth/AG3iALTdqL_Lr8PKfmIcucOP4zTRF1HXks5vDno_gaJpZM4Zl2ph .

-- Timothy Stanislav Cell:507-261-9867 Email:[email protected]

tmstani23 avatar Jan 16 '19 13:01 tmstani23

cross-env is an npm module you have to add to your dev dependencies.

paolo

Da: Tim Stanislav [email protected] Inviato: mercoledì 16 gennaio 2019 14:38 A: the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate fullstack-apollo-express-postgresql-boilerplate@noreply.github.com Cc: Paolo Mosconi [email protected]; Mention [email protected] Oggetto: Re: [the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate] npm run scripts on Windows (#44)

I used:

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/**/*.spec.js"

I haven't tried cross-env. I'm wondering if that's a library or a part of node? Thanks for the response. I've really been enjoying the book so far and learning so much!

Regards, Timothy Stanislav

On Tue, Jan 15, 2019 at 7:02 PM Robin Wieruch <[email protected] mailto:[email protected] > wrote:

Thank you for confirming @tmstani23 https://github.com/tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!

In the end, did you use

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/**/*.spec.js"

or

"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"

or both and both worked for you?

Thank you again!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/issues/44#issuecomment-454611212, or mute the thread https://github.com/notifications/unsubscribe-auth/AG3iALTdqL_Lr8PKfmIcucOP4zTRF1HXks5vDno_gaJpZM4Zl2ph .

-- Timothy Stanislav Cell:507-261-9867 Email:[email protected]

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/issues/44#issuecomment-454781360 , or mute the thread https://github.com/notifications/unsubscribe-auth/AG8cIoaSYry6QtcdpVJDRcsfgEqCVkc9ks5vDysbgaJpZM4Zl2ph . https://github.com/notifications/beacon/AG8cIqB2CMV89-G98ZA-VSgWCN4hfqnTks5vDysbgaJpZM4Zl2ph.gif

pmosconi avatar Jan 16 '19 15:01 pmosconi