--watch


以监视模式启动 Node.js。在监视模式下,监视文件中的更改会导致 Node.js 进程重新启动。默认情况下,监视模式将监视入口点和任何必需或导入的模块。使用 --watch-path 指定要监视的路径。

¥Starts Node.js in watch mode. When in watch mode, changes in the watched files cause the Node.js process to restart. By default, watch mode will watch the entry point and any required or imported module. Use --watch-path to specify what paths to watch.

此标志不能与 --check--eval--interactive 或 REPL 组合。

¥This flag cannot be combined with --check, --eval, --interactive, or the REPL.

注意:--watch 标志需要文件路径作为参数,并且与 --run 或内联脚本输入不兼容,因为 --run 优先并忽略监视模式。如果未提供文件,Node.js 将退出并返回状态码 9

¥Note: The --watch flag requires a file path as an argument and is incompatible with --run or inline script input, as --run takes precedence and ignores watch mode. If no file is provided, Node.js will exit with status code 9.

node --watch index.js