How to properly run a npm script with arguments

久未见 提交于 2019-12-10 13:45:00

问题


I've written a small command line program with nodejs and I want to be able to type npm run test and run the program with the arguments below.

Typing the following command directly works, node.exe scrappee.js -u 'https://github.com/matutter/{}' -us 'cloggie, AirRocks-Flightcontroller' -s '$commit=li.commits > a > span, $sha=.right .commit-tease-sha' -pm .\test\example_parse_module.js

But with the contents of my package.json as follows there is no output whatsoever.

"scripts": {
    "test" : "node.exe scrappee.js -u 'https://github.com/matutter/{}' -us 'cloggie, AirRocks-Flightcontroller' -s '$commit=li.commits > a > span, $sha=.right .commit-tease-sha' -pm .\\test\\example_parse_module.js"
}

How can I get the command npm run test to run the scrappee.js script with the these arguments?


回答1:


The issue was from the single quote ' being converted to "'" by npm when the arguments are forwarded, the solution was to replace them with double quotes like below.

"test" : "node.exe scrappee.js -u \"https://github.com/matutter/{}\" -us \"cloggie, AirRocks-Flightcontroller\" -s \"$commit=li.commits > a > span, $sha=.right .commit-tease-sha\" -pm \".\\test\\example_parse_module.js\""


来源:https://stackoverflow.com/questions/37500744/how-to-properly-run-a-npm-script-with-arguments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!