Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions