Command line arguments is often used to modify the behavior of a application or specify needed parameters for operation. In this lesson, you'll learn how to access the command line arguments passed to your node. JS application as well as dif Ferent strategies for evaluating and accessing them.
To catch what arguement user passed on from command line, we can use 'process.argv '.
If We log out:
// Server.js Console.log (PROCESS.ARGV)
Then we run the command:
Node server.js foo Bar soo
In the console, it logs out this:
' /usr/local/bin/node ' , ' /users/zhentianwan/documents/programming/node/nol/server ' , ' Foo ' , ' Bar ' , ' Soo ' ]
Here the ' foo Bar Soo ' is meaningless, but in the real case, the argv user pass in might is something we need, but the OR Der might is differet, for example, sometime-do:
NPM I ramda--save
Somtime you might:
NPM I--save Ramda
The Order of command can be different.
To make sure what user have pass in, we can do:
if (Process.argv.indexOf ('foo')! =-1) {Console.log ('yeah! We is going to foo! '); }
[node. js] Pass command line arguments to node. js