在Azure上托pipe的Express网站提供意外错误

我正在澳大利亚东南地区的Azure共享资源上运行非常简单的快速网站。 网站在端口3000上本地运行,但部署到Azure时根本不渲染。 尝试从Azure运行时抛出错误

node server.js events.js:141 throw er; // Unhandled 'error' event Error: listen EADDRINUSE 0.0.0.0:3000 at Object.exports._errnoException (util.js:874:11) at exports._exceptionWithHostPort (util.js:897:20) at Server._listen2 (net.js:1234:14) at listen (net.js:1270:10) at Server.listen (net.js:1366:5) at EventEmitter.listen (D:\home\site\wwwroot\node_modules\express\lib\application.js:617:24) at Object.<anonymous> (D:\home\site\wwwroot\server.js:21:5) at Module._compile (module.js:435:26) at Object.Module._extensions..js (module.js:442:10) at Module.load (module.js:356:32) 

Server.js看起来像

 var express = require('express'); var app = express(); var path = require("path"); var port = process.env.PORT || 3000; console.log(__dirname); app.use(express.static('public')); app.get('/', function (req, res) { res.sendFile(path.join(__dirname+'/index.html')); }); app.get('/contact', function (req, res) { res.sendFile(path.join(__dirname+'/contact.html')); }); app.listen(port, function () { console.log('Example app listening on port!' + port); }); 

不知道我错过了什么?

谢谢

Azure网站允许通过称为iisnode的IIS模块托pipenode.js应用程序。 请参阅wiki以了解iisnode。

特别注意下面的内容。

node.js应用程序代码的最小更改。 iisnode模块能够以非常小的变化托pipe现有的HTTP node.js应用程序。 通常所需要做的就是通过process.env.PORT环境variables将HTTP服务器的列出地址更改为由iisnode模块提供的地址。

所以你不需要在Kudu Console中手动通过命令node server.js启动节点应用程序。 请尽量只通过FTP或VS部署或更新代码,直接访问网站检查部署是否成功。 如果它不起作用,您可以尝试在Azure门户上重新启动应用程序。

如果你想查看正在运行的进程,可以在Kudu工具的Process explorer中看到它们,请看下图。

在这里输入图像说明

任何疑虑,请随时让我知道。

好,

这可能是由于您已经在3000上运行了一个节点的实例。使用ssh连接到您的server.invoke此命令转到terminal接口。

  ps -ax | grep Server.js 

正在运行的进程列表将会出现在这里 在这里输入图像说明

从那里和terminal得到1257

  kill 1257 

现在尝试再次运行您的服务器。

这意味着您尝试绑定服务器的端口正在使用中。 尝试另一个端口或使用azure色的端口closures程序。