Node js 项目启动报错,错误码,events.js:141,throw er; //Unhandled 'error' event,解决办法
当我遇到这个问题的时候,我纠结了好半天,找了好多资料,都说是端口占用,必须杀死端口重新启动,确实是这样。但是我当时在Windows下直接启动没有任何问题,直接就能把服务器启动起来,但是发现在mac下老是报这个错:
game server is listening on localhost:9003
client service is listening on port 9001
room service is listening on localhost:9002
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::9001
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at Server._listen2 (net.js:1250:14)
at listen (net.js:1286:10)
at Server.listen (net.js:1382:5)
at EventEmitter.listen (/Users/chaoge/Downloads/cocosjs/server/server/node_modules/express/lib/application.js:617:24)
at Object.exports.start(/Users/chaoge/Downloads/cocosjs/server/server/hall_server/client_service.js:315:6)
at Object.<anonymous>(/Users/chaoge/Downloads/cocosjs/server/server/hall_server/app.js:10:16)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
account server is listening on 9000
dealer api is listening on localhost:12581
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::9000
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at Server._listen2 (net.js:1250:14)
at listen (net.js:1286:10)
at Server.listen (net.js:1382:5)
at EventEmitter.listen(/Users/chaoge/Downloads/cocosjs/server/server/node_modules/express/lib/application.js:617:24)
at Object.exports.start(/Users/chaoge/Downloads/cocosjs/server/server/account_server/account_server.js:19:6)
at Object.<anonymous>(/Users/chaoge/Downloads/cocosjs/server/server/account_server/app.js:11:4)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
game server is listening on 10000
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::10000
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at Server._listen2 (net.js:1250:14)
at listen (net.js:1286:10)
at Server.listen (net.js:1382:5)
at Server.listen.Server.attach(/Users/chaoge/Downloads/cocosjs/server/server/node_modules/socket.io/lib/index.js:216:9)
at new Server(/Users/chaoge/Downloads/cocosjs/server/server/node_modules/socket.io/lib/index.js:50:17)
atServer(/Users/chaoge/Downloads/cocosjs/server/server/node_modules/socket.io/lib/index.js:38:41)
at Object.exports.start(/Users/chaoge/Downloads/cocosjs/server/server/majiang_server/socket_service.js:9:27)
at Object.<anonymous> (/Users/chaoge/Downloads/cocosjs/server/server/majiang_server/app.js:15:16)
看到这些错误信息,我相信很多人都可能遇到过,也到处找解决办法,其实我们只要查看端口号,看看哪些端口被占用。
打开终端,然后输入:ps –ef|grep node,然后显示如图所示:
我们会发现这几个文件占用了这几个端口,那么我们应该怎么办呢?当然是把这几个端口杀死,在终端输入:skill -9 1284,回车,然后再输入:skill -9 1288 ,继续输入skill -9 1858,回车,到此我们就把这几个端口占用都杀死了,如图所示:
执行到这步,你再重新启动,应该就不会报错了,赶紧尝试吧!
更多问题和技术交流欢迎加入QQ群讨论:83459374