[Node.js] Pass command line arguments to node.js
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的更多相关文章
- xargs: How To Control and Use Command Line Arguments
参考: http://www.cyberciti.biz/faq/linux-unix-bsd-xargs-construct-argument-lists-utility/ http://linux ...
- msiexec command line arguments
Documented command line arguments Type MSIEXEC /? and you'll get the following on-screen help: Windo ...
- Unity3d command line arguments
Options Many of these relate to Unity3d command line arguments Batch Mode - should be left enabled u ...
- An annotation based command line parser
Java命令行选项解析之Commons-CLI & Args4J & JCommander http://rensanning.iteye.com/blog/2161201 JComm ...
- atprogram.exe : Atmel Studio Command Line Interface
C:\Program Files\Atmel\Atmel Studio 6.1\atbackend\atprogram.exe No command specified.Atmel Studio Co ...
- Getopt::Long - Extended processing of command line options
use Getopt::Long; my $data = "file.dat"; my $length = 24; my $verbose; GetOptions (" ...
- Creating Node.js Command Line Utilities to Improve Your Workflow
转自:https://developer.telerik.com/featured/creating-node-js-command-line-utilities-improve-workflow/ ...
- [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 ...
- react,react native,webpack,ES6,node.js----------今天上午学了一下node.js
http://www.yiibai.com/nodejs/node_install.html---node.js具体入门资料在此 Node JS事件循环 Node JS是单线程应用程序,但它通过事件和 ...
随机推荐
- new不抛出异常nothrow与new_handler
可以看这里: http://blog.csdn.net/huyiyang2010/article/details/5984987 现在的new是会抛出异常的,bad::alloc 如果不想抛出异常两种 ...
- 源代码编译安装CloudStack 4.2
基于CentOS 6.4安装CloudStack 环境配置 # yum -y update # yum -y upgrade 安装NTP,jdk 1.7, tomcat 6, mysql,git等服务 ...
- 基于Linux系统的Nagios网络管理模块的实现
基于Linux 系统的Nagios网络管理模块的实现 1.引言 随着计算机网络的普及,网络管理已成为信息时代中最重要的问题之一.在现有的技术条件下,人们希望有一个更加稳定可靠的网络环境.计算机网络管理 ...
- 使用Python开发轻量级的Web框架以及基于WSGI的服务器来实现一个网站页面
说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 目录 一丶项目说明 二丶数据准备 三丶使用网络TCP开发一个基于WSGI协议的Web服务器 四丶使用python3开发一个轻量级的 ...
- 删除online日志測试及ora-600 [4194]错误的处理
今天做了一个关于破坏online日志的恢复測试,主要三个场景: 測试1:正常关闭数据库后删除非当前日志 測试2:正常关库后.删除在线日志文件 測试3:非正常关闭数据库.并删除当前在线日志文件 我的測试 ...
- 2lession-文件访问
今天继续学习python,因为是根据网上的教程,里面用到了一些例子,包含有后面的知识点.但是,因为自己稍微有点c.java等语言基础,所以并没有严格按照教程来学习,反而是遇到知识点就记录下来. 代码如 ...
- Android判断App是否在前台运行
版权声明:本文为博主原创文章,未经博主允许不得转载. //当前应用是否处于前台 private boolean isForeground(Context context) { if (context ...
- jquery中prop()和attr()的使用
jquery1.6+出现的prop()方法. • 对于HTML元素本身就带有的固有属性,在处理时,使用prop方法. • 对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法. • ...
- [转]MySQLHelper类
本文转自:http://de.cel.blog.163.com/blog/static/5145123620110181003903/ 类似于SQLHelper,只是这里引用的是MySql.Data类 ...
- postman--基本使用2
本文转自:http://blog.csdn.net/u013613428/article/details/51557804 最近需要测试产品中的REST API,无意中发现了PostMan这个chro ...