1.0.0 • Published 7 years ago

node-cli-params v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

Node Cli Params

Get your inline parameters in a node environment.

Options

MethodsArgumentsDescription
hasKeykeyhasKey(key) - true or false
getKeykeygetKey(key) - returns the value of a found key or false

Example

let nodeCliParams = require('node-cli-params');

console.log("##################");
console.log("### Parameters ###");
console.log("##################");
console.log(nodeCliParams.parameters);

console.log("\r\n#######################");
console.log("### Arguments found ###");
console.log("#######################");
console.log(Object.keys(nodeCliParams.parameters));

console.log("\r\nHas 'environment' key ?",nodeCliParams.hasKey('environment'));
console.log("'environment' value =",nodeCliParams.getKey('environment'));

Run

node ./YOUR_FILE_WITH_THE_ABOVE_CODE.js environment=production title="node cli params" metadata="{text: 'normal text'}"

Output:

##################
### Parameters ###
##################
{ 'which node': '',
  'script file path': '',
  environment: 'production',
  title: 'node cli params',
  metadata: '{text: \'normal text\'}' }

#######################
### Arguments found ###
#######################
[ 'which node',
  'script file path',
  'environment',
  'title',
  'metadata' ]

Has 'environment' key ? true
'environment' value = production