--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