Question: Since most of your code will be from command line, passing parameters maybe necessary to make the code usable, make sure that you document your

Since most of your code will be from command line, passing parameters maybe necessary to make the code usable, make sure that you document your work. Here is how to pass argument to Node.js program.
Create the following code and save it in wk4_args.js
console.log(process.argv);
>node wk4_args.js
You will get something like this;
['C:\
odejs\
ode.exe', 'C:\\ENTD261\\w4_args.js']
Now comment the above code and add the following code;
// console.log(process.argv);
if (process.argv.length <=2){
console.log("Usage: "+" SOME_PARAM");
process.exit(-1);
}
console.log('Params: '+ process.argv.length);
console.log('University: '+ process.argv[2]);
console.log('Class: '+ process.argv[3]);
// Test the code
// node w4_args.js
// node w4_args.js Apus ENTD261
Now uncomment the above line and run the code again, pay attention to the results. To debug any of the code, use console.log to examine the variables where you have an issue.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!