官术网_书友最值得收藏!

  • Node.js Web Development
  • David Herron
  • 441字
  • 2021-06-25 21:54:01

Node.js's command-line tools

The basic installation of Node.js includes two commands, node and npm. We've already seen the node command in action. It's used either for running command-line scripts or server processes. The other, npm, is a package manager for Node.js.

The easiest way to verify that your Node.js installation works is also the best way to get help with Node.js. Type the following command:

$ node --help
Usage: node [options] [ -e script | script.js | - ] [arguments]
node inspect 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)
- script read from stdin (default; interactive mode if a tty)
--inspect[=[host:]port] activate inspector on host:port
(default: 127.0.0.1:9229)
--inspect-brk[=[host:]port]
activate inspector on host:port
and break at start of user script
--inspect-port=[host:]port
set host:port for inspector

... many more options
Environment variables:
NODE_DEBUG ','-separated list of core modules
that should print debug information
NODE_DISABLE_COLORS set to 1 to disable colors in the REPL
NODE_EXTRA_CA_CERTS path to additional CA certificates
file
NODE_ICU_DATA data path for ICU (Intl object) data
(will extend linked-in data)
NODE_NO_WARNINGS set to 1 to silence process warnings
NODE_NO_HTTP2 set to 1 to suppress the http2 module
NODE_OPTIONS set CLI options in the environment
via a space-separated list
NODE_PATH ':'-separated list of directories
prefixed to the module search path
NODE_PENDING_DEPRECATION set to 1 to emit pending deprecation
warnings
NODE_REPL_HISTORY path to the persistent REPL history
file
NODE_REDIRECT_WARNINGS write warnings to path instead of
stderr
OPENSSL_CONF load OpenSSL configuration from file

Documentation can be found at https://nodejs.org/

Note that there are options for both Node.js and V8 (not shown in the previous command line). Remember that Node.js is built on top of V8; it has its own universe of options that largely focus on details of bytecode compilation or garbage collection and heap algorithms. Enter node --v8-options to see the full list of them.

On the command line, you can specify options, a single script file, and a list of arguments to that script. We'll discuss script arguments further in the next section, Running a simple script with Node.js.

Running Node.js with no arguments plops you into an interactive JavaScript shell:

$ node
> console.log('Hello, world!');
Hello, world!
undefined  

Any code you can write in a Node.js script can be written here. The command interpreter gives a good Terminal-oriented user experience and is useful for interactively playing with your code. You do play with your code, don't you? Good!

主站蜘蛛池模板: 龙岩市| 定西市| 乾安县| 正宁县| 石河子市| 新津县| 江都市| 九台市| 通州区| 天峻县| 绥江县| 淮南市| 富源县| 赣州市| 敖汉旗| 册亨县| 龙海市| 阿克陶县| 齐齐哈尔市| 突泉县| 邻水| 故城县| 鹤山市| 墨脱县| 鲜城| 汉寿县| 织金县| 隆安县| 富川| 宁安市| 惠安县| 来安县| 呈贡县| 陇西县| 海原县| 文安县| 滁州市| 响水县| 池州市| 含山县| 承德县|