Reputation: 825
I recently started learning node js and using online tutorials.
I am trying to grab the user name and a little greeting but it keeps failing to get it. There is a if statement to check if it fails, if it does it will output "you blew it". Here is the code:
function grab(flag){
var index = process.argv.indexOf(flag);
return (index==-1) ? null : process.argv[index+1]
}
var greeting = grab('--greeding');
var user = grab('--user');
if (!user || !greeting){
console.log("you belew it")
}else {
console.log('welcome ${user}, ${greeting}');
}
This is the way I am passing data
node app.js --user Stack --greeting "hello"
Upvotes: 2
Views: 65