Sample Video Frame
08: Command Line Arguments
A command line is where you type commands in your terminal (aka PowerShell on Windows). In this exercise you learn how to get information from users by letting them put arguments after your .js file name like this:
$ node ex08.js Zed 44 Blue
The words "Zed", "44", and "Blue" after the script named ex08.js get passed to the script so you can work with them. In Node this is in the process.argv variable, and this variable is a list of the items on the command line.
I'm going to avoid telling you what a list is and save that for later (when we talk about Arrays). For now, just know that argument 1 ("Zed") is at position 2 in the process.argv and you tell JavaScript you want position 2 with [2] after process.argv. Just remember that your arguments are "off by one".
Register for The Pro-Webdev Mega Bundle
Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.