While running my azure application, my server.js is not running properly.

SHASWATA DAS 55 Reputation points
2024-05-23T11:27:07.28+00:00

Hi team,
I am facing some strange issues after my app deployment through Github in the Azure app service.

First of all, I am quite new to Azure, so maybe I am making some mistakes in this case.

GitHub Repo - https://github.com/shaswataddas/azure-login-user/tree/main
I am following a Boilerplate to develop my MERN application. Here is the link to the article (https://medium.com/@atilla.tuna.sogut/how-to-deploy-a-mern-stack-app-to-azure-via-continuous-integration-a3a551526e26).

When I update my app and deploy it into the azure. I can see the frontend code in the base Azure URL(https://authentication-azure-app.azurewebsites.net/). Also, my navigation is working correctly. But Whenever I want to hit URL to register a user, it shows an Error - ***The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.


Here is the network tab -
Screenshot 2024-05-23 at 4.36.32 PM

I also try to hit the endpoint via Postman. not working.

If I run my code in localhost, it runs, the backend and frontend as well. also, I can see the CRUD operations in the Azure SQL DB.
Now, a couple of questions are in my mind, How does Azure run the app, what is the starting point(windows server os No start command is available)? How did Azure come to know that I have to run the server.js file? If my server.js is not able to run then the DB connection is not made and no CRUD operations.

looks like my node.js file is not running properly. Also, is there any way to check the logs on the Azure application?

Thank you in advance

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

2 answers

Sort by: Most helpful
  1. ajkuma 28,036 Reputation points Microsoft Employee Moderator
    2024-05-29T10:16:30.3166667+00:00

    @SHASWATA DAS , Firstly, apologies for the delayed response.

    Based on my understanding of your issue description - Just to highlight, On Azure App Service it uses a file called web.config for IIS-based applications or the startup command for Linux-based applications to understand how to start your app. It looks for the server.js file if that's specified in your configuration as the entry point for your Node.js application

    Regarding the error message you're receiving when trying to register a user, it suggests that the route for registration might not be correctly set up in your Azure environment, or the server is not properly configured to handle the request. This could be due to a variety of reasons, such as missing environment variables, incorrect file paths, or other configuration issues.

    To check the logs on your Azure App Service, you may use Azure's App Service Diagnostic Logs to capture and analyze the activity of your application through logging : Access log files
    Review Enable and review logs to fetch more details about the error.

    Additionally, you can use Azure Monitor Logs and Log Analytics to query and analyze logs for more insights.

    on App Service Windows - If you deploy your files by using Git, or by using ZIP deployment with build automation enabled, the deployment engine generates a web.config in the web root of your app (%HOME%\site\wwwroot) automatically if one of the following conditions is true:

    • Your project root has a package.json that defines a start script that contains the path of a JavaScript file.
    • Your project root has either a server.js or an app.js.

    The generated web.config is tailored to the detected start script. For other deployment methods, add this web.config manually. Make sure the file is formatted properly.

    0 comments No comments

  2. ajkuma 28,036 Reputation points Microsoft Employee Moderator
    2024-05-29T10:18:13.14+00:00

    @SHASWATA DAS , Adding more info, to isolate the issue, please try the following:

    1.Kindly ensure that your server.js file is correctly configured to listen on the correct port and that all necessary modules are installed and required within your application.

    2.For your Node.js application to run in Azure, it needs to listen on the port provided by the PORT environment variable. In your generated Express app, this environment variable is already used in the startup script bin/www (search for process.env.PORT).

    3.The container automatically starts your app with PM2 when one of the common Node.js files is found in your project: E,g : server.js

    The container doesn't automatically start your app with PM2. To start your app with PM2, set the startup command to pm2 start <.js-file-or-PM2-file> --no-daemon. Be sure to use the --no-daemon argument because PM2 needs to run in the foreground for the container to work properly

    1. Ensure that web.config is pointing to the correct .js entrypoint file in the production build.

    Additionally, a web.config in an incorrect location may cause this as well. Eg., placing this in a subfolder outside of the project root.

    Configure a Node.js app for Azure App Service

    Kindly let us know how it goes, I'll follow-up with you.

    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.