[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是单线程应用程序,但它通过事件和 ...
随机推荐
- pdnsd 解析原理
apt install dnsmasq dnsmasq-fullvim /etc/dnsmasq.conf vim /etc/pdnsd.conf killall pdnsdpdnsd -c /etc ...
- 一些VPS
https://www.perfectip.net 5美元/1C/4G/20G/10Thttps://www.hetzne ...
- amazeui的表单开关插件的自定义事件必须添加.bootstrapSwitch 命名空间,给了我们什么启示
amazeui的表单开关插件的自定义事件必须添加.bootstrapSwitch 命名空间,给了我们什么启示 一.总结 一句话总结:详细看使用文档(说明文档说的真的是非常详细呢,不过循序渐进,不同阶段 ...
- Manning.EJB.3.in.Action.2nd.Edition
Manning.EJB.3.in.Action.2nd.Edition http://files.cnblogs.com/files/rojas/EJB_3_in_Action_2nd_Edition ...
- 不用浏览器,直接用代码发送文件给webservices所在服务器 并且可以周期行的发送
package com.toic.test; import java.io.DataInputStream; import java.io.DataOutputStream; import java. ...
- AJAX - 基本流程和特点
<script> window.onload = function(ev){ var oBtn = document.querySelector('button'); // querySe ...
- [Javascript AST] 0. Introduction: Write a simple BabelJS plugin
To write a simple Babel plugin, we can use http://astexplorer.net/ to help us. The plugin we want to ...
- java list 容器的ConcurrentModificationException
java中的很多容器在遍历的同时进行修改里面的元素都会ConcurrentModificationException,包括多线程情况和单线程的情况.多线程的情况就用说了,单线程出现这个异常一般是遍历( ...
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第四篇:传递表单数据
摘要 本文将完成我们“MVC公告发布系统”的公告发布功能,以此展示在ASP.NET MVC中如何传递处理表单的数据. 前言 通过前几篇文章,我们已经能比较自如的使用ASP.NET ...
- js进阶 13-9/10 jquery如何实现三级列表
js进阶 13-9/10 jquery如何实现三级列表 一.总结 一句话总结:用的是定位,父标签相对定位,子标签就可以绝对定位了,绝对定位的孩子还是可以设置绝对定位.用toggle设置子菜单显示和隐藏 ...