大佬教程收集整理的这篇文章主要介绍了如何修复 azure 应用程序服务中的“错误侦听 EADDRINUSE:地址已在使用中”?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 nodeJs/express 应用程序,我将它部署到 linux 平台上的 Azure Appservice。 Azure 提供运行我的应用程序的端口 8080。 但是,当我部署它时,它给了我一个错误
Error Listen EADDRINUSE: address already in use :::8181
error Command Failed with exit code 1.
我用来运行应用程序的主要命令是 env NODE_ENV=production node index.Js
。
应用程序使用的端口是 8080
。但是即将出现的错误是针对端口 8181
。我已经尝试重新启动服务器并重新部署多次。
我按照本教程进行部署。 https://docs.microsoft.com/en-us/azure/app-service/quickstart-nodejs?pivots=platform-linux
我删除了整个应用服务及其计划,然后重新部署,却发现同样的错误。
我通过 SSH 进入容器并检查 8181
是否正在使用中。但事实并非如此。
这是我启动应用程序的方式:
const port = 8080;
const server = app.Listen(process.env.PORT || port,() => {
console.log(`App running on port ${port}`);
});
这是部署日志的截图
我该怎么办?
编辑:
这是我的 package.Json
{
"name": "test-express","version": "1.0.0","main": "index.Js","license": "MIT","scripts": {
"test": "echo \"Error: no test specifIEd\" && exit 1","dev": "nodemon index.Js","build:azure": "env NODE_ENV=production node index.Js"
},"dependencIEs": {
"express": "^4.17.1","morgan": "^1.10.0"
},"devDependencIEs": {
"nodemon": "^2.0.7"
}
}
在我在下面提到的官方文档中,启动应用程序的脚本之一是“build:azure”。
此外,我将这些行添加到我的代码中,以查看传递了哪些环境变量。
console.log("=============");
console.log(process.env.PORT,process.env.NODE_ENV);
console.log("=============");
我得到的构建过程的最终结果是
...
7:00:08 pm test-express: [1/4] Resolving packages...
7:00:09 pm test-express: [2/4] Fetching packages...
7:00:30 pm test-express: info fsevents@2.3.2: The platform "linux" is incompatible with this module.
7:00:30 pm test-express: info "fsevents@2.3.2" is an optional dependency and Failed compatibility check. Excluding it from installation.
7:00:30 pm test-express: [3/4] linking dependencIEs...
7:00:45 pm test-express: [4/4] Building fresh packages...
7:00:45 pm test-express: Done in 37.21s.
7:00:45 pm test-express: Running 'yarn run build:azure'...
7:00:46 pm test-express: yarn run v1.22.10
7:00:46 pm test-express: $ env NODE_ENV=production node index.Js
7:00:46 pm test-express: =============
7:00:46 pm test-express: 8181 production
7:00:46 pm test-express: =============
7:00:46 pm test-express: events.Js:292
7:00:46 pm test-express: throw er; // Unhandled 'error' event
7:00:46 pm test-express: ^
7:00:46 pm test-express: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
7:00:46 pm test-express: Error: Listen EADDRINUSE: address already in use :::8181
7:00:46 pm test-express: at Server.setupListenHandle [as _Listen2] (net.Js:1318:16)
7:00:46 pm test-express: at ListenInCluster (net.Js:1366:12)
7:00:46 pm test-express: at Server.Listen (net.Js:1452:7)
7:00:46 pm test-express: at Function.Listen (/tmp/8d8e87f8a5dd6db/node_modules/express/lib/application.Js:618:24)
7:00:46 pm test-express: at Object.<anonymous> (/tmp/8d8e87f8a5dd6db/index.Js:8:20)
7:00:46 pm test-express: at Module._compile (internal/modules/cJs/loader.Js:1063:30)
7:00:46 pm test-express: at Object.Module._extensions..Js (internal/modules/cJs/loader.Js:1092:10)
7:00:46 pm test-express: at Module.load (internal/modules/cJs/loader.Js:928:32)
7:00:46 pm test-express: at Function.Module._load (internal/modules/cJs/loader.Js:769:14)
7:00:46 pm test-express: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.Js:72:12)
7:00:46 pm test-express: Emitted 'error' event on Server instance at:
7:00:46 pm test-express: at emitErrorNT (net.Js:1345:8)
7:00:46 pm test-express: at processticksAndRejections (internal/process/task_queues.Js:80:21) {
7:00:46 pm test-express: code: 'EADDRINUSE',7:00:46 pm test-express: errno: -98,7:00:46 pm test-express: syscall: 'Listen',7:00:47 pm test-express: address: '::',7:00:47 pm test-express: port: 8181
7:00:47 pm test-express: }
7:00:47 pm test-express: error Command Failed with exit code 1.
7:00:49 pm test-express: /opt/Kudu/Scripts/starter.sh oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform nodeJs --platform-version 14 -i /tmp/8d8e87f8a5dd6db -p compress_node_modules=tar-gz --log-file /tmp/build-deBUG.log
7:01:07 pm test-express: Deployment Failed.
是的,8181 已通过。
已修复:
是的,我通过将脚本属性 build:azure
更改为 start
解决了这个问题。这是我需要在 package.Json
中进行的唯一更改才能使其运行。
更新
疑难解答:
第一步:
第 2 步:
第 3 步:
隐私
请修改监听代码中的代码。
Exp: const port = process.env.PORT || 8080
version: "3.9"
services:
react:
build: .
image: react
ports:
- "5000:5000"
django:
image: django
ports:
- "5001:5000"
相关帖子
1. Strapi on Azure does not run
2. How to view console.log() output in Azure app service app
第一步:推荐使用git进行持续部署,端口设置相同const express = require('express')
const app = express()
const port = process.env.PORT || 8080
app.get('/',(req,res) => {
res.send('Hello World!')
})
app.listen(port,() => {
console.log(`Example app listening at http://localhost:${port}`)
})
按照帖子中的方法参考。然后检查网站是否正常运行。
第2步:如果网站无法正常启动,建议添加启动命令。要尝试的第一个命令是 process.env.PORT
。
第 3 步:如果第 2 步中的命令不起作用,请使用 npx serve -s
。
以上是大佬教程为你收集整理的如何修复 azure 应用程序服务中的“错误侦听 EADDRINUSE:地址已在使用中”?全部内容,希望文章能够帮你解决如何修复 azure 应用程序服务中的“错误侦听 EADDRINUSE:地址已在使用中”?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。