Avatar ·

How to pass command line arguments to an npm script?

Hello everyone! I'm new to Node.js and npm. I have a package.json with several scripts. For example, I want to run tests with different parameters: sometimes with the --watch flag, sometimes specifying a specific file. Currently I'm doing this: ```json { "scripts": { "test": "mocha", "test:watch": "mocha --watch", "test:file": "mocha test/somefile.js" } } ``` But this is terribly inconvenient — I have to create a separate script for each variation. I want to have one `test` script, but pass arguments to it directly from the command line, for example: ``` npm run test -- --watch npm run test -- --grep "pattern" npm run test test/mytest.js ``` But for some reason this doesn't work — the arguments don't reach mocha. I've tried different options: with double dash, without it, with quotes — nothing works.