1

I previously asked (and got a great answer for) this question: named parameter to npm run script

As mentioned in 1 of the comments to the correct answer, the $npm_config_variable does not work on windows. I'm looking for a cross platform way to run this script as npm run say-hello --greeting='hello'.

Is there any way to check for the OS in npm scripts and use %% instead of $?

Community
  • 1
  • 1
Ben
  • 16,124
  • 22
  • 77
  • 122

1 Answers1

1

Use minimist library. Its realy easy to access command line params with it and it works in every environment.

var argv = require('minimist')(process.argv.slice(2));
var param = argv.param;

// package.json snippet
"scripts": {
   "start": "app --param=value"
}
tomastrajan
  • 1,728
  • 14
  • 28
  • that doesn't work inside of package.json though. I need to parse the args in side of the script like this: "scripts":{ "start":"echo $NPM_CONFIG_PARAM" } then from a command line: run npm run start --param='hello' – Ben Aug 12 '15 at 15:15