node-cli-params
v1.0.0
Published
Get your inline parameters.
Downloads
3
Maintainers
Readme
Node Cli Params
Get your inline parameters in a node environment.
Options
Methods | Arguments | Description ------- | -------------- | ----------- hasKey | key | hasKey(key) - true or false getKey | key | getKey(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