ExpressJS-처리되지 않은 오류 이벤트 발생
다음 명령을 사용하여 expressjs 응용 프로그램을 만들었습니다.
express -e folderName
npm install ejs --save
npm install
와 함께 응용 프로그램을 실행할 때
node app.js
다음 오류가 발생합니다.
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:884:11)
at Server._listen2 (net.js:1022:14)
at listen (net.js:1044:10)
at Server.listen (net.js:1110:5)
at Object.<anonymous> (folderName/app.js:33:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
고치는 방법?
다른 서버를 실행하여 8080과 같은 포트를 사용했습니다.
node app
다른 쉘에서 실행했을 수도 있습니다 . 닫고 다시 실행하십시오.
포트 번호를 확인할 수 있습니다. 사용 가능 여부
netstat -tulnp | grep <port no>
익스프레스 앱을 실행하면 비슷한 오류가 발생합니다. 이 경우에도 똑같이 따라야합니다. 터미널에서 실행 중인지 확인해야합니다. 프로세스를 찾아서 종료하려면 다음 단계를 수행하십시오.
- PS AUX | 그렙 노드
- 프로세스 ID를 찾으십시오 (왼쪽에서 두 번째).
- -9 PRCOCESS_ID 죽이기
또는
단일 명령을 사용하여 실행중인 모든 노드 프로세스를 닫으십시오.
ps aux | awk '/node/{print $2}' | xargs kill -9
인스턴스가 여전히 실행 중일 수 있습니다. 이 문제를 해결합니다.
killall node
업데이트 :이 명령은 Linux / Ubuntu 및 Mac에서만 작동합니다.
Linux를 사용하는 경우 Nodejs가 루트로 실행되지 않는 경우에도이 문제가 발생할 수 있습니다.이것에서 변경 :
nodejs /path/to/script.js
이에:
sudo nodejs /path/to/script.js
방금 나에게 일어 났으며 여기에 다른 제안은 없습니다. 운 좋게도 루트로 실행할 때 스크립트가 다른 날에 작동하고 있음을 기억했습니다. 이것이 누군가를 돕기를 바랍니다!
면책 조항 :
이것은 아마도 프로덕션 환경에 가장 적합한 솔루션은 아닙니다. 루트로 서비스를 시작하면 서버 / 애플리케이션에 보안 허점이 생길 수 있습니다. 제 경우에는 로컬 서비스를위한 솔루션 이었지만 다른 사람들이 원인을 찾아 내기 위해 더 많은 시간을 보내도록 권장하고 있습니다.
스크립트를 실행하는 데 사용중인 포트가 이미 사용 중이기 때문입니다. 해당 게시물을 사용하는 다른 모든 노드를 중지해야합니다. 이를 위해 다음을 통해 모든 노드를 확인할 수 있습니다
ps -e
또는 노드 프로세스의 경우에만 사용
ps -ef | grep node
ID가있는 모든 노드 프로세스의 목록을 제공합니다모든 노드 프로세스를 종료하려면
sudo killall -9 node
또는 특정 ID
sudo kill -9 id
포트를 변경하여 버그를 수정했습니다.
app.set('port', process.env.PORT || 3000);<br>
다음으로 변경되었습니다.
app.set('port', process.env.PORT || 8080);<br>
사용하려는 포트 노드가 다른 프로그램에서 이미 사용될 수 있습니다. 내 경우 에는 최근에 설치 한
입니다. 그것을 깨닫기 위해 브라우저에서
을 열어야 했습니다. 프로세스를 찾는 또 다른 방법은
.
동일한 포트 번호를 사용하려면
kill %
터미널에 입력 하면 현재 백그라운드 프로세스가 종료되고 추가 사용을 위해 포트가 해제됩니다.
이것은 파일이 지금 실행 중임을 의미합니다. 아래 코드를 입력하고 다시 시도하십시오.
sudo pkill node
Close any other node servers that are running, even if they are in other terminal windows or running on different ports. That should fix the problem.
If you've tried killing all node instances and other services listening on 3000 (the default used by the express skeleton setup) to no avail, you should check to make sure that your environment is not defining 'port' to be something unexpected. Otherwise, you'll likely get the same error. In the express skeleton's app.js file you'll notice line 15:
app.set('port', process.env.PORT || 3000);
In-order to fix this, terminate or close the server you are running. If you are using Eclipse IDE, then follow this,
Run > Debug
Right-click the running process and click on Terminate.
Reason for this error
Some other process is already running on the port you have specified
Simple and Quick solution
On Linux OS, For example you have specified 3000 as the port
- Open the terminal and run
lsof -i :3000
. If any process is already running on port 3000 then you will see this printing on the console
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 16615 aegon 13u IPv6 183768 0t0 TCP *:3000 (LISTEN)
-
Copy the PID (process ID) from the output
-
Run
sudo kill -9 16615
(you have to put PID after -9) - Start the server again
In my case I've had to run vagrant reload
as well. Even with no node processes running my express app in my virtual machine I was still getting this error until reloading the vagrant box.
Stop the service that is using that port.
sudo service NAMEOFSERVICE stop
In my case the issue was caused by forgetting to call next()
in an expressjs `use' method call.
If the current middleware does not end the request-response cycle, it must call next() to pass control to the next middleware, otherwise the request will be left hanging.
http://expressjs.com/guide/using-middleware.html
This worked for me.
http://www.codingdefined.com/2015/09/how-to-solve-nodejs-error-listen.html
Just change the port number from the Project properties.
You can also change the port from Gruntfile.js and run again.
After killing the same process multiple times and not being able to locate what else was running on port 8000, I realized I was trying to run on port 8000 twice:
Before:
MongoClient.connect(db.url, (err, database) => {
if (err) return console.log(err);
require('./app/routes')(app, database);
app.listen(port, () => {
console.log('We are live on ' + port);
});
});
require('./app/routes')(app, {});
app.listen(port, () => {
console.log("We are live on " + port);
});
After:
MongoClient.connect(db.url, (err, database) => {
if (err) return console.log(err);
require('./app/routes')(app, database);
app.listen(port, () => {
console.log('We are live on ' + port);
});
});
require('./app/routes')(app, {});
I had the same problem and I found out, that a nodejs process that I had previously canceled with CTRL+C was still running. The problem in Windows 10 is, that Ctrl + C Doesn't Kill Gracefully nodejs. I opened the task manager and killed the process manually. The solutions provided on GitHub didn't work for me.
If you using windows, then you can end process from task manager for node.js
events.js:183 throw er; // Unhandled 'error' event
I also got the same kind of problem and tried many ways but finally got this, this works well:
npm install ws@3.3.2 --save-dev --save-exact
Refer to this link for more clarifications https://github.com/ionic-team/ionic-cli/issues/2922
None of the answers worked for me.
When I restarted my computer I could get the server up and running.
Macshutdown now -r
Linuxsudo shutdown now -r
Actually Ctrl+C keys not releasing port used by node process. So there is this error. The resolution to the issue was using following code snippet in server.js:
process.on('SIGINT', function() {
console.log( "\nGracefully shutting down from SIGINT (Ctrl-C)" );
// some other closing procedures go here
process.exit(1);
});
This worked for me.
You can also check for other solutions mentioned at Graceful shutdown in NodeJS
->check what’s running on port 8080 or what ever port u want to check
lsof -i @localhost:8080
if something is running u can close it or use some kill command to close it
Simple just check your teminal in Visual Studio Code Because me was running my node app and i hibernate my laptop then next morning i turn my laptop on back to development of software. THen i run the again command nodemon app.js First waas running from night and the second was running my latest command so two command prompts are listening to same ports that's why you are getting this issue. Simple Close one termianl or all terminal then run your node app.js or nodemon app.js
Just change your port,might be your current port is in use by iis or some other server.
Try the below fixes.
-
Try to close the process that is using your port.
netstat -tulnp | grep <port_number>
-
Installing the below pakcage fixed it for me forever.
npm install ws@3.3.2 --save-dev --save-exact
-
Run this command in your terminal :
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
fs.inotify.max_user_watches=524288
Then execute:
sysctl --system
This will also persist across reboots.
https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details
- For Arch Linux add this line to /etc/sysctl.d/99-sysctl.conf:
npm install --save --save-exact react-scripts@2.1.
참고URL : https://stackoverflow.com/questions/16827987/expressjs-throw-er-unhandled-error-event
'programing' 카테고리의 다른 글
폴더가 있는지 확인하는 방법 (0) | 2020.05.21 |
---|---|
socket.io 및 node.js를 사용하여 특정 클라이언트에게 메시지 보내기 (0) | 2020.05.21 |
INSTALL_FAILED_DUPLICATE_PERMISSION… C2D_MESSAGE (0) | 2020.05.21 |
UIImageView의 UIGestureRecognizer (0) | 2020.05.21 |
iOS : 투명한 배경의 모달 ViewController (0) | 2020.05.21 |