Use process.argv to access arguments passed while running a node.js application.
Install Yargs
Run the fileconsole.log(process.argv);
node test drive --speed=30 --model=nissan
Output[ 'C:\\Program Files\\nodejs\\node.exe',
'C:\\Users\\Dell\\Desktop\\Angular\\myapp\\test011args',
'drive',
'--speed=30',
'--model=nissan' ]
Doing the same using yargs npm packageInstall Yargs
npm install yargs
Write the fileRun the fileconst yargs = require('yargs');console.log(yargs.argv);
node test drive --speed=30 --model=nissan
Output{ _: [ 'drive' ],
speed: 30,
model: 'nissan',
'$0': 'test011args' }
Uargs converts the arguments in an object
Comments
Post a Comment