npm allows passing arguments to scripts defined in the package.json file using the following syntax:
npm run <command> [-- <args>]
Consider the following package.json:
"scripts": { "start": "node ./script.js server" }
To start the server with a custom port, run the following command:
npm run start -- --port=8080
This will invoke the script with the server argument followed by the -port=8080 argument.
The -- separator is essential for distinguishing between arguments passed to npm and those passed to the script. Without the separator, npm may interpret script arguments as its own options.
The above is the detailed content of How Do I Pass Arguments to npm Scripts?. For more information, please follow other related articles on the PHP Chinese website!