Pass command line arguments to npm scripts in package.json

In this short article, we will show you how to pass command line arguments to npm scripts in package.json.

Sometimes, we may need to pass the command line args to npm scripts to dynamically pass the values.

Syntax

It’s possible to pass args into npm scripts since npm 2 (2014). Use the following syntax.

We need to use the -- separator to separate the parameters passed to the npm command itself and those params passed to your npm script.

Example

Let’s consider the following npm scripts for an example.

package.json

Run the following command to pass the host via command line arguments.

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *