Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The following code runs perfectly locally...

var express = require('express');
var app = express();

app.get('/', function (req, res) {
    res.send("Hello World");
});

var port = 8080;

app.listen(port, function () {
    console.log('Server started and is listening on port ' + port);
});

But when i deploy it to azure I get a 500 error. Here is my findings...

  1. I have taken this advice
  2. Have tried all possible combinations of server.js, app.js, directory structure etc.

The code is being deployed from a local git repo.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
881 views
Welcome To Ask or Share your Answers For Others

1 Answer

Azure Web Apps (web sites) listen on ports 80 and 443 only. You can not listen on port 8080.

You'll need to listen on port process.env.PORT. And you can easily run both locally and in Azure by tweaking your port code to something like:

var port = process.env.PORT || 8080;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...