当我运行节点项目时会指定端口,表示未定义。
> sf-chain@1.0.0 dev E:\System\dev\node\sf-chain
> nodemon ./app "HTTP_PORT=3002" "P2P_PORT=5002" "PEERS=ws://localhost:5001"
[nodemon] 1.18.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node ./app HTTP_PORT=3002 P2P_PORT=5002 PEERS=ws://localhost:5001`
process.env.HTTP_PORT :: undefined
HTTP_PORT :: 3001
Listening for peer-to-peer connections on: 5001
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3001
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1259:14)
at listen (net.js:1295:10)
at Server.listen (net.js:1391:5)
at EventEmitter.listen (E:\System\dev\node\sf-chain\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (E:\System\dev\node\sf-chain\app\index.js:28:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
[nodemon] app crashed - waiting for file changes before starting...我运行第一个实例使用
npm run devconst HTTP_PORT = process.env.HTTP_PORT x= 3001;
由于我没有在run命令中指定HTTP_PORT,所以应用程序在端口3001上成功地开始运行。但是当试图通过使用下面的命令指定HTTP_PORT来运行另一个实例时
npm run dev HTTP_PORT=3002 P2P_PORT=5002 PEERS=ws://localhost:5001
我知道这个错误。
Error: listen EADDRINUSE :::3001这意味着在运行时指定的HTTP_PORT被视为未定义的,这就是为什么它试图为第一个实例使用3001端口的原因。
发布于 2018-07-31 11:16:35
错误:侦听EADDRINUSE -当某些东西已经在该端口上运行/侦听时出现错误
这是因为同一nodejs的某些实例获取端口并没有正确地杀死/退出进程,
如果您有Ubuntu,那么首先检查哪个进程正在使用端口
lsof -i :3001 // Port no.那么输出就会像这样。
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 2496 nasiruddin 13u IPv6 37696 0t0 TCP *:3001 (LISTEN)使用PID杀灭
kill 2496然后重新开始
https://stackoverflow.com/questions/51611307
复制相似问题