[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是单线程应用程序,但它通过事件和 ...
随机推荐
- highcharts 阶梯图表并填充颜色(自己觉得:直角折线图表)
例如以下:普通阶梯图 $(function () { $('#container').highcharts({ title: { text: '普通阶梯图' ...
- golang round
func Round(f float64, n int) float64 {pow10_n := math.Pow10(n)return math.Trunc((f+0.5/pow10_n)*pow1 ...
- flex布局:
他的布局主要有两个“二”,一个二:容器项,子项目项.另一个:有两条轴,主轴,副轴.它的使用时,必须先声明说明是flex布局:display:flex; 针对于容器项的属性6个: 1.flex-dire ...
- JavaScript tab页
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 【Codeforces Round #455 (Div. 2) C】 Python Indentation
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一个for循环之后. 下一个写代码的地方一是从(x+1,y+1)开始的 然后如果写完了一个simple statement 下次就有 ...
- BFS模版程序
本文转自q=bfs&u=cnyali&t=blog">http://so.csdn.net/so/search/s.do?q=bfs&u=cnyali& ...
- 分析器错误消息: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分
关于错误提示:此实现不是 Windows 平台 FIPS 验证的加密算法的一部分的解决方案 不知怎么的,每次Win10升级后相应的注册器都恢复默认了,当我运行08版的asp项目时会报这个错. vs上的 ...
- 【习题 6-9 UVA - 127】"Accordian" Patience
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 链表模拟即可. 1pile不能加s... [代码] #include <bits/stdc++.h> using nam ...
- Photon + Unity3D 线上游戏开发 学习笔记(三)
好的,说了两篇了 如今我们正式的入手,揭开photon 的盖头哈 建立photon项目 第一步: 在Visual studio建立一个空的 待会为了測试也会在里面建立一个client 项目 (只 ...
- c编程:僵尸吃大脑
第一行输入一个正整数n 以下每一行输入僵尸已经吃了的大脑数量a,和需要生存必需要吃的大脑数量b.总共n行. 例子输入 3 4 5 3 3 4 3 例子输出 NO BRAINS MMM BRAINS M ...