Entering command line arguments for your IoT application

You can enter command line arguments for use in your IoT application. This provides you with a simple way to input arguments for your code to use. For example, if you have a temperature monitoring application, you can type an argument like -f or -c and have your program change its output to Fahrenheit or Celsius accordingly.

As another example, the following code in your main.js file would output each command line argument to the console, along with an index number:

for (var i=0; i < process.argv.length; i++) {
console.log(i + ':' + process.argv[i]);
}

If you then entered a b c as arguments you would see the following output:

0:node
1:/home/root/.node_app_slot/main.js
2:a
3:b
4:c

You can use the same styles of quoting that you would expect to work in a shell such as bash or ksh. For example, if you entered the arguments: “par\”1” par\ 2

The following output is displayed:

0:node
1:/home/root/.node_app_slot/main.js
2:”par”1”
3:par 2

Entering command line arguments using this feature is similar to running your program from the command line by typing: node main.js argument1 argument2 .... However, you do not need to type node main.js in the Intel XDK, only the arguments to be passed in.

  1. Click the Manage your daemon/IoT device icon in the bottom right of the Intel XDK, then select Enter Arguments for IoT Application. The Enter Arguments for IoT Application dialog box opens.
  2. Type the arguments to pass in, with each argument separated by a space. Click OK.
  3. Run your application. Your arguments are passed to your program.
For more complete information about compiler optimizations, see our Optimization Notice.