Command line arguments are often used to modify the behavior of an application or specify needed parameters for operation. In this lesson, you will learn how to access the command line arguments passed to your node.js application as well as different strategies for evaluating and accessing them.

To catch what arguement user passed in 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 log out this:

[ '/usr/local/bin/node',
'/Users/zhentianwan/Documents/Programming/Node/nol/server',
'foo',
'bar',
'soo' ]

Here the 'foo bar soo' are meaningless, but in the real case, the argv user pass in might be something we need, but the order might be differet, for example, sometime you do:

npm i ramda --save

Somtime you might:

npm i --save ramda

The order of command can be different.

To make sure what user has pass in, we can do:

if (process.argv.indexOf('foo') != -) { console.log('Yeah! We are going to foo!'); }

[Node.js] Pass command line arguments to node.js的更多相关文章

  1. xargs: How To Control and Use Command Line Arguments

    参考: http://www.cyberciti.biz/faq/linux-unix-bsd-xargs-construct-argument-lists-utility/ http://linux ...

  2. msiexec command line arguments

    Documented command line arguments Type MSIEXEC /? and you'll get the following on-screen help: Windo ...

  3. Unity3d command line arguments

    Options Many of these relate to Unity3d command line arguments Batch Mode - should be left enabled u ...

  4. An annotation based command line parser

    Java命令行选项解析之Commons-CLI & Args4J & JCommander http://rensanning.iteye.com/blog/2161201 JComm ...

  5. atprogram.exe : Atmel Studio Command Line Interface

    C:\Program Files\Atmel\Atmel Studio 6.1\atbackend\atprogram.exe No command specified.Atmel Studio Co ...

  6. Getopt::Long - Extended processing of command line options

    use Getopt::Long; my $data   = "file.dat"; my $length = 24; my $verbose; GetOptions (" ...

  7. Creating Node.js Command Line Utilities to Improve Your Workflow

    转自:https://developer.telerik.com/featured/creating-node-js-command-line-utilities-improve-workflow/ ...

  8. [Node] Run Local DevDependencies from the Command Line with npx

    In the past, you've needed to either write a package.json script or use the node_modules/.bin direct ...

  9. react,react native,webpack,ES6,node.js----------今天上午学了一下node.js

    http://www.yiibai.com/nodejs/node_install.html---node.js具体入门资料在此 Node JS事件循环 Node JS是单线程应用程序,但它通过事件和 ...

随机推荐

  1. [ReasonML] Named & optional params

    // ::country is named param // ::country=?: which make it optional // because we make ::country=? op ...

  2. Android 关于expandableListView childrenView 点击改变颜色

    1.点击后改变颜色并保持颜色改变状态: <?xml version="1.0" encoding="utf-8"?> <selector xm ...

  3. values-dimen 不同分辨率资源实现引用

    今天遇到了一种情况,就是在不同分辨率下面出现了需要设定不同的距离,当时第一反映就是重新定义一个layout.但是,仅仅为了更改一个数值就复制那么多的代码,明显不合里.后来就想到干脆在不同的分辨率下创建 ...

  4. 28.lambda表达式与多线程

    #include <iostream> #include <thread> #include <Windows.h> #include <chrono> ...

  5. Mybatis批量插入,是否能够返回id列表

    第1次代码 void batchAdd(List<Photo> list); <insert id="batchAdd" parameterType=" ...

  6. 可执行EXE在windows调用过程

    举例图中, 一个C#编写的测试程序, 输出两句话分别 : Hello, GoodBye, 介绍其在windows上CLR的调用过程. 1.在执行Main方法之前, CLR会检测出Main的代码引用的所 ...

  7. js面向对象1----了解构造函数

    一.构造函数与实例的区别 1 构造函数  构造函数主要是一种用于生成对象的饼干模具,这些对象具有默认属性和属性方法,它可以创建多个共享特定特性和行为的对象.  构造函数只是一个函数,但当函数遇到了ne ...

  8. Java Web学习总结(17)——JSP属性范围

    所谓的属性范围就是一个属性设置之后,可以经过多少个其他页面后仍然可以访问的保存范围. 一.JSP属性范围 JSP中提供了四种属性范围,四种属性范围分别指以下四种: 当前页:一个属性只能在一个页面中取得 ...

  9. WebClient HttpWebRequest从网页中获取请求数据

    WebClient HttpWebRequest //HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(urlAddress) ...

  10. 宝塔 ftp 不能连接 列出时出错

    摘抄自 https://www.bt.cn/bbs/forum.php?mod=viewthread&tid=1903&page=1&extra=#pid6515 1.注意内网 ...