How to run startup command for a nodejs, express js project on Azure?

Viewed 2748

I am using Azure DevOps for my app. I am not sure how to set up a startup command for the project. If I will add it to the task in the created pipeline, it gives an error, maybe because the process will never end.

Actually, I am able to run npm install and create the artifact, but I will need the App a StartUp command to execute Node server.js

So, below is an image showing a post-deployment action I have added. It does the job but at last, it says deployment failed. I am hoping there is a better process to trigger the npm start command because I can't see any logs as I see on a local server with this command.

enter image description here

1 Answers

If I will add it to the task in the created pipeline, it gives an error, maybe because the process will never end.

This is correct, if you try to run the startup command on your application within a pipeline it will start a process that will run until the Agent Job times out (60 minutes by default for Microsoft-hosted agents, 360 minutes for self-hosted agents).

You will want to avoid running the startup command within your pipelines to avoid tying up your agents.

If you have code that needs to be executed within the application start-up to complete your build/deployment, I'd recommend moving into your webpack.config.js or your package.json's commands.

UPDATE

Thanks for clarifying that you're trying to run the startup command within an Azure App Service on startup. You won't want to use the Post Deployment ACtion, that feature is designed for altering the contents of your deployment after the deployment is successful.

To get your node.js app to start, within your package.json file make sure it has "start" under "scripts":

{
  "scripts": {
    "start": "your start script here",
  }
}

The Azure App Service will, by default, look for "start" within your "package.json" file at the root of your App Service content. If you have a custom startup file, you can configure your app service to use it with the following command:

az webapp config set --resource-group your-resource-group --name your-app-name --startup-file "path/to/custom-startup.json" 

Here is a link to Microsoft's documentation on configuring a Node.js application's startup within an App Service:

Related