Express Applications Throwing 500 Azure

The following code works fine 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 breed it on azure, I get 500 error. Here are my findings ...

  • I accepted this one.
  • I tried all possible combinations of server.js, app.js, directory structures, etc.

The code is deployed from the local git repository.

+4
source share
1 answer

Azure Web Apps (websites) only listens on ports 80 and 443. You cannot listen on port 8080.

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

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

+8
source

All Articles