node.js - Azure 上托管的 Express 网站出现意外错误

标签 node.js azure express

我正在澳大利亚东南地区的 Azure 共享资源上运行非常简单的 Express 网站。网站在端口 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 模块托管 Node.js 应用程序。请参阅wiki让iisnode知道它。

特别注意以下内容。

Minimal changes to node.js application code. The iisnode module enables hosting of existing HTTP node.js applications with very minimal changes. Typically all that is required is to change the listed address of the HTTP server to one provided by the iisnode module via the process.env.PORT environment variable.

因此,您不需要在 Kudu 控制台中通过命令 node server.js 手动启动 Node 应用程序。请尝试仅通过FTP或VS部署或更新代码,并直接访问网站检查部署是否成功。如果应用程序不起作用,您可以尝试在 Azure 门户上重新启动该应用程序。

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

enter image description here

如有任何疑问,请随时告诉我。

关于node.js - Azure 上托管的 Express 网站出现意外错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36880755/

相关文章:

node.js - 如何使用 express 在 Chrome 中获取 net::ERR CONTENT LENGTH MISMATCH

javascript - Node : how to clone an object

node.js - Node-js 事件循环和范围

azure - 更改 Azure 中 VM 的云服务

Azure 授权 : what is scope parameter in REST API?

Azure AD 与 Azure AD B2C 与 Azure AD B2B

node.js - Express + Node : file downloaded through response. download() 与原始文件相比大小不同

angularjs - Angular 不响应 ui-router 的任何路由 - 当我输入时 URL 就消失了

model-view-controller - Node.JS/Mongoose/Express -> 对象没有方法 "findAll"

node.js - 如何在nodejs中找到item的路径?