【发布时间】:2018-07-31 10:32:41
【问题描述】:
当我运行节点项目时指定端口未定义。
> 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 dev
const HTTP_PORT = process.env.HTTP_PORT || 3001;
应用程序开始在端口 3001 上成功运行,因为我没有在运行命令中指定 HTTP_PORT。 但是当尝试通过使用以下命令指定 HTTP_PORT 来运行另一个实例时
npm run dev HTTP_PORT=3002 P2P_PORT=5002 PEERS=ws://localhost:5001
我收到此错误。
Error: listen EADDRINUSE :::3001
这意味着在运行时指定的 HTTP_PORT 被视为未定义,这就是它尝试将 3001 端口用于第一个实例的原因。
【问题讨论】:
-
这是特定于
dev脚本及其运行的任何内容。它们没有显示出来。
标签: node.js environment-variables