Nodejs Express App Not Starting

Matt Bergwall 1 Reputation point
2020-11-02T16:51:43.11+00:00

Hello,

I have a very simple Express app that works fine locally that I am deploying to Azure. Code is below:

const express = require('express')  
const app = express()  
const port = 3000  
  
app.get('/', (req, res) => {  
  res.send('Hello World!')  
})  
  
app.listen(port, () => {  
  console.log(`Example app listening at http://localhost:${port}`)  
})  

This deploys without issue, but the container in Azure is not running. Here are the logs:

36848-2020-11-02-lw1sdlwk00000s-dockerlog.txt

I'm unsure if I am missing additional configuration - the app is running on port 3000, I am sure I need to add some reverse proxy to port 80 in Azure.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,663 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 27,771 Reputation points Microsoft Employee
    2020-11-02T19:45:52.427+00:00

    Hi @Matt Bergwall ,

    I suggest setting your port to process.env.PORT if available, this will allow your application to listen to the port set for your environment. You can set it as follows:

     const port = process.env.PORT || 3000  
    

    Another thing you could do is set WEBSITES_PORT = 3000. You can do this by either adding the value to your Application Settings under the Configuration blade in the portal:

    36933-image.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.