node.jsexpressazure-devopsazure-pipelinesazure-releases

How to deploy nodejs expressjs app in Azure with CI/CD?


I'm trying to deploy a nodejs with expressjs app. My pipeline is this:

enter image description here

This create a correct artifact:

enter image description here

We can check here:

enter image description here

Now I create this release that uses the artifact I mentioned previously:

enter image description here

The steps in release:

enter image description here

And after release executed(success) in appname.scm.azurewebsites.net in wwwroot folder I have the right files:

enter image description here But application never start because I never tell how start I think.

What would I put in Post deployment action? node server/server.js? (server.js is in server folder), npm start? In my package.json if I use npm start, then it going to run node server/server.js. Because in local, if I will run my app I have to execute npm start or node server/server.js


Solution

  • In the package.json file, normally you set the main file, "main": "server.js", in your case I think you should define main as "main": "server.js" and move the server.js file from the server directory to project root directory.

    If you look at the log stream, normally to start the project, azure runs node server or something you defined in the package.json as main.

    I have pasted some parts of the azure log stream here so you can see what happens in the azure:

    2022-05-09T18:19:04.222521897Z # Enter the source directory to make sure the script runs where the user expects
    2022-05-09T18:19:04.222528898Z cd "/home/site/wwwroot"
    2022-05-09T18:19:04.222535898Z
    2022-05-09T18:19:04.222542298Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
    2022-05-09T18:19:04.222548498Z if [ -z "$PORT" ]; then
    2022-05-09T18:19:04.222554799Z      export PORT=8080
    2022-05-09T18:19:04.222561899Z fi
    2022-05-09T18:19:04.222783509Z
    2022-05-09T18:19:04.222805710Z node server.js