我正在使用8080端口的localserver上的express.js使用nodemon。
nodemon总是在我对文件进行任何更改后始终崩溃,并出现此错误:
events.js:292
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::8080
at Server.setupListenHandle [as _listen2] (net.js:1313:16)
at listenInCluster (net.js:1361:12)
at Server.listen (net.js:1447:7)
at Function.listen (/home/sergey/Dev/Web/projects/YelpCamp/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/sergey/Dev/Web/projects/YelpCamp/app.js:69:5)
at Module._compile (internal/modules/cjs/loader.js:1123:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:972:32)
at Function.Module._load (internal/modules/cjs/loader.js:872:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1340:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '::',
port: 8080
}
[nodemon] app crashed - waiting for file changes before starting...
我可以通过添加空格或回车来解决它,但是nodemon将在我进行另一次更改后再次崩溃。
我的app.js侦听器:
app.listen(process.env.PORT || 8080, process.env.ip, function(){
console.log('Server is running!');
});
如果您在Linux上运行,则需要在8080(或阻塞的任何端口)处杀死所有进程
kill $(lsof -t -i:8080)
然后再次运行您的应用程序。我认为您在代码中犯了一些错误,因此会影响到您的nodemon。