Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (43 sloc) 858 Bytes
layout title date excerpt categories
post
Passing arguments to npm scripts
2017-04-29 20:42:06 -4000
How to pass arguments on the command-line to an npm script.
npm script cli

Passing arguments to a Node.js script is pretty straightforward:

// index.js
console.log(process.argv.slice(2));
$ node index.js --arg
[ '--arg' ]

But how do we pass our arguments to an npm script?

Given the following package.json:

{
  "scripts": {
    "main": "node index.js"
  }
}

We pass our arguments after the end of options delimiter (--):

$ npm run main -- --arg
[ '--arg' ]

This holds true even for nested npm scripts:

{
  "scripts": {
    "main": "node index.js",
    "nested": "npm run main"
  }
}
$ npm run nested -- -- --arg
[ '--arg' ]