Node.js Command Line Options(命令行参数)

  • Command Line Options

    • Synopsis
    • Options

      • -v, –version
      • -h, –help
      • -e, –eval “script”
      • -p, –print “script”
      • -c, –check
      • -i, –interactive
      • -r, –require module
      • –no-deprecation
      • –trace-deprecation
      • –throw-deprecation
      • –no-warnings
      • –trace-warnings
      • –trace-sync-io
      • –zero-fill-buffers
      • –preserve-symlinks
      • –track-heap-objects
      • –prof-process
      • –v8-options
      • –tls-cipher-list=list
      • –enable-fips
      • –force-fips
      • –icu-data-dir=file
    • Environment Variables

      • NODE_DEBUG=module[,…]
      • NODE_PATH=path[:…]
      • NODE_DISABLE_COLORS=1
      • NODE_ICU_DATA=file
      • NODE_REPL_HISTORY=file
      • NODE_TTY_UNSAFE_ASYNC=1

Command Line Options

命令行参数

Node.js comes with a variety of CLI options. These options expose built-in debugging, multiple ways to execute scripts, and other helpful runtime options.

To view this documentation as a manual page in your terminal, run man node.

Node.js自带了各种各样的命令行参数。这些参数显示了内置的调试接口、执行脚本的多种方式和其它有帮助的运行时选项。

在你的终端上,查阅该文档作为一个参考手册,通过执行“man node”命令。

Synopsis

大纲;摘要;梗概

node [options] [v8 options] [script.js | -e "script"] [arguments]
node debug [script.js | -e "script" | <host>:<port>] | -p <pid> …
node --v8-options

Execute without arguments to start the REPL.

For more info about node debug, please see the debugger documentation.

不带参数的执行改命令会启动REPL(Read-Eval-Print Loop,“读取-求值-输出”循环,即交互式解释器)。

更多关于“node debug”命令的信息,请参看 “debugger”文档。

Options

选项

-v, –version

Added in: v0.1.3
Print node’s version.

打印node的版本信息。

这里写图片描述

-h, –help

Added in: v0.1.3
Print node command line options. The output of this option is less detailed than this document.

打印node命令行参数。该选项的输出不会比本文档更详尽。

-e, –eval “script”

Added in: v0.5.2
Evaluate the following argument as JavaScript. The modules which are predefined in the REPL can also be used in script.

将随后的参数当作JavaScript执行。在REPL交互式解释器中预定义的模块也可以用在该脚本中。

-p, –print “script”

Added in: v0.6.4
Identical to -e but prints the result.

与-e选项相同,但是会打印该结果(最后一条语句的执行结果)

这里写图片描述

-c, –check

Added in: v5.0.0
Syntax check the script without executing.

校验脚本的语法错误而不执行。

这个选项我测试了一下,加不加-c脚本都会执行,因此很奇怪。

-i, –interactive

Added in: v0.7.7
Opens the REPL even if stdin does not appear to be a terminal.

打开REPL,即使终端不是标准输入。

进入REPL后,执行命令的输出与不加-i一样

-r, –require module

Added in: v1.6.0
Preload the specified module at startup.

Follows require()’s module resolution rules. module may be either a path to a file, or a node module name.

在启动的时候预加载这些特殊的模块。

其规则和require()函数引入模块的解决方案类似。模块可以是一个文件路径或一个node模块名。

C:\Users\Administrator> node -r YOUR_MODULE_NAME
>

–no-deprecation

Added in: v0.8.0
Silence deprecation warnings.

引用被废弃的对象时禁用警告

–trace-deprecation

Added in: v0.8.0
Print stack traces for deprecations.

引用被废弃的对象时禁用警告

–throw-deprecation

Added in: v0.11.14
Throw errors for deprecations.

引用被废弃的对象时抛出错误

这里写图片描述

这里试了一下,既是使用deprecated对象也能正常运行,不会有任何反馈

–no-warnings

Added in: v6.0.0
Silence all process warnings (including deprecations).

禁用所有执行警告(包括废弃警告)

–trace-warnings

Added in: v6.0.0
Print stack traces for process warnings (including deprecations).

打印执行警告的堆栈跟踪信息(包括废弃警告)

–trace-sync-io

Added in: v2.1.0
Prints a stack trace whenever synchronous I/O is detected after the first turn of the event loop.

第一轮事件循环后,一旦检测到同步I/O,就打印堆栈跟踪信息。

–zero-fill-buffers

Added in: v6.0.0
Automatically zero-fills all newly allocated Buffer and SlowBuffer instances.

自动填充零到所有新分配的Buffer和SlowBuffer(deprecated)实例中。

这里写图片描述

Added in: v6.3.0
Instructs the module loader to preserve symbolic links when resolving and caching modules.

By default, when Node.js loads a module from a path that is symbolically linked to a different on-disk location, Node.js will dereference the link and use the actual on-disk “real path” of the module as both an identifier and as a root path to locate other dependency modules. In most cases, this default behavior is acceptable. However, when using symbolically linked peer dependencies, as illustrated in the example below, the default behavior causes an exception to be thrown if moduleA attempts to require moduleB as a peer dependency:

命令模块加载器在解析和缓存模块时,保存符号链接。

默认情况是,当Node.js从一个符号链接到另一个不同的磁盘的路径中加载模块时,Node.js会间接引用该链接并且使用一个实际存在于磁盘上的真实路径,即可以作为一个标识,也可以作为一个根目录来定位其它依赖的模块。在大部分情况下,这个默认的行为是可以接受的。然而,当使用符号链接同等的依赖时,如下图所示,默认的行为会导致抛出一个异常,如果模块A尝试去引用模块B’作为一个同等的依赖。

 ├── app
 │   ├── index.js
 │   └── node_modules
 │       ├── moduleA -> {appDir}/moduleA
 │       └── moduleB
 │           ├── index.js
 │           └── package.json
 └── moduleA
      ├── index.js
      └── package.json

The –preserve-symlinks command line flag instructs Node.js to use the symlink path for modules as opposed to the real path, allowing symbolically linked peer dependencies to be found.

Note, however, that using –preserve-symlinks can have other side effects. Specifically, symbolically linked native modules can fail to load if those are linked from more than one location in the dependency tree (Node.js would see those as two separate modules and would attempt to load the module multiple times, causing an exception to be thrown).

–preserve-symlinks命令行标志指示Node.js使用模块的符号链接路径而不是它的真实路径,并且允许符号链接到发现的同等的依赖。

注意,然而使用–preserve-symlinks也会有副作用。特别是,符号链接本地模块有可能加载失败,如果它们在依赖树种链接到多个不同的路径(Node.js会把它们当成2个不同的路径,并且将会尝试多次加载该模块,这会产生一个异常被抛出)。

实验方法可以参看这篇文章 https://yq.aliyun.com/articles/58911
其实我是没看懂!我自己在Windows上做了实验,好像无效。

实验目录如下
这里写图片描述

└── appDir
     ├── node_modules
          │   ├── moduleA.js
     │   └── moduleB.js.lnk
     ├── index.js
     └── moduleB.js

index.js

const process = require('process');
console.log('process.cwd() =', process.cwd());
console.log('process.execPath =', process.execPath);
console.log('index.js', __dirname, __filename);
console.log(module.paths);
require('moduleA.js');

moduleA.js

console.log('moduleA.js', __dirname, __filename);
console.log(module.paths);
require('moduleB.js');

moduleB.js

console.log('moduleB.js', __dirname, __filename);

执行命令,得出一个结论,在Windows上加不加该标志都一样!!!
这里写图片描述

–track-heap-objects

Added in: v2.4.0
Track heap object allocations for heap snapshots.

在堆快照中跟踪堆对象的分配信息。

–prof-process

Added in: v6.0.0
Process v8 profiler output generated using the v8 option –prof.

使用v8选项,执行v8分析器对输出进行分析。

–v8-options

Added in: v0.1.3
Print v8 command line options.

Note: v8 options allow words to be separated by both dashes (-) or underscores (_).

For example, –stack-trace-limit is equivalent to –stack_trace_limit.

打印v8命令行参数。

v8选项允许单词用破折号(-)或下划线(_)分割。

举个例子,–stack-trace-limit等价于 –stack_trace_limit

–tls-cipher-list=list

Added in: v4.0.0
Specify an alternative default TLS cipher list. (Requires Node.js to be built with crypto support. (Default))

指定一个备选的默认的TLS加密列表(需要Node.js编译时带加密支持(默认选项))

安全传输层协议(TLS)用于在两个通信应用程序之间提供保密性和数据完整性。该协议由两层组成: TLS 记录协议(TLS Record)和 TLS 握手协议(TLS Handshake)。

–enable-fips

Added in: v6.0.0
Enable FIPS-compliant crypto at startup. (Requires Node.js to be built with ./configure –openssl-fips)

在启动时打开遵循FIPS加密标准的选项。(需要Node.js使用 ./configure –openssl-fips 命令编译)

openssl-fips是符合FIPS标准的Openssl。

联邦信息处理标准(Federal Information Processing Standards,FIPS)是一套描述文件处理、加密算法和其他信息技术标准(在非军用政府机构和与这些机构合作的政府承包商和供应商中应用的标准)的标准。

–force-fips

Added in: v6.0.0
Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.) (Same requirements as –enable-fips)

在启动时强制遵循FIPS加密标准。(不能从脚本中被禁用)(和 –enable-fips 选项的需求一致)

–icu-data-dir=file

Added in: v0.11.15
Specify ICU data load path. (overrides NODE_ICU_DATA)

指定ICU数据加载路径(覆盖 NODE_ICU_DATA)

Environment Variables

环境变量

NODE_DEBUG=module[,…]

Added in: v0.1.32
‘,’-separated list of core modules that should print debug information.

使用逗号(’,’)作为核心模块的分隔符,它会在调试信息中被打印出来。

NODE_PATH=path[:…]

Added in: v0.1.32
‘:’-separated list of directories prefixed to the module search path.

Note: on Windows, this is a ‘;’-separated list instead.

用冒号(’:’)分割模块搜索路径列表。

注意:在Windows上,是用分号(’;’)作为列表分隔符。

NODE_DISABLE_COLORS=1

Added in: v0.3.0
When set to 1 colors will not be used in the REPL.

当该变量设置成1的时候,颜色将不会被用在REPL交互式解释器。

NODE_ICU_DATA=file

Added in: v0.11.15
Data path for ICU (Intl object) data. Will extend linked-in data when compiled with small-icu support.

ICU路径的(国际对象)数据。当使用带small-icu支持的编译方式编译时,将会扩展链接数据。

ICU(International Component for Unicode) 是 IBM 与开源组织合作研究 , 基于 “IBM 公共许可证 ” 的用于支持软件国际化的开源项目。 ICU 实现了对数字、日期、货币等提供国际化支持,提供了强大的 BIDI 算法,对阿拉伯语和希伯来语等 BiDi 语言提供了完善的支持。 ICU 分为 ICU4J 和 ICU4C,分别对应 Java 和 c/c++ 平台。 ICU4J 被 Sun 的 JDK1.1 采用并随 JDK 版本更新。最新的 ICU4J 库可以从 http://icu-project.org/ 网站上下载。

NODE_REPL_HISTORY=file

Added in: v3.0.0
Path to the file used to store the persistent REPL history. The default path is ~/.node_repl_history, which is overridden by this variable. Setting the value to an empty string (“” or ” “) disables persistent REPL history.

该文件路径用来持久地存储REPL的历史记录。默认的路径是~/.node_repl_history,它将会被该变量的值覆盖。将该变量的值设置为空(”“或” “)将会禁止保存REPL的历史记录。

NODE_TTY_UNSAFE_ASYNC=1

Added in: 6.4.0
When set to 1, writes to stdout and stderr will be non-blocking and asynchronous when outputting to a TTY on platforms which support async stdio. Setting this will void any guarantee that stdio will not be interleaved or dropped at program exit. Use of this mode is not recommended.

当设置成1的时候,如果输出到的TTY的平台支持异步输入输出,那么向标准输出流和标准错误流的写操作将变成异步且不阻塞的。该设置将不保证标准输入输出将会交叉进行,或在程序退出后停止。不推荐使用该模式。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值