Nodemon 崩溃并显示等待文件更改
Nodemon crashes and shows waiting for file changes
我正在使用 nodemon 版本 1.18.3 和 express 版本 4。
直接使用 运行 nodemon 命令时,出现以下错误:
events.js:165
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Server.setupListenHandle [as _listen2] (net.js:1346:14)
at listenInCluster (net.js:1387:12)
at Server.listen (net.js:1475:7)
at Function.app.listen (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/application.js:531:24)
at Object.<anonymous> (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/bin/www:7:18)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1366:8)
at process._tickCallback (internal/process/next_tick.js:178:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:697:11)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
[nodemon] app crashed - waiting for file changes before starting...
Nodemon 崩溃并继续等待文件更改。
错误提示端口 3000
已被使用。
您需要使用其他端口,可以使用以下命令,
nodemon ./YOUR_SCRIPT_NAME.js localhost 3005
希望对您有所帮助!
发生这种情况是因为 nodemon 无法监视您的文件系统,如 issue on github 中所述。
基本上,nodemon 使用称为 inotify
观察者的东西来观察您在代码中所做的更改。
您可以通过增加最大观察者数量来解决此问题,然后重新启动计算机以应用更改:
echo fs.inotify.max_user_watches=524298 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
也提到了here。
或者您也可以在端点文件中添加以下代码:
process.on('SIGUSR2', () => { process.exit(0); });
我正在使用 nodemon 版本 1.18.3 和 express 版本 4。 直接使用 运行 nodemon 命令时,出现以下错误:
events.js:165
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Server.setupListenHandle [as _listen2] (net.js:1346:14)
at listenInCluster (net.js:1387:12)
at Server.listen (net.js:1475:7)
at Function.app.listen (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/application.js:531:24)
at Object.<anonymous> (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/bin/www:7:18)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1366:8)
at process._tickCallback (internal/process/next_tick.js:178:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:697:11)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
[nodemon] app crashed - waiting for file changes before starting...
Nodemon 崩溃并继续等待文件更改。
错误提示端口 3000
已被使用。
您需要使用其他端口,可以使用以下命令,
nodemon ./YOUR_SCRIPT_NAME.js localhost 3005
希望对您有所帮助!
发生这种情况是因为 nodemon 无法监视您的文件系统,如 issue on github 中所述。
基本上,nodemon 使用称为 inotify
观察者的东西来观察您在代码中所做的更改。
您可以通过增加最大观察者数量来解决此问题,然后重新启动计算机以应用更改:
echo fs.inotify.max_user_watches=524298 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
也提到了here。
或者您也可以在端点文件中添加以下代码:
process.on('SIGUSR2', () => { process.exit(0); });