CLI模块为node的命令行工具,需在ssh或cmd中执行,常用命令示例列举如下:
#获取node版本
[root@iZ94b9jaqbfZ ~]# node -v
v4.4.3
#获取帮助信息
[root@iZ94b9jaqbfZ ~]# node -h
Usage: node [options] [ -e script | script.js ] [arguments]
node debug script.js [arguments]
Options:
-v, --version print Node.js version
-e, --eval script evaluate script
-p, --print evaluate script and print result
-c, --check syntax check script without executing
-i, --interactive always enter the REPL even if stdin
does not appear to be a terminal
-r, --require module to preload (option can be repeated)
--no-deprecation silence deprecation warnings
--trace-deprecation show stack traces on deprecations
--throw-deprecation throw an exception anytime a deprecated function is used
--trace-sync-io show stack trace when use of sync IO
is detected after the first tick
--track-heap-objects track heap object allocations for heap snapshots
--prof-process process v8 profiler output generated
using --prof
--v8-options print v8 command line options
--tls-cipher-list=val use an alternative default TLS cipher list
--icu-data-dir=dir set ICU data load path to dir
(overrides NODE_ICU_DATA)
Environment variables:
NODE_PATH ':'-separated list of directories
prefixed to the module search path.
NODE_DISABLE_COLORS set to 1 to disable colors in the REPL
NODE_ICU_DATA data path for ICU (Intl object) data
NODE_REPL_HISTORY path to the persistent REPL history file
Documentation can be found at https://nodejs.org/
#将字符串转换为js语句,并执行
[root@iZ94b9jaqbfZ ~]# node -e 'console.log("aaa")'
aaa
#将字符串转换为js语句,并执行打印最终结果
[root@iZ94b9jaqbfZ ~]# node -p 'var a=22;a+3'
25