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. windows下硬盘安装debian

    windows下硬盘安装debian 此方法在 windows8.1 + debian8.7.1 可用 配置系统安装镜像 1 在windows下格式化一个fat32的分区 2 把下载的debian-7 ...

  2. css 兼容性前缀

    一.不同浏览器内核下的书写规则 二:transform  具体变性中心基点  transform-origin  默认情况下  rotate旋转.scale缩放.translate位移.矩阵matri ...

  3. Tuple<int, int> Dictionary<string, object>妙用

    Tuple<int, int> Dictionary<string, object>妙用

  4. erroe:plot.new() : figure margins too large

    使用R时多次出现这个错误,plot.new() : figure margins too large,提示图片边界太大 解决方法,win.graph(width=4.875, height=2.5,p ...

  5. 关于Webpack详述系列文章 (第二篇)

    1.缩小文件搜索范围 1.1.1 include & exclude module:{ rules:[ { test:/\.js$/, use:['babel-loader?cacheDire ...

  6. Mysql 简介二

    Mysql 数据库引擎: 数据库引擎是用于存储.处理和保护数据的核心服务 Mysql支持的引擎一般有这几种: MyISAM Mysql 5.1版本之前默认的存储引擎,仅仅支持表锁,但查询速度较Inno ...

  7. ecshop微信接口基础认识

    ecshop微信接口基础认识,当你要学习ecshop和微信整合的时候,你就必须研究ecshop的数据结构对接以及微信数据接口的基本知识.我们知道微信其实就是通过有效的消息推送,用JSON格式的数据或者 ...

  8. JPA的配置文件persistence.xml参数详解

    <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0&q ...

  9. Python写爬虫-爬甘农大学校新闻

    Python写网络爬虫(一) 关于Python: 学过C. 学过C++. 最后还是学Java来吃饭. 一直在Java的小世界里混迹. 有句话说: "Life is short, you ne ...

  10. (转)Oracle命令

    转自:http://www.cnblogs.com/NaughtyBoy/p/3181052.html Oracle登录命令 1.运行SQLPLUS工具 C:\Users\wd-pc>sqlpl ...