$ node yourscript.js banana monkey
var program_name = process.argv[0]; //value will be "node"var script_path = process.argv[1]; //value will be "yourscript.js"var first_value = process.argv[2]; //value will be "banana"var second_value = process.argv[3]; //value will be "monkey"
// Lodash libraryconst _ = require('lodash');
// Function that goes through each CommandLine Arguments and prints it to the console.const runApp = () => {_.map(process.argv, (arg) => {console.log(arg);});};
// Calling the function.runApp();
0 'C:\\Program Files\\nodejs\\node.exe'1 'C:\\Users\\Nouman\\Desktop\\Node\\camer nodejs\\proj.js'2 'arg1' your first argument you passed.3 'arg2' your second argument you passed.4 'arg3' your third argument you passed.
const process = require( 'process' );
const argv = key => {// Return true if the key exists and a value is definedif ( process.argv.includes( `--${ key }` ) ) return true;
const value = process.argv.find( element => element.startsWith( `--${ key }=` ) );
// Return null if the key does not exist and a value is not definedif ( !value ) return null;
return value.replace( `--${ key }=` , '' );}
const arguments = require("minimist")(process.argv.slice(2));// get the extra argument of command line .eg node app.js --process="sendEmailWithReminder"