0

This is the code:

var minimist = require('minimist')
const args = minimist(process.argv.slice(2))
console.log(args)

In the terminal, I type: npm start -a abc -b bbc

$ npm start -a abc -b bbc
{ _: [ 'abc', 'bbc' ] }

This is what I expected:

{ _: [], a: 'abc', b: 'bbc' }

This might sound silly, but please help me get out of this...

Kumar Abhirup
  • 197
  • 4
  • 16

1 Answers1

1

npm 2 and newer

Use -- prefix to pass args to npm run since npm 2 (2014). The syntax is as follows:

$ npm run <command> [-- <args>]

Your command should look like this:

$ npm start -- -a abc -b bbc
{ _: [], a: 'abc', b: 'bbc' }

Note the -- separator, used to separate the params passed to npm command itself, and the params passed to your script.

Read more

luthfimasruri
  • 61
  • 2
  • 5